/* * @Author: dugulingping * @Date: 2022-04-15 21:25:51 * @LastEditTime: 2022-05-23 16:57:02 * @LastEditors: dugulingping * @Description: DHT11 * @FilePath: \test\DHT11\DHT11.ino */ #include "DHT.h" #define DHTPIN 4 #define DHTTYPE DHT22 // DHT 11` DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); Serial.println(F("\nDHT11 test!")); dht.begin(); } void loop() { delay(2000); // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(false); // Check if any reads failed and exit early (to try again). if (isnan(h) || isnan(t)){ Serial.println(F("Failed to read from DHT sensor!")); return; } // Compute heat index in Celsius (isFahreheit = false) float hic = dht.computeHeatIndex(t, h, false); Serial.print(F("湿度: ")); Serial.print(h); Serial.print(F("%\t温度: ")); Serial.print(t); Serial.print(F("°C ")); Serial.print(F("\t体感温度: ")); Serial.print(hic); Serial.print(F("°C \n")); }