If you’re looking to build reliable temperature and humidity monitoring projects, DHT22 with Arduino is one of the best choices you can make. Whether you’re a hobbyist working on a home automation system or a student developing a weather station, the DHT22 sensor paired with Arduino offers high accuracy, digital output, and ease of integration — all at an affordable cost.
In this guide, you’ll learn how to use the DHT22 sensor with Arduino to read real-time environmental data. We’ll walk through everything: how the sensor works, how to wire it up, how to install the required library, and how to write and upload the code to your Arduino board. By the end of this tutorial, you’ll be able to reliably collect and display temperature and humidity readings using DHT22 and Arduino .
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
Using DHT22 opens up possibilities for building more accurate and responsive projects compared to DHT11. It’s easy to use, reliable, and perfect for hobbyists and professionals looking to measure environmental conditions. Whether you’re designing a weather station, greenhouse automation, or a smart home sensor, DHT22 with Arduino is a smart and scalable solution.