# include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN , DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2); // Change the address and dimensions if necessary
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
dht.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Humidity & Tem");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000); // this speeds up the simulation
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h)||isnan(t)){
Serial.println("Failed to read from the sensor !!");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Sensor failed");
return;
}
Serial.print("Humidity is : ");
Serial.println(h);
Serial.print("Temperature is: ");
Serial.println(t);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Hum: ");
lcd.setCursor(4, 0);
lcd.print(h);
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.setCursor(5, 1);
lcd.print(t);
}