#include <DHT.h>
DHT dht(2, DHT11);
void setup()
{
Serial.begin(115200);
dht.begin();
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
if (isnan(h) || isnan(t) || isnan(f))
{
Serial.println("Failed to read DHT sensor!");
delay(1000);
}
Serial.print("Humidity: " + String(h) + "% ");
Serial.print("Temperature: " + String(t) + "C ");
Serial.print(String(f) + "°F ");
Serial.print("Heat index: " + String(hic) + "°C ");
Serial.println(String(hif) + " °F");
delay(1000);
}