#include "DHT.h" #define DHTPIN D1 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(115200); dht.begin(); } void loop() { delay(500); // The DHT22 returns at most 1 measurement every 2s float h = dht.readHumidity(); // Reads the humidity in % float t = dht.readTemperature(); // Reads the temperature in degrees Celsius float f = dht.readTemperature(true); // true returns the temperature in Fahrenheit if (isnan(h) || isnan(t) || isnan(f)) { Serial.println(F("Failed reception")); return; // Returns an error if the ESP32 does not receive any measurements } Serial.print("Humidite: "); Serial.print(h); Serial.print("% Temperature: "); Serial.print(t); Serial.print("°C, "); Serial.print(f); Serial.println("°F"); // Transmits the received measurements to the serial terminal }