#include <DHT.h>
// Define the pin where the DHT22 sensor is connected
#define DHTPIN 2
// Define the type of the DHT sensor (DHT22)
#define DHTTYPE DHT22
// Create a DHT object
DHT dht(DHTPIN, DHTTYPE);
// Define the pin where the LED is connected
int ledPin = 13;
void setup() {
// Start the serial communication
Serial.begin(9600);
// Initialize the DHT sensor
dht.begin();
// Set the LED pin as an output
pinMode(ledPin, OUTPUT);
}
void loop() {
// Read temperature and humidity
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Print temperature and humidity to the serial monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Check conditions and control the LED
if (temperature > 75 || humidity > 30) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
}
// Delay for a short period
delay(1000);
}