DHT22 / AM2302 Temperature and Humidity Sensor

View on Amazon
Overview
About DHT22 / AM2302 Temperature and Humidity Sensor
The DHT22, also known as AM2302, is a low-cost digital sensor designed for precise temperature and humidity measurement. It uses a capacitive humidity sensor and a thermistor for reliable data collection and communicates via a single-wire digital interface, ensuring easy integration with ESP32, Arduino, and other microcontrollers.
⚡ Key Features
- Improved Accuracy & Range – More precise than DHT11, with a wider measurement range.
- Single-Wire Communication – Simple interfacing with microcontrollers.
- Capacitive Humidity Sensing – Ensures stable and long-term performance.
- Ideal for Demanding Applications – Used in weather stations, HVAC systems, and industrial monitoring.
With its affordability and high accuracy, the DHT22 is a great choice for climate monitoring and smart home applications. 🚀
Get Your DHT22 / AM2302
💡 Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.
DHT22 / AM2302 Specifications
Complete technical specification details for DHT22 / AM2302 Temperature and Humidity Sensor
📊 Technical Parameters
DHT22 / AM2302 Pinout
The DHT22/AM2302 uses the same 4-pin layout as the DHT11, with improved accuracy and wider measurement range.
Visual Pinout Diagram

Pin Types
Quick Tips
Uses proprietary single-wire digital protocol,⚠️ Requires 5kΩ to 10kΩ pull-up resistor on DATA pin
Higher accuracy than DHT11 (±0.5°C vs ±2°C),⏱️ Can be read once every 2 seconds
Operates in wider temperature range (-40°C to 80°C)
Pin Descriptions
| Pin Name | Type | Description | Notes |
|---|---|---|---|
1 VCC | Power | Power supply input (3.3V to 6V) | Works with both 3.3V and 5V logic levels |
2 DATA | Communication | Digital signal output | Single-wire digital interface for data transmission |
3 NC | Control | Not connected | Leave this pin unconnected |
4 GND | Power | Ground connection | Connect to ESP32 ground |
Wiring DHT22 / AM2302 to ESP32
Connect the DHT22/AM2302 using the single-wire digital interface with a pull-up resistor for stable readings.
Visual Wiring Diagram

Connection Status
Protocol
Pin Connections
| DHT22 / AM2302 Pin | Connection | ESP32 Pin | Description |
|---|---|---|---|
1 VCC Required | 3.3V | Power supply (3.3V to 6V supported) | |
2 GND Required | GND | Ground connection | |
3 DATA Required | GPIO4 | Digital data line | |
4 DATA (Pull-up) Required | 5kΩ to VCC | Pull-up resistor for reliable communication |
Any GPIO pin works - GPIO4 is commonly used
5kΩ pull-up resistor recommended (10kΩ also works)
Use 3.3V for ESP32, sensor supports up to 6V
Minimum 2 second interval between readings
Better accuracy than DHT11 for demanding applications
DHT22 / AM2302 Troubleshooting
Common issues and solutions to help you get your sensor working
Common Issues
Issue: Receiving 'Failed to read from DHT sensor!' or NaN readings when attempting to retrieve data from the DHT22 (AM2302) sensor.
Possible causes include incorrect wiring, insufficient power supply, or improper sensor initialization.
Solution: Double-check the wiring connections: ensure VCC is connected to 3V to 6V, GND to ground, and the data pin to the appropriate GPIO pin on the microcontroller. Verify that a suitable pull-up resistor (typically 5kΩ) is connected between the data pin and VCC. Ensure the sensor is properly initialized in the code, and that the correct sensor type is specified in the library. Additionally, consider increasing the time between sensor readings, as the DHT22 has a sampling rate of once every 2 seconds.
Issue: The DHT22 sensor provides incorrect temperature readings when the ambient temperature falls below 0°C (32°F).
Possible causes include limitations in the sensor's design or firmware that affect accuracy at low temperatures.
Solution: Be aware that the DHT22 may have reduced accuracy at temperatures below freezing. For applications requiring precise measurements in sub-zero conditions, consider using a sensor specifically designed for low-temperature accuracy.
Issue: The DHT22 sensor ceases to provide valid readings after extended periods of operation, requiring a reset to resume functionality.
Possible causes include sensor lockup due to environmental factors or power supply instability.
Solution: Implement periodic sensor resets in your code to mitigate potential lockups. Ensure a stable power supply and consider adding decoupling capacitors to filter out noise. If the problem persists, evaluate the operating environment for factors that may adversely affect the sensor's performance.
Issue: Connecting the DHT22 sensor alongside other I2C devices causes communication issues or device malfunctions.
Possible causes include the DHT22's communication protocol conflicting with I2C devices.
Solution: The DHT22 uses a proprietary single-wire protocol and does not operate on the I2C bus. Ensure that the sensor is connected to a dedicated GPIO pin and that its communication does not interfere with I2C devices. If issues persist, consider isolating the sensor's data line from the I2C bus.
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
DHT22 / AM2302 Programming Examples
Ready-to-use code examples for different platforms and frameworks
#include "DHT.h"
#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println("DHT22 Sensor Example");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "dht.h"
#define DHT_PIN GPIO_NUM_4
void app_main() {
setDHTgpio(DHT_PIN);
while (1) {
printf("Reading DHT22 sensor...\n");
int ret = readDHT();
errorHandler(ret);
printf("Humidity: %.1f%%\n", getHumidity());
printf("Temperature: %.1f°C\n", getTemperature());
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}sensor:
- platform: dht
pin: GPIO4
model: DHT22
temperature:
name: "Living Room Temperature"
humidity:
name: "Living Room Humidity"
update_interval: 60splatformio.ini
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
adafruit/DHT sensor library @ ^1.4.2
monitor_speed = 115200main.cpp
#include <DHT.h>
#define DHTPIN 4
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println("DHT22 Sensor Example");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" % ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}from machine import Pin
from time import sleep
import dht
# Initialize the DHT22 sensor
sensor = dht.DHT22(Pin(4))
print('DHT22 Sensor Example')
while True:
sensor.measure()
temperature = sensor.temperature() # Temperature in Celsius
humidity = sensor.humidity() # Relative Humidity in %
print('Temperature: {} °C'.format(temperature))
print('Humidity: {} %'.format(humidity))
sleep(2)Wrapping Up DHT22 / AM2302
The ESP32 DHT22 / AM2302 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 DHT22 / AM2302 into your ESP32 project and bring your ideas to life!
Explore Alternative Sensors
Looking for alternatives to the DHT22 / AM2302? Check out these similar sensors that might fit your project needs.

SHT40 Temperature and Humidity Sensor
The SHT40 is a high-accuracy digital temperature and humidity sensor with a compact design and low power consumption. Its I²C interface and...

HTE501 Temperature and Humidity Sensor
The E+E HTE501 is a digital humidity and temperature sensor designed for high accuracy in demanding environments. Compactly housed in a DFN...

BMP180 Barometric Pressure Sensor
The BMP180 is a high-precision digital barometric pressure and temperature sensor, designed for applications such as weather monitoring,...





