Introduction
The DHT22 is a reliable sensor for measuring temperature and humidity. It is a digital sensor that provides high accuracy and long-term stability. The DHT22 is widely used in weather stations, home automation systems, and environmental monitoring due to its ease of use and affordability.
Technical Specifications
Key Technical Details
- Voltage: 3.3 to 6V DC
- Current: 2.5mA max current use during conversion (while requesting data)
- Humidity Range: 0-100% with 2-5% accuracy
- Temperature Range: -40 to 80°C with ±0.5°C accuracy
- Resolution: Humidity 0.1% RH, Temperature 0.1°C
- Sampling Rate: No more than 0.5 Hz (once every 2 seconds)
Pin Configuration and Descriptions
Usage Instructions
Integration with a Circuit
- Connect the VDD pin to a 3.3V or 5V power supply.
- Connect the GND pin to the ground of the power supply.
- Connect the DATA pin to a digital input pin on a microcontroller, such as an Arduino.
- A pull-up resistor (typically 10kΩ) is required between the DATA pin and VDD.
Best Practices
- Avoid placing the sensor in direct sunlight or near heat sources to prevent inaccurate readings.
- Ensure the sensor is not exposed to condensation or water.
- Allow the sensor to acclimatize to the environment for accurate readings.
- Use a decoupling capacitor (e.g., 100nF) between VDD and GND close to the sensor to filter out power supply noise.
Example Code for Arduino UNO
#include "DHT.h"
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Celsius (isFahrenheit = false)
float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature: ");
Serial.print(temperature);
Serial.print("°C Heat index: ");
Serial.print(heatIndex);
Serial.println("°C");
}
Troubleshooting and FAQs
Common Issues
- Sensor not responding: Ensure the wiring is correct and the pull-up resistor is in place.
- Inaccurate readings: Make sure the sensor is not exposed to direct sunlight or heat sources.
- Fluctuating data: Check for loose connections and ensure the power supply is stable.
FAQs
Q: How long does the DHT22 need to warm up?
A: The DHT22 typically requires one to two seconds to warm up after power-on.
Q: Can I use a longer cable to connect the DHT22 to a microcontroller?
A: Yes, but keep the cable length under 20 meters to prevent signal degradation.
Q: How often can I request data from the DHT22?
A: You should wait at least 2 seconds between data requests to avoid self-heating and ensure accurate measurements.
Q: Is the DHT22 waterproof?
A: No, the DHT22 is not waterproof. Protect it from condensation and water exposure.
For further assistance, consult the datasheet or contact technical support.