#include <DHT.h>
#define DHTPIN 6
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float hum;
float temp;
#define ALARM_PIN 13 // Define the pin for the alarm (e.g., digital pin 13)
void setup() {
Serial.begin(9600); // Initialize serial communication
dht.begin(); // Initialize the DHT sensor
pinMode(ALARM_PIN, OUTPUT); // Set the alarm pin as output
digitalWrite(ALARM_PIN, LOW); // Initialize the alarm to be off
}
void loop() {
hum = dht.readHumidity(); // Read humidity
temp = dht.readTemperature(); // Read temperature
Serial.print("Humidity: ");
Serial.print(hum);
Serial.println(" %");
Serial.print("Temp: ");
Serial.print(temp);
Serial.println(" C");
Serial.println("-----------------------------");
// Check if temperature reaches 50 degrees
if (temp >= 50) {
digitalWrite(ALARM_PIN, HIGH); // Turn on the alarm
} else {
digitalWrite(ALARM_PIN, LOW); // Turn off the alarm
}
delay(2000); // Wait for 2 seconds before the next reading
}