The DHT22, also known as the AM2302, is a digital sensor designed to measure both humidity and temperature. It offers high accuracy and a wide measurement range, making it suitable for a variety of applications. The sensor communicates using a single-wire digital interface, simplifying its integration into microcontroller-based systems.
The DHT22 sensor is designed for precision and reliability. Below are its key technical details:
Parameter | Value |
---|---|
Humidity Range | 0% to 100% RH |
Humidity Accuracy | ±2% RH (typical) |
Temperature Range | -40°C to +80°C |
Temperature Accuracy | ±0.5°C |
Operating Voltage | 3.3V to 6V |
Max Current Consumption | 2.5mA during measurement |
Communication Protocol | Single-wire digital interface |
Sampling Period | Minimum 2 seconds between reads |
Dimensions | 15.1mm x 25mm x 7.7mm |
The DHT22 sensor has four pins, but only three are typically used in most applications. Below is the pinout:
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 6V) |
2 | DATA | Digital data output (connect to microcontroller) |
3 | NC (Not Connected) | No connection (leave unconnected) |
4 | GND | Ground (0V reference) |
Below is an example of how to use the DHT22 sensor with an Arduino UNO. This code uses the popular DHT
library.
#include "DHT.h"
// Define the DHT sensor type and pin
#define DHTTYPE DHT22 // DHT22 (AM2302) sensor type
#define DHTPIN 2 // Pin connected to the DATA pin of the sensor
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Start serial communication
Serial.println("DHT22 Sensor Initialization");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait at least 2 seconds between readings
// Read temperature and humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if the readings are valid
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}
No Data or Incorrect Readings
Frequent Communication Errors
Sensor Not Responding
Inconsistent Readings
Q: Can I use the DHT22 with a 3.3V microcontroller?
A: Yes, the DHT22 operates within a voltage range of 3.3V to 6V, making it compatible with 3.3V systems.
Q: What is the maximum cable length for the DHT22?
A: The recommended maximum cable length is about 20 meters, but this depends on the pull-up resistor value and environmental noise.
Q: How often can I read data from the DHT22?
A: The DHT22 requires a minimum of 2 seconds between consecutive readings to ensure accurate data.
Q: Is the DHT22 waterproof?
A: No, the DHT22 is not waterproof. For outdoor or wet environments, consider using a waterproof enclosure.