#include <DHT.h>;
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <Servo.h>
LiquidCrystal_I2C lcd(0x27,16,2); // Initializing an LCD object with address 0x27 and dimensions 16x2
Servo moto;// Creating a servo motor object
#define DHTTYPE DHT22// Defining the type of DHT sensor
DHT dht(12, DHTTYPE); // Creating a DHT sensor object with pin 12 and defined type
int humidity; // Variable to store humidity and temperature readings
int temp;
int num=0;
void setup()
{
Serial.begin(9600);
dht.begin();// Initializing DHT sensor
lcd.init();
lcd.backlight();
moto.attach(2);// Attaching servo motor to pin 2
moto.write(90);// Setting initial position of servo motor
Serial.begin(9600);
}
void loop()
{
humidity = dht.readHumidity();
temp = dht.readTemperature();
lcd.setCursor(0, 0); // Setting cursor to first row, first column of LCD
lcd.print("Temperature:");
lcd.print(temp);
lcd.print("C");
lcd.setCursor(0, 1);// Setting cursor to second row, first column of LCD
lcd.print("Humidity:");
lcd.print(humidity);
lcd.print("%");
if(temp>28){// the servo motor runs if temp. is greater than 28 C
moto.write(180);
delay(1000);
moto.write(0);
delay(1000);
}
}