#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27,16,2);
//Constants
#define DHTPIN 7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float t = dht.readTemperature();
float h = dht.readHumidity();
void setup()
{
Serial.begin(9600);
Serial.println("Temperature and Humidity Sensor Test");
dht.begin();
lcd.init();
lcd.backlight();
}
void loop()
{
t = dht.readTemperature();
h = dht.readHumidity();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %, Temp: ");
Serial.print(t);
Serial.print(" ° Celcius");
lcd.setCursor(0, 0);
lcd.println(" Now Temperature ");
lcd.setCursor(0,1);
lcd.print("T:");
lcd.print(t);
lcd.print("C");
lcd.setCursor(9,1);
lcd.print("H:");
lcd.print(h);
lcd.print("%");
delay(1000);
static float oldT = t;
static float oldH = h;
float newT = t;
float newH = h;
if(newT < oldT)
{
digitalWrite(3, HIGH);
tone(12,500);
digitalWrite(2, LOW);
}
else if(newT > oldT)
{
digitalWrite(2, HIGH);
tone(12,600);
digitalWrite(3, LOW);
}
else
{
digitalWrite(2, LOW);
digitalWrite(3, LOW);
noTone(12);
}
oldT = newT;
}