OC
OceanRemote
Low-code IoT platform
← Back to Course

DHT22 vs DHT11 - Temperature and Humidity

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

FeatureDHT22DHT11
💰 Price$5-6$3-4
🌡️ Temperature Range-40 to 80°C0-50°C
🎯 Temperature Accuracy±0.5°C±2°C
💧 Humidity Range0-100%20-90%
🎯 Humidity Accuracy±2%±5%
⏱️ Sampling Rate2 seconds (0.5Hz)1 second (1Hz)
📏 SizeLargerSmaller
🔌 Pins4 pins4 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.