//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)
DHT dht(DHTPIN, DHTTYPE); //Initialize DHT sensor for normal 16mhz Arduino
//Variables:
int chk;
float H; //Humidity value
float T; //Temperature value
void setup(){
//Initialize LCD, DHT22 sensor and buzzer:
lcd.init(); lcd.backlight();
//Serial Communication is starting with 9600 of baudrate speed
Serial.begin(115200);
dht.begin();
pinMode(13, OUTPUT);
//Print some text in Serial Monitor
Serial.println("DHT22 sensor with Arduino Uno R3!");
pinMode(9, OUTPUT); pinMode(10, OUTPUT);
}
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(9, HIGH);
digitalWrite(10, LOW);
lcd.setCursor(1, 0);
lcd.print(" Humidity: ");
lcd.setCursor(4, 1);
lcd.print(H);
lcd.setCursor(9, 1);
lcd.print(" %");
delay(1000);
lcd.setCursor(1, 0);
lcd.print(" Temperature: ");
lcd.setCursor(4, 1);
lcd.print(T);
lcd.setCursor(9, 1);
lcd.print( (char)223);
lcd.print("C");
delay(1000);
lcd.setCursor(1, 0);
lcd.println(" Cool down! ");
lcd.setCursor(4, 1);
lcd.println("--------");
}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”*/
digitalWrite(9, LOW);
digitalWrite(10, LOW);
lcd.setCursor(1, 0);
lcd.print(" Humidity: ");
lcd.setCursor(4, 1);
lcd.print(H);
lcd.setCursor(9, 1);
lcd.print(" %");
delay(1000);
lcd.setCursor(1, 0);
lcd.print(" Temperature: ");
lcd.setCursor(4, 1);
lcd.print(T);
lcd.setCursor(9, 1);
lcd.print( (char)223);
lcd.print("C");
delay(1000);
lcd.setCursor(1, 0);
lcd.println(" Normal ");
lcd.setCursor(4, 1);
lcd.println("-------");
}
/*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){
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
lcd.setCursor(1, 0);
lcd.print(" Humidity: ");
lcd.setCursor(4, 1);
lcd.print(H);
lcd.setCursor(9, 1);
lcd.print(" %");
delay(1000);
lcd.setCursor(1, 0);
lcd.print(" Temperature: ");
lcd.setCursor(4, 1);
lcd.print(T);
lcd.setCursor(9, 1);
lcd.print( (char)223);
lcd.print("C");
delay(1000);
lcd.setCursor(1, 0);
lcd.println(" Be ware! ");
lcd.setCursor(4, 1);
lcd.println("Temp HIGH");
}
if(H >= 70.00 && T < 30.00){
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
lcd.setCursor(1, 0);
lcd.print(" Humidity: ");
lcd.setCursor(4, 1);
lcd.print(H);
lcd.setCursor(9, 1);
lcd.print(" %");
delay(1000);
lcd.setCursor(1, 0);
lcd.print(" Temperature: ");
lcd.setCursor(4, 1);
lcd.print(T);
lcd.setCursor(9, 1);
lcd.print( (char)223);
lcd.print("C");
delay(1000);
lcd.setCursor(1, 0);
lcd.println(" Be ware! ");
lcd.setCursor(4, 1);
lcd.println("Hum. HIGH");
}
}