// Install from the Library Manager: // "LiquidCrystal I2C" and "DHTlib" #include #include #include // The DHT11's data (DATA) pin const int DHT_PIN = 2; // Between readings (ms): DHT11 is slow const unsigned long READ_EVERY = 2000; // I2C address: 0x27 on most, 0x3F on some LiquidCrystal_I2C lcd(0x27, 16, 2); dht DHT; void setup() { lcd.init(); lcd.backlight(); lcd.print("Measuring..."); Serial.begin(9600); } void loop() { delay(READ_EVERY); int chk = DHT.read11(DHT_PIN); if (chk != DHTLIB_OK) { // No reading: say so on the screen lcd.setCursor(0, 0); lcd.print("Sensor error "); lcd.setCursor(0, 1); lcd.print("Check the wires "); Serial.println("Sensor could not be read"); return; } // 16 characters fit on a line lcd.setCursor(0, 0); lcd.print("Temp: "); lcd.print(DHT.temperature, 0); // 223: the LCD's degree sign lcd.print((char)223); // Trailing spaces wipe the old text lcd.print("C "); lcd.setCursor(0, 1); lcd.print("Humidity: "); lcd.print(DHT.humidity, 0); lcd.print(" % "); Serial.print("Temperature: "); Serial.print(DHT.temperature, 0); Serial.print(" °C Humidity: "); Serial.print(DHT.humidity, 0); Serial.println(" %"); }