DHT20 Temperature and Humidity Sensor

View on Amazon
Overview
About DHT20 Temperature and Humidity Sensor
The DHT20 is a high-accuracy digital temperature and humidity sensor that communicates via I²C, offering stable and reliable measurements. Its wide voltage range (2.2V – 5.5V) makes it easy to integrate into various systems.
⚡ Key Features
- High Precision – Ensures accurate temperature & humidity readings.
- I²C Communication – Simple integration with ESP32, Arduino, and other microcontrollers.
- Wide Voltage Range – Operates from 2.2V to 5.5V, making it highly flexible.
- Versatile Applications – Used in HVAC, weather stations, home appliances, and medical devices.
With its stability and ease of use, the DHT20 is an excellent choice for climate monitoring and humidity control applications. 🚀
DHT20 Specifications
Complete technical specification details for DHT20 Temperature and Humidity Sensor
📊 Technical Parameters
DHT20 Pinout
The DHT20 uses an I²C interface with 4 pins for power and communication, offering improved accuracy over the DHT11/22 series.
Visual Pinout Diagram

Pin Types
Quick Tips
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
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply input (2.2V to 5.5V) | Wide voltage range for flexible integration |
2 GND | Power | Ground connection | Connect to ESP32 ground |
3 SDA | Communication | I²C data line | Bidirectional data communication |
4 SCL | Communication | I²C clock line | Clock signal from master device |
Wiring DHT20 to ESP32
Connect the DHT20 using the I²C interface for reliable temperature and humidity measurements.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| DHT20 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply (2.2V to 5.5V supported) | |
2 GND Required | GND | Ground connection | |
3 SDA Required | GPIO21 | I²C data line (default SDA) | |
4 SCL Required | 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 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
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.
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.
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.
Debugging Tips
Use the Serial Monitor to check for error messages and verify the sensor's output. Add debug prints in your code to track the sensor's state.
Use a multimeter to verify voltage levels and check for continuity in your connections. Ensure the power supply is stable and within the sensor's requirements.
Additional Resources
DHT20 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#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.
#include "dht20.h"
#include "esp_log.h"
#define I2C_MASTER_SCL_IO 22
#define I2C_MASTER_SDA_IO 21
#define I2C_MASTER_FREQ_HZ 100000
#define DHT20_ADDR 0x38
static const char *TAG = "DHT20";
void app_main() {
ESP_LOGI(TAG, "Initializing DHT20...");
dht20_dev_t dev;
dht20_init(&dev, I2C_MASTER_SCL_IO, I2C_MASTER_SDA_IO, I2C_MASTER_FREQ_HZ, DHT20_ADDR);
while (1) {
dht20_data_t data;
if (dht20_read(&dev, &data) == ESP_OK) {
ESP_LOGI(TAG, "Temperature: %.2f°C", data.temperature);
ESP_LOGI(TAG, "Humidity: %.2f%%", data.humidity);
} else {
ESP_LOGE(TAG, "Failed to read data from DHT20 sensor");
}
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}This ESP-IDF code configures the ESP32 to communicate with the DHT20 sensor via I²C. The dht20_init function initializes the sensor, while the dht20_read function fetches temperature and humidity data. If successful, the data is logged to the console every two seconds; otherwise, an error message is displayed.
sensor:
- platform: dht
model: DHT20
pin: I2C
temperature:
name: "DHT20 Temperature"
humidity:
name: "DHT20 Humidity"
update_interval: 2sThis ESPHome configuration sets up the DHT20 sensor to provide temperature and humidity data over the I²C interface. The sensor readings update every two seconds.
platformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
dfrobot/DFRobot DHT20 Library
wire
monitor_speed = 115200main.cpp
#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() {
Serial.print("Temperature: ");
Serial.print(dht20.getTemperature(), 1);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(dht20.getHumidity(), 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.
Wrapping Up DHT20
The ESP32 DHT20 Temperature and Humidity Sensor is a powerful environment sensor that offers excellent performance and reliability. With support for multiple development platforms including Arduino, ESP-IDF, ESPHome, PlatformIO, and MicroPython, it's a versatile choice for your IoT projects.
Best Practices
For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.
Safety First
Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.
Ready to Start Building?
Now that you have all the information you need, it's time to integrate the DHT20 into your ESP32 project and bring your ideas to life!






