Advertisement
gio_aggiustatutto

Pluviometro con Arduino

Aug 25th, 2022 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x27,20,4);
  5.  
  6. const float mmPerPulse = 0.173;  //inserire qui il valore in mm di pioggia per ogni cambio di stato del sensore
  7.  
  8. float mmTotali = 0;
  9. int sensore = 0;
  10. int statoPrecedente = 0;
  11.  
  12. void setup() {
  13.   pinMode(9, INPUT);
  14.  
  15.   lcd.init();
  16.   lcd.init();
  17.  
  18.   lcd.backlight();
  19.  
  20.   lcd.setCursor(4,0);
  21.   lcd.print("Pluviometro");
  22.   lcd.setCursor(7,2);
  23.   lcd.print("RESET");
  24.  
  25.   delay(1000);
  26.  
  27.   lcd.clear();
  28. }
  29.  
  30. void loop() {
  31.   sensore = digitalRead(9);
  32.  
  33.   if (sensore != statoPrecedente) {
  34.     mmTotali = mmTotali + mmPerPulse;
  35.   }
  36.  
  37.   delay(500);
  38.  
  39.   statoPrecedente = sensore;
  40.  
  41.  
  42.   lcd.setCursor(4,0);
  43.   lcd.print("Pluviometro");
  44.   lcd.setCursor(2,2);
  45.   lcd.print("Pioggia totale:");
  46.   lcd.setCursor(2,3);
  47.   lcd.print(mmTotali);
  48.   lcd.setCursor(7,3);
  49.   lcd.print("mm");
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement