#include <DHT.h>
#define DHTPIN 2 // Pin where the DHT sensor is connected
#define DHTTYPE DHT22 // DHT 11 or DHT 12
// Replace DHTTYPE with DHT12 if you're using DHT12 sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000); // Wait for 2 seconds between measurements
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
}