#include "DHT.h"
#define DHTPIN 16 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11 sensor type
DHT dht(16, DHT11);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait a few seconds between measurements
// Reading humidity and temperature
float h = dht.readHumidity();
float t = dht.readTemperature(); // Temperature in Celsius
float f = dht.readTemperature(true); // Temperature in Fahrenheit
// Check if any reads failed and exit early (to try again next time)
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(h);
Serial.println("%");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println("°C");
Serial.print("Temperature: ");
Serial.print(f);
Serial.println("°F");
Serial.println();
}