DHT11: Temperature and Humidity Sensor Explained

The DHT11 is a low-cost digital temperature and humidity sensor that is widely used in weather monitoring, home automation, and IoT applications. It provides real-time temperature and humidity readings using a simple one-wire communication protocol, making it easy to interface with microcontrollers like Arduino, ESP32, Raspberry Pi, and STM32.


πŸ”Ή 1. What is the DHT11?

  • DHT11 is a digital temperature and humidity sensor with a built-in capacitive humidity sensing element and a thermistor for measuring temperature.
  • Uses a single digital data pin for communication, making it easy to integrate into microcontroller-based projects.
  • Operating voltage: 3.3V – 5V, making it compatible with Arduino, ESP32, and Raspberry Pi.

πŸ“Œ Key Features:

  • Temperature Range: 0Β°C to 50Β°C (Β±2Β°C accuracy). More about Accuracy->
  • Humidity Range: 20% to 90% RH (Β±5% accuracy). More about Accuracy->
  • Supply Voltage: 3.3V – 5V.
  • Sampling Rate: 1 reading per second (1Hz).
  • Communication Protocol: Single-wire digital signal.
  • Low power consumption.

πŸ“Œ Common Applications:

  • Weather monitoring stations.
  • Home automation and smart homes.
  • Greenhouse and indoor climate monitoring.
  • IoT-based environmental monitoring.
  • Industrial humidity control systems.

πŸ”Ή 2. DHT11 Pinout & Functions

The DHT11 sensor comes in two forms:

  1. Standalone DHT11 sensor (4 pins)
  2. DHT11 module (3 pins with built-in pull-up resistor).
Pin No.NameFunction
1VCCPower Supply (3.3V – 5V)
2Data (OUT)Digital Data Output (One-wire communication)
3NC (Not Connected)Unused (leave unconnected)
4GNDGround (0V)

πŸ“Œ Note:

  • If using a standalone DHT11, connect a 4.7kΞ© – 10kΞ© pull-up resistor between the Data pin and VCC.
  • DHT11 modules already include a pull-up resistor, so no additional resistor is needed.

πŸ”Ή 3. Wiring the DHT11 with an Arduino

πŸ›  Required Components

  • 1x Arduino (Uno, Nano, Mega, ESP32, etc.)
  • 1x DHT11 Sensor
  • 1x 10kΞ© Resistor (if using the 4-pin version)
  • Jumper Wires

πŸ›  Wiring:

DHT11 PinArduino Pin
VCC (Pin 1)5V (or 3.3V for ESP32/Raspberry Pi)
Data (Pin 2)Digital Pin (e.g., D2 on Arduino)
GND (Pin 4)GND

πŸ“Œ For standalone DHT11: Connect a 10kΞ© pull-up resistor between Data and VCC.


πŸ”Ή 4. Arduino Code to Read DHT11 Sensor

We use the DHT library to easily communicate with the sensor.

πŸ›  Install the DHT Library

  1. Open Arduino IDE.
  2. Go to Sketch β†’ Include Library β†’ Manage Libraries.
  3. Search for “DHT sensor library by Adafruit” and install it.

βœ… Arduino Code for DHT11

#include <DHT.h>

#define DHTPIN 2        // DHT11 connected to digital pin 2
#define DHTTYPE DHT11   // Define sensor type

DHT dht(DHTPIN, DHTTYPE);

void setup() {
    Serial.begin(9600);
    dht.begin();
}

void loop() {
    float temperature = dht.readTemperature();  // Read temperature (Celsius)
    float humidity = dht.readHumidity();       // Read humidity

    if (isnan(temperature) || isnan(humidity)) {
        Serial.println("Failed to read from DHT11 sensor!");
        return;
    }

    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" Β°C");

    Serial.print("Humidity: ");
    Serial.print(humidity);
    Serial.println(" %");

    delay(2000);  // Wait 2 seconds before next reading
}

πŸ“Œ How it works:

  • The dht.readTemperature() function reads the temperature in Celsius.
  • The dht.readHumidity() function reads the humidity percentage.
  • If the sensor fails to respond, it prints an error message.
  • Data is updated every 2 seconds (recommended by the DHT11 specs).


πŸ”Ή 5. DHT11 vs DHT22: Which One to Use?

The DHT22 (AM2302) is a more accurate and wider-range version of the DHT11.

FeatureDHT11DHT22 (AM2302)
Temperature Range0 to 50Β°C-40 to 80Β°C
Temperature AccuracyΒ±2Β°CΒ±0.5Β°C
Humidity Range20% to 90% RH0% to 100% RH
Humidity AccuracyΒ±5% RHΒ±2% RH
Sampling Rate1 Hz (1s)0.5 Hz (2s)
CostCheaper (~$2-3)More Expensive (~$5-7)

πŸ“Œ Verdict:

  • Use DHT11 for simple low-cost projects where Β±2Β°C accuracy is acceptable.
  • Use DHT22 if you need better accuracy and wider temperature range.

🌑️ DHT11 vs. DHT22: Detailed Comparison


πŸ”Ή 6. Common Issues & Fixes

❌ Sensor not responding? βœ… Check wiring, pull-up resistor, and power supply.

❌ Incorrect temperature/humidity readings? βœ… Allow the sensor to stabilize for a few seconds after startup.

❌ Slow updates? βœ… DHT11 updates every 1 second. Use a faster sensor (DHT22 or AM2302) if needed.


🎯 Conclusion

  • DHT11 is a simple, low-cost digital sensor for temperature and humidity.
  • Easy to connect with only 1 data pin.
  • Best for beginner projects, home automation, and IoT applications.
  • For better accuracy, use DHT22 instead.
πŸ“‘Broadcast the signal β€” amplify the connection.

Leave a Reply