#include <dht.h> //add the dht sensor library
#include <LiquidCrystal_I2C.h> //add the i2c lcd library
#define sensorPin 8 //set digital pin 8 to the sensorPin
dht Sensor; //create an object named Sensor and connect it to the dht
//create an object named display - connect it to the lcd library and set the parameters
//set the i2c address and the dimension - 16, 2
LiquidCrystal_I2C display(0x27, 16, 2);
int led = 2; //assign pin 2 to the led variable
int buzzer = 3; //assign pin 3 to buzzer variable
void setup() {
// put your setup code here, to run once:
display.init(); //initiate the LCD
display.clear(); //clear any display text
display.backlight(); //turn on the backlight
pinMode(led, OUTPUT); //set led as an output
pinMode(buzzer, OUTPUT); //set buzzer as an output
}
void loop() {
// put your main code here, to run repeatedly:
int collect = Sensor.read22(sensorPin); //initiate collection of data from the sensor
float temp = Sensor.temperature;//collect temp data
float hum = Sensor.humidity;//collect humidity data
if (temp > 30.0)
{
digitalWrite(led, HIGH);
tone(buzzer, 2000);
delay(100);
noTone(buzzer);
delay(100);
}
digitalWrite(led, LOW);
noTone(buzzer);
display.setCursor(0,0); //column 0, row 0
display.print("Temperature:"); //display this text
display.setCursor(12, 0); //column 12, row 0
display.print(temp); //display variable value
display.setCursor(0,1); //column 0, row 1
display.print("Humidity:"); //display this text
display.setCursor(10, 1); //column 10, row 1
display.print(hum); //display variable value
delay(1000); //delay 1 sec
display.clear(); //clear text
}