//include libraries
#include "DHT.h"
#define DHTPIN 2 // The pin number which is the DHT22 Sensor was Connected
#define DHTTYPE DHT22 // Type of the DHT Sensor
#define TEMPERATURE_THRESHOLD 45 // Temperature threshold
#define BUZZER_PIN 3 // The pin number which is the Buzzer was connected
#define PUSH_BUTTON_PIN 4 // The pin number which is the PushButton was connected
DHT dht(DHTPIN, DHTTYPE);
float temperature; // Variable for assigning the temperature readings
bool isAlarmTurnedOn = false; // To indicate the alarm is turned On or Off
int isPushButtonPressed = 0; // To store the PushButton state
void setup() {
Serial.begin(9600);
pinMode(PUSH_BUTTON_PIN, INPUT);
dht.begin();
}
void loop() {
temperature = dht.readTemperature(); //Read the temperature
if (temperature > TEMPERATURE_THRESHOLD && !isAlarmTurnedOn) { // check whether the temperature exceeds the thresholed value
tone(BUZZER_PIN,450); // set the alarm
isAlarmTurnedOn = true; // indicate that the alarm is turned on
}
isPushButtonPressed = digitalRead(PUSH_BUTTON_PIN); // Reading the Button State
if(isPushButtonPressed == 1 && isAlarmTurnedOn){ // reset the alarm
noTone(BUZZER_PIN); // stop the buzzer sound
isAlarmTurnedOn = false; // indicate that the alarm is turned off
}
}