mpmcws

LCD + DHT11

Jul 16th, 2018
74
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //LCD (no I2C) con DHT11
  2. //Cerani luglio 2018
  3. #include <LiquidCrystal.h> // libreria
  4. #include <DHT.h>
  5. #include <Adafruit_Sensor.h>
  6. #define DHTTYPE DHT11
  7. #define DHTPIN 9
  8. DHT dht(DHTPIN, DHTTYPE);
  9. float celsius; // variabile
  10. float humidity;
  11. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  12. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  13. void setup() {
  14.   dht.begin();
  15.   lcd.begin(16, 2); // LCD ha 16 caratteri e 2 linee
  16. }
  17. void loop() {
  18.   humidity = dht.readHumidity();
  19.   celsius = dht.readTemperature();
  20.   lcd.setCursor(0,0); //riposiziono il cursore
  21.   lcd.print("Temper.: ");
  22.   lcd.print(celsius);
  23.   lcd.print((char)223);
  24.   lcd.print("C");
  25.   lcd.setCursor(0,1);
  26.   lcd.print("Umidita: ");
  27.   lcd.print(humidity);
  28.   lcd.print(" %");
  29.   delay (2000);
  30. }
RAW Paste Data