#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "DHT.h"
#define DHT_PIN 4
#define DHTTYPE DHT22
DHT dht(DHT_PIN,DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup()
{
Wire.begin(21,22);
lcd.init();
lcd.backlight();
dht.begin();
delay(2000);
}
void loop()
{
float t=dht.readTemperature();
float h=dht.readHumidity();
lcd.clear();
if (isnan(t) || isnan(h)) {
lcd.setCursor(0, 0);
lcd.print("DHT Error");
} else {
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.print(t);
lcd.print("°C");
lcd.setCursor(0, 1);
lcd.print("Humi:");
lcd.print(h);
lcd.print("%");
}
delay(2000);
}