//LCD I2C library:
#include <LiquidCrystal_I2C.h>
//DHT22 sensor library:
#include <DHT.h>
//LCD I2C address 0x27, 16 column and 2 rows!
LiquidCrystal_I2C lcd(0x27, 16, 2);
//Constants:
#define DHTPIN 2 //what pin we're connected to
#define DHTTYPE DHT22 //DHT 22 (AM2302)
#define light 8
DHT dht(DHTPIN, DHTTYPE); //Initialize DHT sensor for normal 16mhz Arduino
//Variables:
float H; //Humidity value
float T; //Temperature value
//Initialize LCD and DHT22 sensor:
void setup() {
lcd.init();
lcd.backlight();
dht.begin();
pinMode(light,OUTPUT);
// Print some text in Serial Monitor
Serial.begin(9600);
Serial.println("DHT22 sensor with Arduino Uno R3!");
}
void loop() {
delay(2000);
// Read data and store it to variables hum and temp
H = dht.readHumidity();
T = dht.readTemperature();
// Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(H);
Serial.println(" %; ");
Serial.print("Temperature: ");
Serial.print(T);
Serial.println(" Celsius.\n");
/* If humidity is higher than 70% &
temperature is higher than 30 degrees Celsius
then it will show on LCD „Too warm! Cool down!” */
if (H >= 70.00 && T >= 30.00) {
digitalWrite(light,HIGH);
lcd.println(" Too warm! ");
lcd.setCursor(0, 1);
lcd.println(" Cool down! ");
lcd.setCursor(0, 0);
delay(2000);
digitalWrite(light,LOW);
} else {
/* If humidity is lower than 70% &
temperature is lower than 30 degrees Celsius
then it will show on LCD „Temp. & hum. are in normal limits” */
lcd.println("Temp. & hum. are");
lcd.setCursor(0, 1);
lcd.println("in normal limits");
lcd.setCursor(0, 0);
}
/* If either humidity is lower than 70%, but
temperature is higher than 30 degrees Celsius,
then it will show on LCD „Be ware! Temp. too high” or
humidity is higher than 70%, but
temperature is lower than 30 degrees Celsius, then
it will show on LCD „Be ware! Hum. too high” */
if (H < 70.00 && T >= 30.00) {
lcd.println("Be ware! ");
lcd.setCursor(0, 1);
lcd.println("Temp. too high! ");
lcd.setCursor(0, 0);
}
if (H >= 70.00 && T < 30.00) {
lcd.println("Be ware!" );
}
}