#include <DHT.h>
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int LED1 = 4;
int LED2 = 5;
void setup() {
Serial.begin(9600);
Serial.println("DHT22 test");
dht.begin();
lcd.init(); lcd.backlight();
pinMode(LED1,OUTPUT); pinMode(LED2,OUTPUT);
}
void loop() {
delay(1000);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(t)|| isnan(h)){
Serial.println("Failed to read from DHT ");
}
else {
Serial.print("Humidity: "); Serial.print(h); Serial.print(" %╲t");
lcd.setCursor(0,0); lcd.print("Humi: ");
lcd.setCursor(7,0); lcd.print(h);
lcd.setCursor(15,0); lcd.print("%");
Serial.print("Temperature: "); Serial.print(t); Serial.println(" C");
lcd.setCursor(0,1); lcd.print("Temp = ");
lcd.setCursor(7,1); lcd.print(t);
lcd.setCursor(15,1); lcd.print("C");
if((h >= 75)|| (t >=36)){
digitalWrite(LED1,LOW);
digitalWrite(LED2,HIGH);
}
else{
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
}
}
}