If you’re working on a DIY project that needs reliable temperature and humidity monitoring, pairing a DHT22 with Arduino is a solid choice. We’ve used this combo in several home automation setups and weather station builds, and it’s always proven accurate, responsive, and easy to set up.
In this guide, we’ll show you how to use the DHT22 sensor with an Arduino step by step. You’ll learn how the sensor works, how to connect it, install the necessary library, and write the code to start collecting live environmental data. Whether you’re building a simple indoor climate tracker or a more advanced IoT system, this guide will help you get started the right way.
What is the DHT22 Sensor?
The DHT22, also known as the AM2302, is a popular digital sensor used for measuring both temperature and relative humidity. It’s the upgraded version of the DHT11 sensor and is known for its higher accuracy, wider measurement range, and greater reliability.
Internally, the DHT22 uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and it outputs a calibrated digital signal via a single data pin. This makes it perfect for interfacing with microcontrollers like Arduino — and that’s why DHT22 with Arduino is a go-to choice for many electronics projects that require environmental sensing.
The sensor is compact, energy-efficient, and very easy to use in Arduino-based projects. Its improved performance compared to the DHT11 makes DHT22 with Arduino an excellent solution for projects that require more precise and stable environmental data — like indoor climate control systems, smart greenhouses, or long-term data logging applications.
DHT11 vs. DHT22: Key Differences

Here’s how DHT11 compares with DHT22:
Feature | DHT11 | DHT22 |
---|---|---|
Temperature Range | 0-50 °C | -40 to 80 °C |
Temperature Accuracy | ±2 °C | ±0.5 °C |
Humidity Range | 20-90% RH | 0-100% RH |
Humidity Accuracy | ±5% RH | ±2-5% RH |
Sampling Rate | 1 Hz (1 second) | 0.5 Hz (2 seconds) |
Cost | Cheaper | Slightly more expensive |
If you want better precision and a wider operating range, DHT22 with Arduino is the preferred choice over DHT11.
Required Components
To build this, you’ll need the following components:
- Arduino Uno (or compatible board)
- DHT22 sensor module
- Breadboard and jumper wires
- (Optional) 10kΩ pull-up resistor
DHT22 Pinout
DHT22 sensors usually have 3 or 4 pins depending on the module:
Pin | Description |
---|---|
VCC | Power supply (3.3V–5V) |
GND | Ground |
DATA | Digital output signal |

When using DHT22 with Arduino, the DATA pin can be connected to any digital pin. In this example, we’ll use digital pin 2.
Circuit Diagram: DHT22 with Arduino
Here’s how to connect the DHT22 sensor to Arduino:
DHT22 Pin | Arduino Pin |
---|---|
VCC | 5V |
GND | GND |
DATA | Digital Pin 2 |

To improve stability, it’s recommended to place a 10kΩ pull-up resistor between VCC and DATA.
Installing the DHT Library
Before using the DHT22 sensor, you need to install the DHT library in the Arduino IDE:
- Open the Arduino IDE and go to Sketch > Include Library > Manage Libraries…
- In the Library Manager, search for DHT Sensor Library by Adafruit.
- Click Install and wait for the installation to complete.
For more details or manual installation, you can visit the Adafruit DHT Sensor Library GitHub repository.
Arduino Code for DHT22
Here’s a simple code example to read data from DHT22 with Arduino:
// Interfacing DHT22 Sensor with Arduino by ArduinoYard
#include "DHT.h"
#define DHTPIN 2 // DHT22 data pin connected to digital pin 2
#define DHTTYPE DHT22 // Define sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("Reading from DHT22 sensor...");
}
void loop() {
float temperature = dht.readTemperature(); // Celsius
float humidity = dht.readHumidity(); // Percent
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Failed to read from DHT22 sensor!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
delay(2000); // Wait 2 seconds between readings
}
Code Breakdown
- Sensor Initialization: We define
DHTTYPE
asDHT22
. - Pin Assignment: DATA is connected to digital pin 2.
- Sensor Readings: We fetch temperature and humidity with simple function calls.
- Error Handling:
isnan()
checks ensure valid readings are displayed.
With this structure, you can easily build projects using DHT22 with Arduino that are scalable and reliable.
Output Example
Hardware:

Serial Monitor:

The values are updated every 2 seconds, which matches the sampling rate of the DHT22.
Troubleshooting: DHT22 with Arduino
Problem: “Failed to read from DHT22 sensor!”
- Double-check the wiring and power supply.
- Ensure the correct sensor type is set in the code (
DHT22
). - Add a 10kΩ resistor between VCC and DATA if needed.
Problem: No or random data
- Avoid using very long jumper wires.
- Make sure the sensor is not exposed to extreme moisture or damage.
Applications of DHT22 with Arduino
- Smart Home Projects: Control fans, AC, or humidifiers based on sensor readings.
- Weather Monitoring Stations: Gather accurate climate data over time.
- Data Logging: Store temperature and humidity logs for analysis.
- Greenhouse Systems: Automate ventilation based on precise air conditions.
DHT22 Sensor is ideal when you need high-resolution temperature and humidity readings for real-world applications.
Conclusion
The DHT22 sensor is a great upgrade over the DHT11 when you need more accurate and reliable environmental monitoring. It’s easy to integrate with Arduino and works well in a wide range of DIY and professional applications. Whether you’re building a weather station, automating a greenhouse, or adding climate sensing to a smart home project, the DHT22 offers the precision and stability you need to get consistent results.