#include <LiquidCrystal_I2C.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 2
#define DHTTYPE 22
float temp,humidity;
DHT dht(DHTPIN,DHTTYPE);
LiquidCrystal_I2C LCD= LiquidCrystal_I2C (0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
LiquidCrystal_I2C lcd= LiquidCrystal_I2C (0x28, 16, 2); // I2C address 0x28, 16 column and 2 rows
void setup() {
dht.begin();//initialize the dht
Serial.begin(9600);
LCD.init();//initialize the lcd
LCD.setCursor(0,0);//open the backlight
lcd.init();//initialize the lcd
lcd.setCursor(0,0);//open the backlight
}
void loop() {
temp=dht.readTemperature();
humidity=dht.readHumidity();
if(isnan(temp)||isnan(humidity))
Serial.println("Error in DHT sensor");//if there is a error it show a error message
else{
lcd.clear();//clear the values
LCD.clear();//clear the values
lcd.println("Temperature");//display
lcd.println(temp);
LCD.println("Humidity");//display
LCD.println(humidity);
}
delay(2000);//delay in 2s
}