Grove DHT11 with ESP32: Wiring, Arduino Code and Read Errors
Read the Grove DHT11 temperature and humidity sensor with ESP32, select the correct library sensor type and troubleshoot invalid readings.
On this page
Identify DHT11 rather than DHT22 or DHT20Account for sensor revision when reading specificationsWire it to XIAO ESP32-C3Install the library and choose DHT11Upload the minimal temperature/humidity exampleCheck the first measurementsTroubleshoot NaN and inconsistent readingsDownloads and reference versionsProduct and related tutorials
Identify DHT11 rather than DHT22 or DHT20
This tutorial is for the Grove product labelled DHT11. A similar Grove socket or “temperature and humidity” name does not establish the sensor type. DHT11 uses a timed single-data-pin protocol; it is not an I2C device and does not respond to an I2C address scanner. DHT22/AM2302 needs a different library type, while DHT20 needs a different interface/driver.
Account for sensor revision when reading specifications
Supplier descriptions can refer to updated DHT11 elements while older manufacturer tutorials quote a narrower range. Match the supplied sensor marking and revision before relying on limits or accuracy, particularly below 0 °C. Do not borrow DHT22 accuracy or range for DHT11. For the initial check use a stable indoor environment, away from condensation, direct heat and the controller’s warm regulator.
Wire it to XIAO ESP32-C3
| Grove wire / label | Example connection |
|---|---|
| Red / VCC | 3.3 V |
| Black / GND | GND |
| Yellow / SIG | XIAO D0 = ESP32-C3 GPIO2 |
| White / NC | Not used for this sensor |
Using a Grove Base, choose its D0 socket and confirm the printed 3V3 rail. With another ESP32 board, pick a suitable free GPIO and change SENSOR_PIN; do not assume its D0 label means the same pin. Bare four-pin DHT elements require their own pinout/pull-up check rather than this Grove cable mapping.
Install the library and choose DHT11
Install DHT sensor library by Adafruit and its Adafruit Unified Sensor dependency. Select XIAO_ESP32C3 and enable USB CDC for the example. The constructor explicitly uses DHT11; leaving a downloaded example set to DHT22 is a common source of wrong or failed readings.
Upload the minimal temperature/humidity example
#include <Arduino.h>
#include <DHT.h>
constexpr int SENSOR_PIN = D0; // XIAO ESP32-C3 D0 = GPIO2
DHT sensor(SENSOR_PIN, DHT11);
void setup() {
Serial.begin(115200);
sensor.begin();
delay(2000);
}
void loop() {
float rh = sensor.readHumidity();
float c = sensor.readTemperature();
if (isnan(rh) || isnan(c)) {
Serial.println("No valid DHT11 reading: check type, SIG, power and cable");
} else {
Serial.printf("Temperature: %.1f C | Humidity: %.1f %%RH\n", c, rh);
}
delay(2500); // Allow the sensor's sampling interval
}
Open Serial Monitor at 115200. The 2.5-second interval allows time between samples and keeps the first experiment easy to inspect. More decimal places in the printed output do not create more sensor resolution or accuracy.
Check the first measurements
Expect a temperature in Celsius and relative humidity in %RH under room conditions. Let the module settle, compare several readings and note the environment. A decimal in the output is formatting, not a calibration certificate. Use a suitable reference instrument for accuracy checks and allow both instruments to reach the same conditions before drawing conclusions.
Troubleshoot NaN and inconsistent readings
| Problem | Check next |
|---|---|
| No valid DHT11 reading | Library type, SIG pin, common ground and sensor power |
| I2C scanner sees nothing | Expected: this DHT11 is not I2C |
| Fails only with a long cable | Start with a short cable, stable rail and correct pull-up arrangement |
| Values shift near electronics | Move the sensor away from heat sources and give it time to settle |
| Application requires a wide cold-weather range | Confirm the exact DHT11 revision or choose a documented alternative; do not change a software constant to invent a capability |
Downloads and reference versions
Download the minimal Arduino sketch (.zip)
- Seeed Grove DHT11 interface and revision reference
- Adafruit DHT library and supported sensor types
- Seeed XIAO ESP32-C3 board setup
Reviewed 22 October 2026. The minimal sketch was compiled with Arduino-ESP32 3.3.0. Its ZIP includes the source and exact board profile; compilation does not establish electrical operation or sensor accuracy. No physical bench test was performed.
Example dependencies: DHT sensor library 1.4.7 and Adafruit Unified Sensor 1.1.15
Product and related tutorials
Share the product link, hardware revision, software version and any error messages.
Contact ESP32S support →