#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 16, 2); //16 col, 2 row
#define DHTPIN A3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE); //initi senr to 16mhz arduino
int h, t;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
//Serial.println("Temperature and Humidity Sensor test!");
dht.begin();
lcd.init();
lcd.backlight();
pinMode(2, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
//read data and store it to variables h ,t.
//reading them takes 250 ms
h = dht.readHumidity();
t = dht.readTemperature();
/*//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %, Temp: ");
Serial.print(t);
Serial.println(" ° Celsius");
*/
//set lcd cursor..
lcd.setCursor(0,0);
lcd.println("Temperature and");
lcd.setCursor(0,1);
lcd.println("Humidity sensor!");
delay(1000);
lcd.setCursor(0,0);
lcd.println("Simple Ciruits ");
lcd.setCursor(0,1); //below row
lcd.println("T:");
lcd.print(t);
lcd.println("C");
lcd.setCursor(8,1); //below row
lcd.println("H:");
lcd.print(h);
lcd.println("%");
if(h>=50 || t>=50)
digitalWrite(2, HIGH);
else
digitalWrite(2, LOW);
delay(1000);
}