#include #include #include #include #define DHTPIN 2 // Digital pin connected to the DHT sensor #define DHTTYPE DHT11 // DHT 11 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); Serial.println(F("DHT11 test!")); dht.begin(); } void loop() { delay(1000); // DHT11每隔1s更新一次数据 // 读取温湿度 float h = dht.readHumidity(); float t = dht.readTemperature(); // 读取失败处理 if (isnan(h) || isnan(t)) { Serial.println(F("Failed to read from DHT sensor!")); return; } // 计算热指数(利用摄氏温度) float hic = dht.computeHeatIndex(t, h, false); Serial.print(F("Humidity: ")); Serial.print(h); Serial.print(F("% Temperature: ")); Serial.print(t); Serial.print(F(" Heat index: ")); Serial.println(hic); }