#include <DHTesp.h>
#define DHTPIN 15 // Replace with the GPIO pin connected to DHT22 data pin
#define DHTTYPE DHTesp::DHT22
DHTesp dht;
const int buzzerPin = 5; // Replace with the GPIO pin connected to the positive (anode) of the buzzer
void setup() {
Serial.begin(115200);
dht.setup(DHTPIN, DHTTYPE);
pinMode(buzzerPin, OUTPUT);
digitalWrite(buzzerPin, LOW);
}
void loop() {
float temperature = dht.getTemperature();
float humidity = dht.getHumidity();
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Check the temperature and activate the buzzer if it's above a certain threshold
if (temperature > 30.0) {
digitalWrite(buzzerPin, HIGH); // Turn ON the buzzer
delay(1000); // Buzz for 1 second
digitalWrite(buzzerPin, LOW); // Turn OFF the buzzer
delay(1000); // Wait for 1 second before checking again
}
delay(2000); // Adjust the delay as per your requirement
}