/*create by group
muhd fawwaz
MOHD NAZRI BIN MOHD ZUKI - 52103121615
aqil fitri
this programe about barn temperature and will automatically open the window if the
surrounding getting too hot*/
//define and declare
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include "DHT.h"
#define DHTPIN 13
#define speakerPin 10
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);
Servo myservo;
int led = 2;
void setup()
{
//FOR OUTPUT
Serial.begin(11500);
Serial.println("BARN TEMPERATURE MONITORING SYSTEM");
//for lcd display
lcd.begin(16, 2);
//led and speaker
dht.begin();
pinMode(led, OUTPUT);
pinMode(speakerPin, OUTPUT);
//the servo attach
myservo.attach(3);
}
void loop()
{
//read surrounding temperature and humidity
float h = dht.readHumidity();
float t = dht.readTemperature();
delay(50);
//DISPLAY LCD
lcd.setCursor(0,0);
lcd.println("TEMP:");
lcd.print(t);
lcd.println(" 'C");
lcd.setCursor(0,1);
lcd.println("HUMID:");
lcd.print(h);
lcd.println(" %");
//DISPLAY THE SERIAL
Serial.print("TEMPERATURE ");
Serial.print(t);
Serial.print(" *C\t");
Serial.print("HUMIDITY: ");
Serial.print(h);
Serial.println(" %");
if(t>30)
{
//led will turn on if the temperature more than 30 celcius
digitalWrite(led, HIGH);
delay(250);
digitalWrite(led, LOW);
delay(250);
myservo.write(0); //the servo turn 0 degrees left
delay(1000);
//speker will turn on if the temperature more than 30 celcius
tone(speakerPin, 50, 1000);
delay(500);
noTone(speakerPin);
delay(500);
}
else
{
//led will turn off if the temperature less than 30 celcius
digitalWrite(led, LOW);
myservo.write(180);
delay(1000);
}
}