#include "DHT.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
DHT el(DHTPIN, DHTTYPE);
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
}
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){
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
}
while(t > 38.00){
digitalWrite(ld, HIGH);
delay(200);
digitalWrite(ld, LOW);
delay(200);
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); */
}