- تكلفه فاتورة الكهرباء
- Electrical Energy Consumption
- Parallel and Series Resistor Calculator
- LED Resistor Calculator
- UPS Battery Backup Calculator
- Voltage Divider Calculator
- Resistor Color Code Calculator
- Ohm’s Law Calculator
- Current Divider Calculator
- Number System Conversion Calculator
- Boost Converter Calculator
- MOSFET Threshold Voltage Calculator
- Apparent Power Calculator (kVA & VA)
- 555 Timer Calculator
- Buck Converter Calculator
- Capacitors in Series or Parallel Calculator
- Low Pass Filter Calculator
- RMS Voltage Calculator
- Universal Data Converter
- RMS Voltage Calculator
- Capacitor Code Converter
- Series Inductors Calculator
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
// 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:
#include <DHT.h> #include <Adafruit_Sensor.h>
- Initialize the sensor:
#define DHTPIN 2 // Digital pin connected #define DHTTYPE DHT22 // DHT 22 (AM2302) DHT dht(DHTPIN, DHTTYPE); void setup() { dht.begin(); }
Basic Sensor Example
#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
// 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
// Read temperature in Fahrenheit
float f = dht.readTemperature(true);
Serial.print("Temperature: ");
Serial.print(f);
Serial.println("°F");
Sensor Diagnostics
// Check sensor status
if (dht.read() == DHTLIB_OK) {
Serial.println("Sensor working properly");
} else {
Serial.println("Sensor error detected");
}
Power Saving
// 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