ESP32 DHT21 / AM2301A Temperature and Humidity Sensor

DHT21 / AM2301A Temperature and Humidity Sensor image

DHT21 / AM2301A

Protocol: Analog

Overview

The DHT21 is a reliable sensor for measuring temperature and humidity, offering calibrated digital output and ease of integration with microcontrollers. With a temperature measurement range of -40°C to 80°C and a humidity range of 0% to 100%, the DHT21 is suitable for various applications, including environmental monitoring and HVAC systems.

About DHT21 / AM2301A Temperature and Humidity Sensor

The DHT21, also known as AM2301, is a digital temperature and humidity sensor that provides accurate environmental measurements. It uses a capacitive humidity sensor and a thermistor to ensure reliable data collection.

Key Features

  • High Accuracy – Delivers precise temperature and humidity readings.
  • Single-Wire Digital Communication – Easy integration with ESP32, Arduino, and other microcontrollers.
  • Capacitive Humidity Sensing – Provides stable and long-term performance.
  • Similar to DHT22 – Slight differences in casing and specifications.

With its ease of use and reliable performance, the DHT21 is ideal for climate monitoring, smart home systems, and industrial automation. 🚀

Where to Buy

DHT21 / AM2301A Temperature and Humidity Sensor

Starting from

$5 per unit

Amazon com
Amazon.com Ships worldwide
View Price
Amazon de
Amazon.de Ships to EU
View Price
Aliexpress
AliExpress Best value
View Price

Prices are subject to change. We earn from qualifying purchases as an Amazon Associate.

Technical Specifications

Operating Voltage 3.3V to 5.5V
Temperature Range -40°C to 80°C
Humidity Range 0% to 100% RH
Temperature Accuracy ±0.5°C
Humidity Accuracy ±3% RH
Sampling Rate 0.5 Hz (once every 2 seconds)
Dimensions 59mm x 27mm x 13.5mm

Pinout Configuration

The VCC pin is used to supply power to the sensor, and it typically requires 3.3V or 5V (refer to the datasheet for specific voltage requirements). The GND pin is the ground connection and must be connected to the ground of your ESP32.

The DHT21 pinout is as follows:

  • Pin 1 (VCC): Connect to a 3.3V or 5V power supply.
  • Pin 2 (DATA): Outputs digital signal; connect to a digital input on your microcontroller.
  • Pin 3 (NC): Not connected; leave unconnected.
  • Pin 4 (GND): Connect to the ground of the microcontroller.

Wiring with ESP32

To interface the DHT21 with an ESP32:
  • Connect Pin 1 (VCC) to the 3.3V or 5V pin on the ESP32.
  • Connect Pin 4 (GND) to the ground (GND) of the ESP32.
  • Connect Pin 2 (DATA) to a digital GPIO pin on the ESP32 (e.g., GPIO 4).
  • Place a 10kΩ pull-up resistor between the DATA pin and VCC to ensure reliable communication.

Troubleshooting Guide

Common Issues

⚠️ Incorrect Temperature Readings

💧 Humidity Reading Stuck at 99.9%

❓ Receiving NaN (Not a Number) Values

💻 Compilation Errors with DHT Library

Debugging Tips

🔍 Serial Monitor

⚡ Voltage Checks

Code Examples

Arduino Example

C++
🔧

ESP-IDF Example

C++
🏠

ESPHome Example

YAML
🛠️

PlatformIO Example

C++
🐍

MicroPython Example

Python

Conclusion

The ESP32 DHT21 / AM2301A 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.

For optimal performance, ensure proper wiring and follow the recommended configuration for your chosen development platform.

Always verify power supply requirements and pin connections before powering up your project to avoid potential damage.