ddeexxiikk

C++ Arduino

May 20th, 2025
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | Source Code | 0 0
  1. #include <Arduino.h>
  2.  
  3. // Definicja pinu, do którego podłączony jest czujnik LM35
  4. #define LM35_PIN PC1
  5.  
  6. void setup() {
  7.   // Rozpoczęcie komunikacji przez UART
  8.   Serial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12.   // Odczyt wartości z czujnika LM35 (napięcie analogowe)
  13.   int analogValue = analogRead(LM35_PIN);
  14.  
  15.   // Przekształcamy wartość analogową na napięcie (w V)
  16.   float voltage = analogValue * (5.0 / 1023.0);
  17.  
  18.   // Obliczamy temperaturę w stopniach Celsjusza
  19.   float temperature = voltage * 100.0; // LM35 daje 10 mV na każdy stopień Celsjusza
  20.  
  21.   // Wysyłamy wartość temperatury na UART
  22.   Serial.print(temperature);
  23.   Serial.print("\n");
  24.  
  25.   delay(2000);
  26. }
Add Comment
Please, Sign In to add comment