#include "DHT.h"
#include <Servo.h>
#define DHTPIN 3
#define DHTTYPE DHT22 //declare type of dht sensor
int btn1 = 7; //pin number for button
int ld = 11; //pin number for LED
float threshold = 38.00; //temperature theshold
int timer = 200; //delay time
DHT el(DHTPIN, DHTTYPE);
Servo svo; // create Servo object to control the servo
void setup() {
pinMode(ld, OUTPUT); //initialising led as an output pin/device
pinMode(btn1, INPUT); //initialising button as an input pin/device
Serial.begin(9600);
el.begin(); // start the communication between the sensor and the board
svo.attach(5);
}
void loop() {
float t = el.readTemperature(); //to read temp. from the sensor
float h = el.readHumidity(); //to read the humidity fron sensor
bool btnState = digitalRead(btn1); //read the state of the btn
if(btnState == true){
svo.write(180); // move servo to 100 degrees
digitalWrite(ld, HIGH); //turn on the LED
Serial.print("temperature = ");
Serial.print(t);
Serial.println(".C");
Serial.print("humidity = ");
Serial.print(h);
Serial.println("%");
Serial.println("*******************************************");
delay(1000);
}else{
digitalWrite(ld, LOW); // turn of the LED
svo.write(0); // move servo to 0 degrees
}
while(t > threshold){
digitalWrite(ld, HIGH);
delay(timer);
digitalWrite(ld, LOW);
delay(timer);
Serial.println("Temperature is abnormally high");
t = el.readTemperature();
}
/* Serial.print("temperature = ");
Serial.print(t);
Serial.println(".C");
Serial.print("humidity = ");
Serial.print(h);
Serial.println("%");
delay(1000); */
/* bool btnState = digitalRead(btn1);
Serial.print("button signal= ");
Serial.println(btnState); */
}