DHT20 Temperature and Humidity Sensor
The DHT20 is a high-precision digital temperature and humidity sensor with an I²C interface. It features low power consumption, fast response, and excellent long-term stability, making it ideal for a wide range of environmental monitoring applications.

On this page
DHT20 pinout
The DHT20 uses an I²C interface with 4 pins for power and communication, offering improved accuracy over the DHT11/22 series.
| Pin | Type | Description | Notes |
|---|---|---|---|
| VCC | Power | Power supply input (2.2V to 5.5V) | Wide voltage range for flexible integration |
| GND | Power | Ground connection | Connect to ESP32 ground |
| SDA | Communication | I²C data line | Bidirectional data communication |
| SCL | Communication | I²C clock line | Clock signal from master device |
Uses standard I²C protocol for easy integration
Default I²C address is 0x38
Higher accuracy than DHT11/22 series
Pull-up resistors usually built into modules
Operates from -40°C to +80°C
Wiring the DHT20 to ESP32
Connect the DHT20 using the I²C interface for reliable temperature and humidity measurements.
| DHT20 pin | ESP32 pin | Purpose |
|---|---|---|
| VCC | 3.3V | Power supply (2.2V to 5.5V supported) |
| GND | GND | Ground connection |
| SDA | GPIO21 | I²C data line (default SDA) |
| SCL | GPIO22 | I²C clock line (default SCL) |
GPIO21/22 are default I²C pins on ESP32
I²C address is 0x38 (fixed)
Most modules have built-in pull-up resistors
Can share I²C bus with other devices
DHT20 code examples
DHT20 Arduino example
Copy#include <Wire.h>
#include "DFRobot_DHT20.h"
DFRobot_DHT20 dht20;
void setup() {
Serial.begin(115200);
while (dht20.begin()) {
Serial.println("Failed to initialize DHT20 sensor!");
delay(1000);
}
}
void loop() {
float temperature = dht20.getTemperature();
float humidity = dht20.getHumidity();
Serial.print("Temperature: ");
Serial.print(temperature, 1);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity * 100, 1);
Serial.println(" %");
delay(2000);
}This Arduino code initializes the DHT20 sensor using the DFRobot DHT20 library. In the setup() function, it attempts to initialize the sensor and prints an error message if initialization fails. In the loop() function, it reads the temperature and humidity values from the sensor and prints them to the Serial Monitor every two seconds.
DHT20 ESP-IDF example
Copy// Requires the esp-idf-lib AHT driver (the DHT20 is an AHT20) from the ESP Component Registry:
// idf.py add-dependency "esp-idf-lib/aht^1.0.8"
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "aht.h"
#define SDA_GPIO GPIO_NUM_21
#define SCL_GPIO GPIO_NUM_22
void app_main(void)
{
ESP_ERROR_CHECK(i2cdev_init());
aht_t dev;
memset(&dev, 0, sizeof(aht_t));
dev.mode = AHT_MODE_NORMAL;
dev.type = AHT_TYPE_AHT20;
ESP_ERROR_CHECK(aht_init_desc(&dev, AHT_I2C_ADDRESS_GND, 0, SDA_GPIO, SCL_GPIO));
ESP_ERROR_CHECK(aht_init(&dev));
while (1) {
float temperature, humidity;
if (aht_get_data(&dev, &temperature, &humidity) == ESP_OK)
printf("Temp %.1f C, Hum %.1f%%\n", temperature, humidity);
else
printf("Could not read data from sensor\n");
vTaskDelay(pdMS_TO_TICKS(2000));
}
}ESP-IDF ships no DHT20 driver of its own, so this example uses the maintained esp-idf-lib AHT driver from the ESP Component Registry - the DHT20 is the same sensor as the AHT20 in a different package. Install it into your project first with idf.py add-dependency "esp-idf-lib/aht^1.0.8", then build as usual.
The device is configured as AHT_TYPE_AHT20, and aht_get_data() returns temperature in Celsius and relative humidity in percent. i2cdev_init() sets up the shared I2C layer used by all esp-idf-lib drivers. Unlike the DHT11/DHT22, the DHT20 talks plain I2C, so it can share the bus with other I2C devices.
DHT20 ESPHome example
Copyi2c:
sda: GPIO21
scl: GPIO22
sensor:
- platform: aht10
variant: AHT20 # the DHT20 is an AHT20 in a different package
temperature:
name: "DHT20 Temperature"
humidity:
name: "DHT20 Humidity"
update_interval: 2sThe DHT20 is the same sensor as the AHT20 in a different package and talks I2C - it does not work with ESPHome's dht platform (which is for the single-wire DHT11/DHT22 family). Use the aht10 platform with variant: AHT20 on the default I2C pins, as shown.
DHT20 PlatformIO example
Copy[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
lib_deps =
dfrobot/DFRobot_DHT20 @ ^1.0.0#include <Arduino.h>
#include <Wire.h>
#include "DFRobot_DHT20.h"
DFRobot_DHT20 dht20;
void setup() {
Serial.begin(115200);
while (dht20.begin()) {
Serial.println("Failed to initialize DHT20 sensor!");
delay(1000);
}
}
void loop() {
float temperature = dht20.getTemperature();
float humidity = dht20.getHumidity();
Serial.print("Temperature: ");
Serial.print(temperature, 1);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity * 100, 1);
Serial.println(" %");
delay(2000);
}This PlatformIO code initializes the DHT20 sensor using the DFRobot DHT20 library. The program continuously reads temperature and humidity values and prints them to the Serial Monitor every two seconds.
DHT20 MicroPython example
Copy# Requires driver: ahtx0.py from https://github.com/targetblank/micropython_ahtx0
# Copy it to the board: mpremote cp ahtx0.py :
import machine
import time
from ahtx0 import AHT20
# Initialize I2C
i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(21))
# The DHT20 is an AHT20 in a different package - the ahtx0 driver works unchanged
sensor = AHT20(i2c)
# Main loop
while True:
try:
# Read temperature and humidity
temperature = sensor.temperature
humidity = sensor.relative_humidity
# Print readings
print("Temperature: {:.2f} °C".format(temperature))
print("Humidity: {:.2f} %".format(humidity))
# Wait for 2 seconds
time.sleep(2)
except Exception as e:
print("Error reading sensor:", e)
time.sleep(2)The DHT20 is the same sensor as the AHT20 in a different package and talks plain I2C, so the community ahtx0 driver works unchanged (copy ahtx0.py from targetblank/micropython_ahtx0 to the board). temperature and relative_humidity are read every 2 seconds on the default I2C pins.
DHT20 specifications
About the DHT20
The DHT20 keeps the classic DHT11-family through-hole shell and pinout, but almost everything under the hood changed: it’s electrically the AHT20 sensor - the same ASIC from Aosong’s AHT series - repackaged, talking plain I2C at the fixed address 0x38 instead of the single-wire protocol its DHT11/DHT22 namesakes use. That means no bit-banged timing to get right, and it can share the I2C bus with other sensors, which the single-wire DHT parts can’t do without extra glue code.
One nuance worth knowing: even though the silicon is shared with the AHT20, Asair’s own DHT20 datasheet publishes slightly more conservative accuracy figures than the AHT20’s spec sheet - ±0.5 degC and ±3% RH here, versus ±0.3 degC and ±2% RH for the AHT20. The difference is unlikely to matter for a room monitor, but it means the two parts aren’t quite interchangeable numbers on paper despite being the same chip.
If you’re buying new rather than matching an old DHT11/DHT22 hole pattern, an AHT20 breakout is the same sensor in a smaller, often connector-equipped package for about the same money. Either way, code written for one drops onto the other with just a library swap - both speak the same AHT-family I2C commands under the hood.
DHT20 troubleshooting
Initialization Failure
›
Issue: The sensor fails to initialize, and no data is received.
Solution: Ensure that the I²C address (0x38) is correctly specified in your code. Verify that the sensor is properly connected to the I²C bus and that there are no loose connections. Use an I²C scanner to confirm that the sensor is detected on the bus.
Incorrect Readings
›
Issue: The sensor provides inaccurate temperature or humidity readings.
Solution: Ensure that the sensor is not exposed to rapid environmental changes or placed near heat sources. Allow the sensor to stabilize after power-up, as recommended by the manufacturer. Calibration may be necessary for precise measurements.
Communication Errors
›
Issue: Communication with the sensor is intermittent or fails.
Solution: Check the integrity of the I²C connections and ensure that appropriate pull-up resistors are in place if not already included on the sensor module. Verify that the I²C bus speed is set correctly, typically 100 kHz or 400 kHz, as supported by the sensor.
Resources
Similar sensors





