- All products
- Sensors & Modules
- Temp + Humidity
- DHT22 Temperature Humidity Sensor
- Temp + Humidity
Principle of Operation
The DHT22 uses two sensing elements to measure environmental conditions:

- Humidity measurement: A capacitive sensing element absorbs and releases moisture as the surrounding relative humidity changes. This changes its capacitance, which the internal controller measures and converts into a digital humidity value.
- Temperature measurement: An NTC thermistor changes resistance according to temperature. The sensor's internal electronics measure this change and convert it into a digital temperature value.
The internal controller processes both measurements and transmits them to the microcontroller through one data line. Communication is initiated by the microcontroller, which sends a start signal. The sensor then responds with a 40-bit data frame containing:
- 8 bits: Humidity integer value
- 8 bits: Humidity decimal value
- 8 bits: Temperature integer value
- 8 bits: Temperature decimal value
- 8 bits: Checksum for data validation
The DHT22 uses its own timing-based communication protocol. It does not use I2C, SPI, RS-232, or the Dallas 1-Wire protocol. Allow at least 2 seconds between readings.
Pinout

| Pin | Name | Description |
| 1 | VCC | Power supply, typically 3.3V to 5.5V. |
| 2 | DATA | Digital data communication for temperature and humidity readings. |
| 3 | NC | No connection. Leave this pin unconnected. |
| 4 | GND | Ground connection. |
Note: The pin sequence applies to the standalone four-pin sensor shown. Check the sensor orientation and pin labels before wiring. Reversing VCC and GND can damage the sensor.
Wiring and Connection
Connect the four-pin DHT22 sensor to an Arduino Uno as follows:

| DHT22 Pin | Arduino Uno |
| Pin 1 - VCC | 5V |
| Pin 2 - DATA | Digital pin 2 |
| Pin 3 - NC | Not connected |
| Pin 4 - GND | GND |
For a standalone four-pin sensor, connect a 4.7kΩ to 10kΩ pull-up resistor between VCC and DATA. Some breakout modules already include this resistor, so an additional one may not be necessary.
When connecting the sensor to a 3.3V microcontroller such as an ESP32 or ESP8266, ensure that the DATA line is pulled up to 3.3V rather than 5V. Connect the DATA pin to a digital GPIO, not an analog input for analog measurement.
Library
The SimpleDHT library provides functions for reading temperature and humidity from the DHT22 using Arduino IDE.

- Download the SimpleDHT library from GitHub.
- Open the Arduino IDE.
- Select Sketch → Include Library → Add .ZIP Library.
- Locate and select the downloaded ZIP file.
- Wait for the Arduino IDE to complete the installation.
After installation, include SimpleDHT.h in your Arduino sketch.
Code
This example reads temperature and humidity from the DHT22 and displays the results in the Serial Monitor. It uses digital pin 2 for the DATA connection and waits 2 seconds between readings.
#include "SimpleDHT.h"
// DHT22 DATA pin connected to Arduino digital pin 2
int pinDHT22 = 2;
SimpleDHT22 dht22(pinDHT22);
void setup() {
Serial.begin(115200);
Serial.println("DHT22 Temperature and Humidity Sensor");
}
void loop() {
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
// Read temperature and humidity
err = dht22.read2(&temperature, &humidity, NULL);
if (err != SimpleDHTErrSuccess) {
Serial.print("DHT22 read failed, error = ");
Serial.println(err);
delay(2000);
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" % RH");
// Wait before the next reading
delay(2000);
}
Upload the sketch to the Arduino and open the Serial Monitor at 115200 baud to view the readings.
Applications
- Weather stations: Collecting local temperature and humidity measurements.
- Indoor climate control: Monitoring environmental conditions for ventilation and air conditioning systems.
- Greenhouses: Monitoring temperature and humidity to help maintain suitable growing conditions.
- Food storage: Monitoring environmental conditions in refrigerators and storage areas.
- Data centers: Monitoring room temperature and humidity around electronic equipment.
- Museums and archives: Monitoring environmental conditions in areas where documents and artifacts are stored.
- Agriculture: Collecting environmental data for crop and greenhouse monitoring.
- Home automation: Triggering fans, ventilation systems, or humidifiers based on sensor readings.
- Drying systems: Monitoring humidity during drying and dehumidification processes.
- Terrariums and incubators: Monitoring environmental conditions in controlled enclosures.
- Laboratory projects: Collecting temperature and humidity data for experiments and monitoring.
- IoT applications: Sending environmental readings from ESP8266, ESP32, and other connected microcontroller systems.
Specifications
| Sensor model | DHT22 / AM2302 |
| Sensor type | Digital temperature and humidity sensor |
| Humidity sensing element | Capacitive |
| Temperature sensing element | NTC thermistor |
| Operating voltage | 3.3V to 5.5V |
| Temperature range | -40°C to 80°C |
| Temperature resolution | 0.1°C |
| Temperature accuracy | Typically ±0.5°C |
| Humidity range | 0% to 100% RH |
| Humidity resolution | 0.1% RH |
| Humidity accuracy | Typically ±2% RH |
| Output interface | Single-bus digital communication |
| Sampling interval | At least 2 seconds |
| Sensor connections | VCC, DATA, NC, GND |
Comparison: DHT22, DHT11, and LM35

The DHT22 and DHT11 measure both temperature and humidity, while the LM35 measures temperature only. The DHT22 offers a wider operating range and finer resolution than the DHT11. The LM35 provides an analog temperature output and can be sampled more frequently because it does not use the DHT communication protocol.
| Specification | DHT22 | DHT11 | LM35 |
| Measured parameters | Temperature and humidity | Temperature and humidity | Temperature only |
| Temperature range | -40°C to 80°C | 0°C to 50°C | -55°C to 150°C (device-dependent operating conditions) |
| Temperature resolution | 0.1°C | 1°C | Analog output; resolution depends on the ADC |
| Typical temperature accuracy | ±0.5°C | ±2°C | Typically ±0.5°C at 25°C for common LM35 versions |
| Humidity range | 0% to 100% RH | 20% to 90% RH | Not supported |
| Humidity resolution | 0.1% RH | 1% RH | Not supported |
| Output type | Digital | Digital | Analog voltage |
| Sampling interval | At least 2 seconds | At least 1 second | Depends on the measurement system |
Selection guide: Choose the DHT22 when both temperature and humidity measurements are required over a wider range. The DHT11 is suitable for basic, lower-cost monitoring. Choose the LM35 when temperature measurement alone is required and an analog output is preferred.
Resources
Principle of Operation
The DHT22 uses two sensing elements to measure environmental conditions:

- Humidity measurement: A capacitive sensing element absorbs and releases moisture as the surrounding relative humidity changes. This changes its capacitance, which the internal controller measures and converts into a digital humidity value.
- Temperature measurement: An NTC thermistor changes resistance according to temperature. The sensor's internal electronics measure this change and convert it into a digital temperature value.
The internal controller processes both measurements and transmits them to the microcontroller through one data line. Communication is initiated by the microcontroller, which sends a start signal. The sensor then responds with a 40-bit data frame containing:
- 8 bits: Humidity integer value
- 8 bits: Humidity decimal value
- 8 bits: Temperature integer value
- 8 bits: Temperature decimal value
- 8 bits: Checksum for data validation
The DHT22 uses its own timing-based communication protocol. It does not use I2C, SPI, RS-232, or the Dallas 1-Wire protocol. Allow at least 2 seconds between readings.
Pinout

| Pin | Name | Description |
| 1 | VCC | Power supply, typically 3.3V to 5.5V. |
| 2 | DATA | Digital data communication for temperature and humidity readings. |
| 3 | NC | No connection. Leave this pin unconnected. |
| 4 | GND | Ground connection. |
Note: The pin sequence applies to the standalone four-pin sensor shown. Check the sensor orientation and pin labels before wiring. Reversing VCC and GND can damage the sensor.
Wiring and Connection
Connect the four-pin DHT22 sensor to an Arduino Uno as follows:

| DHT22 Pin | Arduino Uno |
| Pin 1 - VCC | 5V |
| Pin 2 - DATA | Digital pin 2 |
| Pin 3 - NC | Not connected |
| Pin 4 - GND | GND |
For a standalone four-pin sensor, connect a 4.7kΩ to 10kΩ pull-up resistor between VCC and DATA. Some breakout modules already include this resistor, so an additional one may not be necessary.
When connecting the sensor to a 3.3V microcontroller such as an ESP32 or ESP8266, ensure that the DATA line is pulled up to 3.3V rather than 5V. Connect the DATA pin to a digital GPIO, not an analog input for analog measurement.
Library
The SimpleDHT library provides functions for reading temperature and humidity from the DHT22 using Arduino IDE.

- Download the SimpleDHT library from GitHub.
- Open the Arduino IDE.
- Select Sketch → Include Library → Add .ZIP Library.
- Locate and select the downloaded ZIP file.
- Wait for the Arduino IDE to complete the installation.
After installation, include SimpleDHT.h in your Arduino sketch.
Code
This example reads temperature and humidity from the DHT22 and displays the results in the Serial Monitor. It uses digital pin 2 for the DATA connection and waits 2 seconds between readings.
#include "SimpleDHT.h"
// DHT22 DATA pin connected to Arduino digital pin 2
int pinDHT22 = 2;
SimpleDHT22 dht22(pinDHT22);
void setup() {
Serial.begin(115200);
Serial.println("DHT22 Temperature and Humidity Sensor");
}
void loop() {
float temperature = 0;
float humidity = 0;
int err = SimpleDHTErrSuccess;
// Read temperature and humidity
err = dht22.read2(&temperature, &humidity, NULL);
if (err != SimpleDHTErrSuccess) {
Serial.print("DHT22 read failed, error = ");
Serial.println(err);
delay(2000);
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" % RH");
// Wait before the next reading
delay(2000);
}Upload the sketch to the Arduino and open the Serial Monitor at 115200 baud to view the readings.
Applications
- Weather stations: Collecting local temperature and humidity measurements.
- Indoor climate control: Monitoring environmental conditions for ventilation and air conditioning systems.
- Greenhouses: Monitoring temperature and humidity to help maintain suitable growing conditions.
- Food storage: Monitoring environmental conditions in refrigerators and storage areas.
- Data centers: Monitoring room temperature and humidity around electronic equipment.
- Museums and archives: Monitoring environmental conditions in areas where documents and artifacts are stored.
- Agriculture: Collecting environmental data for crop and greenhouse monitoring.
- Home automation: Triggering fans, ventilation systems, or humidifiers based on sensor readings.
- Drying systems: Monitoring humidity during drying and dehumidification processes.
- Terrariums and incubators: Monitoring environmental conditions in controlled enclosures.
- Laboratory projects: Collecting temperature and humidity data for experiments and monitoring.
- IoT applications: Sending environmental readings from ESP8266, ESP32, and other connected microcontroller systems.
Specifications
| Sensor model | DHT22 / AM2302 |
| Sensor type | Digital temperature and humidity sensor |
| Humidity sensing element | Capacitive |
| Temperature sensing element | NTC thermistor |
| Operating voltage | 3.3V to 5.5V |
| Temperature range | -40°C to 80°C |
| Temperature resolution | 0.1°C |
| Temperature accuracy | Typically ±0.5°C |
| Humidity range | 0% to 100% RH |
| Humidity resolution | 0.1% RH |
| Humidity accuracy | Typically ±2% RH |
| Output interface | Single-bus digital communication |
| Sampling interval | At least 2 seconds |
| Sensor connections | VCC, DATA, NC, GND |
Comparison: DHT22, DHT11, and LM35

The DHT22 and DHT11 measure both temperature and humidity, while the LM35 measures temperature only. The DHT22 offers a wider operating range and finer resolution than the DHT11. The LM35 provides an analog temperature output and can be sampled more frequently because it does not use the DHT communication protocol.
| Specification | DHT22 | DHT11 | LM35 |
| Measured parameters | Temperature and humidity | Temperature and humidity | Temperature only |
| Temperature range | -40°C to 80°C | 0°C to 50°C | -55°C to 150°C (device-dependent operating conditions) |
| Temperature resolution | 0.1°C | 1°C | Analog output; resolution depends on the ADC |
| Typical temperature accuracy | ±0.5°C | ±2°C | Typically ±0.5°C at 25°C for common LM35 versions |
| Humidity range | 0% to 100% RH | 20% to 90% RH | Not supported |
| Humidity resolution | 0.1% RH | 1% RH | Not supported |
| Output type | Digital | Digital | Analog voltage |
| Sampling interval | At least 2 seconds | At least 1 second | Depends on the measurement system |
Selection guide: Choose the DHT22 when both temperature and humidity measurements are required over a wider range. The DHT11 is suitable for basic, lower-cost monitoring. Choose the LM35 when temperature measurement alone is required and an analog output is preferred.

