β Back to Course
DHT22 vs DHT11 - Temperature and Humidity
π‘οΈ DHT22 vs DHT11 - Temperature and Humidity Sensors
π‘οΈ What You'll Learn:
- π Compare DHT22 and DHT11 specifications
- π° Decide which sensor fits your budget and accuracy needs
- π Wire either sensor correctly to ESP32/ESP8266/Pico
- πΎ Get crop recommendations based on temperature/humidity
π DHT22 vs DHT11 Comparison
| Feature | DHT22 | DHT11 |
|---|---|---|
| π° Price | $5-6 | $3-4 |
| π‘οΈ Temperature Range | -40 to 80Β°C | 0-50Β°C |
| π― Temperature Accuracy | Β±0.5Β°C | Β±2Β°C |
| π§ Humidity Range | 0-100% | 20-90% |
| π― Humidity Accuracy | Β±2% | Β±5% |
| β±οΈ Sampling Rate | 2 seconds (0.5Hz) | 1 second (1Hz) |
| π Size | Larger | Smaller |
| π Pins | 4 pins | 4 pins |
π Recommendation:
Spend the extra $2 on DHT22 - much better accuracy, wider temperature range, and more reliable for farm monitoring. DHT11 is fine for basic classroom projects.
π Wiring (Both sensors use same pins)
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
DHT22 / DHT11 WIRING
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
DHT22/DHT11 ESP32 / ESP8266 / Pico W
βββββββββββββββββββ βββββββββββββββββββββββββββ
β Pin 1 (VCC) β ββββββββββββΊ β 3.3V (or 5V for DHT11) β
β Pin 2 (DATA) β ββββββββββββΊ β GPIO16 β
β Pin 3 (NC) β ββββββββββββΊ β Not connected β
β Pin 4 (GND) β ββββββββββββΊ β GND β
βββββββββββββββββββ βββββββββββββββββββββββββββ
β οΈ CRITICAL: Add a 10kΞ© pull-up resistor between DATA and VCC!
βββββββ
β β
β 10kΞ©β
β β
ββββ¬βββ
β
3.3VβΌβββββββββββββββββ¬ββββββββββΊ DHT22 VCC
β β
βββββββββββββββββββΌββββββββββΊ DHT22 DATA (with pull-up)
β
GNDβββββββββββββββββ΄ββββββββββΊ DHT22 GND
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Complete Code (Works for Both Sensors)
#include "DHT.h"
// Change DHTTYPE to DHT11 if using that sensor
#define DHTPIN 16
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
Serial.println("π‘οΈ Weather Monitor Started");
delay(1000);
}
void loop() {
delay(2000); // DHT22 needs 2 seconds between readings!
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (isnan(temp) || isnan(hum)) {
Serial.println("β Sensor read failed! Check wiring.");
return;
}
float tempF = temp * 9.0 / 5.0 + 32.0;
Serial.println("ββββββββββββββββββββββββββββββββββ");
Serial.printf("π‘οΈ Temperature: %.1fΒ°C | %.1fΒ°F\n", temp, tempF);
Serial.printf("π§ Humidity: %.1f%%\n", hum);
// ========== CROP RECOMMENDATIONS ==========
Serial.println("\nπ CROP ADVICE:");
if (temp > 35) {
Serial.println(" π₯ TOO HOT! Increase irrigation, provide shade");
} else if (temp > 30) {
Serial.println(" βοΈ WARM - Monitor moisture levels");
} else if (temp < 10 && temp > 0) {
Serial.println(" βοΈ COOL - Delay planting warm-season crops");
} else if (temp < 0) {
Serial.println(" π¨ FROST WARNING! Protect crops immediately!");
} else {
Serial.println(" β
OPTIMAL - Good growing conditions");
}
if (hum > 85) {
Serial.println(" π§ HIGH HUMIDITY - Risk of mold/fungal disease");
Serial.println(" β Increase ventilation, reduce watering");
} else if (hum < 30) {
Serial.println(" π₯ LOW HUMIDITY - Plants stressed");
Serial.println(" β Misting or shade cloth recommended");
} else {
Serial.println(" β
OPTIMAL - Good humidity for most crops");
}
Serial.println("ββββββββββββββββββββββββββββββββββ\n");
}
π‘ Which Sensor Should You Choose?
- πΎ Farm use / Greenhouses: DHT22 - accuracy matters!
- π° Budget classroom project: DHT11 - cheaper, works fine
- βοΈ Cold climates (freezing): DHT22 only (DHT11 stops at 0Β°C)
- ποΈ Hot climates (above 50Β°C): DHT22 only
- π Research/Data logging: DHT22 for reliable data
β οΈ Common Issues:
- "Sensor read failed": Add delay(2000) between readings (DHT22)
- Constant 0% humidity: Missing pull-up resistor (10kΞ©)
- Temperature stuck at -40Β°C: Bad connection or missing pull-up
- DHT11 reads 0Β°C: Temperature below 0Β°C - use DHT22
π Key Takeaways:
- β DHT22: Better accuracy (Β±0.5Β°C), wider range (-40 to 80Β°C)
- β DHT11: Cheaper but less accurate (Β±2Β°C), limited range (0-50Β°C)
- β Both need 10kΞ© pull-up resistor between DATA and VCC
- β DHT22 needs 2 seconds between readings (important!)
- β For farm use, spend the extra $2 on DHT22
π‘ Key Takeaways:
- Apply these concepts directly to your farm or project.
- Take notes on important details for the quiz.
- Use the button below to track your progress.
×