#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
dht.begin();
lcd.init();
lcd.backlight();
lcd.setCursor(5, 0);
lcd.print("DHT SENSOR");
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
lcd.setCursor(1, 1);
lcd.print("Hum");
lcd.print(h);
lcd.print("%");
lcd.setCursor(1, 2);
lcd.print("Temp");
lcd.print(t);
lcd.print("C ");
lcd.print(f);
lcd.print("F");
lcd.setCursor(1, 3);
lcd.print("Heat");
lcd.print(hic);
lcd.print("C ");
lcd.print(hif);
lcd.println("F");
lcd.setCursor(0, 0);
}