mpmcws

Stazione meteo #3 Temperatura, umidità, luce, bagnato.

Aug 27th, 2018
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //LCD (no I2C) con DHT22
  2. //Cerani Marco - MPMC Workshop 7 agosto 2018 V1.3
  3. #include <LiquidCrystal.h>
  4. #include <DHT.h>
  5. #include <Adafruit_Sensor.h>
  6. #define DHTTYPE DHT22
  7. #define DHTPIN 9
  8. DHT dht(DHTPIN, DHTTYPE);
  9. //
  10. float celsius;
  11. float humidity;
  12. //
  13. int val0 = A0;
  14. int val1 = A1;
  15. int analogInPin9 = 9;
  16. int sensorValue9 = 0;
  17. //
  18. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  19. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  20. void setup() {
  21.   dht.begin();
  22.   lcd.begin(16, 2);
  23.   //
  24.   pinMode( analogInPin9, INPUT);
  25.   pinMode( val0, INPUT);
  26.   pinMode( val1, INPUT);
  27.   //
  28. }
  29. void loop() {
  30.   humidity = dht.readHumidity();
  31.   celsius = dht.readTemperature();
  32.   sensorValue9 = analogRead(analogInPin9);
  33.   delay (1000);
  34.   char lcd_buffer[16];
  35.   lcd.setCursor(0, 0); //riposiziono il cursore
  36.   sprintf(lcd_buffer, "%02d.%01d %cC ", (int)celsius, (int)(celsius * 10.0) % 100, (char)223);
  37.   lcd.print(lcd_buffer);
  38.   sprintf(lcd_buffer, "%02d.%01d %cC", (int)humidity, (int)(humidity * 10.0) % 100, (char)37);
  39.   lcd.print(lcd_buffer);
  40.   lcd.setCursor(0, 1);
  41.   //
  42.   delay (1000);
  43.   lcd.print ("L ");
  44.   int val0 = analogRead(A0);
  45.   val0 = map(val0, 0, 1023, 0, 100);
  46.   analogWrite(0, val0);
  47.   lcd.print (val0);
  48.   lcd.print (" %");
  49.   //
  50.   delay (1000);
  51.   lcd.print (" B ");
  52.   int val1 = analogRead(A1);
  53.   val1 = map(val1, 0, 1023, 0, 100);
  54.   analogWrite(0, val1);
  55.   lcd.print (val1);
  56.   lcd.print (" %");
  57.   //
  58.   delay (1000);
  59. }
RAW Paste Data