#include <DHT.h>
#define DHTPIN 2 // Pin where the DHT11 is connected
#define DHTTYPE DHT22 // DHT sensor type
DHT dht(DHTPIN, DHTTYPE);
int controlPin = 7; // Pin to control based on conditions
void setup() {
pinMode(controlPin, OUTPUT);
Serial.begin(9600);
dht.begin();
}
void loop() {
// Read humidity and temperature from the DHT11 sensor
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if the sensor read was successful
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Check humidity and temperature conditions
if (humidity > 60.0 || temperature > 25.0) {
digitalWrite(controlPin, HIGH); // Turn the control pin HIGH
} else {
digitalWrite(controlPin, LOW); // Turn the control pin LOW
}
// Print humidity and temperature to the serial monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("%\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println("°C");
delay(2000); // Wait for 2 seconds before the next reading
}