DHT22 Digital Temperature & Humidity Sensor Module

DHT22 Digital Temperature & Humidity Sensor
High-Precision Environmental Sensing for Arduino Projects
Introduction
The DHT22 (AM2302) is a calibrated digital sensor that provides high-accuracy temperature and humidity measurements. With its single-wire serial interface, it’s perfect for weather stations, greenhouse monitoring, and HVAC systems.
DHT22 Digital Temperature & Humidity Sensor
Key Features
High Accuracy
±0.5°C temperature, ±2% humidity
Simple Interface
Single-wire digital communication
Long Range
Up to 20m signal transmission
Fast Updates
2-second sampling rate
Technical Specifications
Temperature Range | -40°C to 80°C |
---|---|
Humidity Range | 0-100% RH |
Operating Voltage | 3.3V – 5.5V DC |
Current Consumption | 1.5mA (measuring), 50μA (standby) |
Resolution | 0.1°C / 0.1% RH |
Dimensions | 27mm × 59mm × 13.5mm |
Pin Configuration
Pin | Function | Arduino Connection |
---|---|---|
1 | VCC (3.3V-5V) | 5V |
2 | DATA | Digital Pin (D2) |
3 | NC | Not Connected |
4 | GND | GND |
Note: Requires 4.7KΩ-10KΩ pull-up resistor between DATA and VCC
Wiring with Arduino
1 2 3 4 |
// Basic Connections: // VCC → 5V // DATA → D2 (with pull-up resistor) // GND → GND |
Important: Avoid long wires (>20cm) without proper shielding to prevent signal issues
Library Setup
- Install the DHT sensor library by Adafruit
- Include the required libraries:
12#include <DHT.h>#include <Adafruit_Sensor.h> - Initialize the sensor:
12345678#define DHTPIN 2 // Digital pin connected#define DHTTYPE DHT22 // DHT 22 (AM2302)DHT dht(DHTPIN, DHTTYPE);void setup() {dht.begin();}
Basic Sensor Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
#include <DHT.h> #define DHTPIN 2 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } void loop() { delay(2000); // Wait between measurements float h = dht.readHumidity(); float t = dht.readTemperature(); if (isnan(h) || isnan(t)) { Serial.println("Failed to read from DHT sensor!"); return; } Serial.print("Humidity: "); Serial.print(h); Serial.print("%\tTemperature: "); Serial.print(t); Serial.println("°C"); } |
Advanced Features
Heat Index Calculation
1 2 3 4 5 |
// Calculate heat index (feels-like temp) float hic = dht.computeHeatIndex(t, h, false); Serial.print("Heat index: "); Serial.print(hic); Serial.println("°C"); |
Fahrenheit Conversion
1 2 3 4 5 |
// Read temperature in Fahrenheit float f = dht.readTemperature(true); Serial.print("Temperature: "); Serial.print(f); Serial.println("°F"); |
Sensor Diagnostics
1 2 3 4 5 6 |
// Check sensor status if (dht.read() == DHTLIB_OK) { Serial.println("Sensor working properly"); } else { Serial.println("Sensor error detected"); } |
Power Saving
1 2 3 4 5 |
// Put sensor to sleep between readings digitalWrite(DHTPIN, LOW); delay(60000); // Sleep for 1 minute digitalWrite(DHTPIN, HIGH); delay(2000); // Allow sensor to stabilize |
Troubleshooting
No Readings (NaN values)
- Verify wiring connections
- Check pull-up resistor is installed
- Ensure proper power supply (3.3V-5V)
Incorrect Values
- Keep sensor away from heat sources
- Allow 2 seconds between readings
- Check for condensation on sensor
Communication Errors
- Shorten data wire length
- Try different digital pin
- Add 100nF capacitor between VCC and GND