#include <DHT.h>
// Define DHT sensor type and pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTPIN 2 // Pin connected to the data pin of DHT22
DHT dht(DHTPIN, DHTTYPE);
// Define LED pin
#define R 8
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Initialize DHT sensor
dht.begin();
// Set LED pin as output
pinMode(R, OUTPUT);
}
void loop() {
// Read temperature as Celsius
float temperature = dht.readTemperature();
// Check if reading was successful
if (isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
// Check if temperature is above 33°C
if (temperature > 33) {
// Blink LED continuously
digitalWrite(R, HIGH);
delay(50); // LED ON for 500ms
digitalWrite(R, LOW);
delay(50); // LED OFF for 500ms
} else {
// Keep LED OFF
digitalWrite(R, LOW);
}
// Small delay before next reading
delay(1000); // Read every 2 seconds
}