Blog

DHT22 Digital Temperature & Humidity Sensor Module – Complete Guide

Temperature & Humidity Sensor

DHT22 Digital Temperature & Humidity Sensor Module

Precision Single-Wire Sensor for Climate Monitoring

The DHT22 (also sold as the AM2302) combines two separate sensing elements behind one chip: a capacitive humidity sensor, whose two electrodes sandwich a moisture-absorbing polymer film that changes electrical capacitance as it absorbs or releases water vapor from the air, and a standard NTC thermistor for temperature. Rather than exposing these raw analog readings, an onboard microcontroller inside the sensor itself digitizes, calibrates, and packages both values into a single 40-bit data frame sent out over one wire using precisely-timed pulses - each bit is encoded as a HIGH pulse whose duration (26-28µs for a ”0”, ~70µs for a ”1”) your microcontroller decodes in software. This onboard processing is exactly why the DHT22 needs no external ADC or manual calibration curve, and why - compared to the cheaper DHT11, which uses a lower-resolution, less linear version of the same idea - it delivers a wider measurement range and roughly 4x better humidity accuracy, making it the preferred choice for weather stations, greenhouses, and any project where the extra precision is worth the modest price difference.

-40°C to +80°C
Temperature Range
0-100% RH
Humidity Range
± 0.5°C / ± 2% RH
Accuracy

Key features

Higher Accuracy Than DHT11

Roughly 4x better humidity accuracy and a much wider usable temperature range than the entry-level DHT11.

Single-Wire Digital Output

Sends fully processed, calibrated readings - no analog-to-digital conversion or manual calibration needed.

Wide Operating Range

Rated from -40°C to +80°C, suitable for outdoor weather stations as well as indoor climate monitoring.

Built-In Signal Conditioning

Onboard chip handles amplification and calibration internally for consistent readings across units.

Low Power Consumption

Draws only tens of microamps in standby, making it practical for battery-powered weather stations.

2-Second Sampling Rate

Fast enough for most environmental monitoring while staying well within the sensor's rated read interval.

Technical specifications

Supply Voltage 3.3V – 6V DC
Operating Current 1 – 1.5 mA (measuring)
Standby Current 40 – 50 µA
Temperature Accuracy ± 0.5°C
Temperature Resolution 0.1°C
Humidity Accuracy ± 2% RH
Humidity Resolution 0.1% RH
Minimum Sampling Period 2 seconds
Package 4-pin (3-pin + cable on some modules)

Pinout

PinFunction
VCC 3.3V – 6V power supply
DATA Single-wire digital I/O - needs a 4.7k-10k pull-up resistor to VCC
NC Not connected (present on some 4-pin variants)
GND Ground

Applications

Weather stations and outdoor climate logging Greenhouse and grow-tent climate control HVAC and indoor air quality monitoring Home automation temperature triggers Incubators and terrariums Data logging projects

What's in the box

1x DHT22 (AM2302) sensor module
Onboard pull-up resistor on breakout-style modules

Downloads

Datasheet (PDF) Arduino Library (DHT sensor library)
🔌
Pin Connections
1 Table
Pin Connections Table 1
BoardSensor PinConnection
DHT22VCC/GND/DATA3.3-5V / GND / board data pin
📟
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module
7 Examples • C/C++ | Boards: Arduino Uno, Arduino Nano, Arduino Mega, ESP32, ESP8266, STM32, Raspberry Pi Pico
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - Arduino Uno
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - Arduino Nano
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - Arduino Mega
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - ESP32
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - ESP8266
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - STM32
DHT22 Digital Temperature & Humidity Sensor Module for Arduino DIY Projects Black module - Raspberry Pi Pico
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_arduino_uno.inoArduino Uno
667 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin 2 on Arduino Uno
6#include <DHT.h>
7
8#define DHT_PIN 2
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_arduino_nano.inoArduino Nano
668 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin 2 on Arduino Nano
6#include <DHT.h>
7
8#define DHT_PIN 2
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_arduino_mega.inoArduino Mega
668 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin 2 on Arduino Mega
6#include <DHT.h>
7
8#define DHT_PIN 2
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_esp32.inoESP32
661 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin 4 on ESP32
6#include <DHT.h>
7
8#define DHT_PIN 4
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_esp8266.inoESP8266
665 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin D4 on ESP8266
6#include <DHT.h>
7
8#define DHT_PIN D4
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_stm32.inoSTM32
665 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin PB4 on STM32
6#include <DHT.h>
7
8#define DHT_PIN PB4
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
📄 File: dht22_digital_temperature_&_humidity_sensor_module_for_arduino_diy_projects_black_module_-_raspberry_pi_pico.inoRaspberry Pi Pico
673 characters
1//ekostra.com
2//electronics store in egypt
3//+201008896258
4
5// Data pin 2 on Raspberry Pi Pico
6#include <DHT.h>
7
8#define DHT_PIN 2
9#define DHT_TYPE DHT22
10
11DHT dht(DHT_PIN, DHT_TYPE);
12
13void setup() {
14 Serial.begin(115200);
15 dht.begin();
16}
17
18void loop() {
19 float humidity = dht.readHumidity();
20 float tempC = dht.readTemperature();
21
22 if (isnan(humidity) || isnan(tempC)) {
23 Serial.println("Failed to read from DHT sensor!");
24 } else {
25 Serial.print("Temp: "); Serial.print(tempC); Serial.print(" C ");
26 Serial.print("Humidity: "); Serial.print(humidity); Serial.println(" %");
27 }
28
29 delay(2000); // DHT sensors are slow - don't read faster than every ~2s
30}
Higher-precision digital temp/humidity sensor than DHT11.
Do not read the sensor faster than once every 2 seconds - reading too quickly is the most common cause of failed/NaN readings in beginner projects, since the sensor is still finishing its previous conversion cycle. Keep the data wire reasonably short, or use a stronger pull-up resistor (down to around 4.7k) for cable runs longer than a couple of meters, since a weak pull-up combined with wire capacitance can round off the sharp pulse edges the timing-based protocol depends on. Mount the sensor away from any heat-generating components on your board (regulators, the microcontroller itself) - a surprisingly common source of a several-degree offset in beginner projects is simply the sensor reading the warm air rising off the board it is mounted on rather than true ambient temperature.