#include <DHT.h>
#define DHTPIN 17 // Define the pin where the data line is connected
#define DHTTYPE DHT22 // Define the type of sensor (DHT11 or DHT22)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
}
void loop() {
delay(2000); // Wait a few seconds between measurements
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(); // Read temperature in Celsius
// Check if reading failed
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" *C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // Wait a few seconds between measurements
}