What is the DHT11 Sensor?
The **DHT11** is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensing element and a thermistor to measure the surrounding air. It outputs a calibrated digital signal on the data pin — no analog input is needed!
The DHT11 is perfect for beginners, weather stations, home automation, and IoT monitoring projects. It comes in two forms:
- **Bare sensor** (4 pins, blue plastic housing)
- **Module** (3 pins with built-in resistor, mounted on a small PCB)
For beginners, we recommend the **module version** as it has the required pull-up resistor already soldered.
DHT11 vs DHT22 — Which to Choose?
|---|---|---|
**Verdict**: Use DHT11 for learning and basic projects. Choose DHT22 for weather stations or projects requiring higher accuracy and wider range.
How the DHT11 Works
The sensor uses a **single-wire digital protocol** (not I2C, not SPI) to communicate:
1. The microcontroller sends a **start signal** by pulling the data line LOW for 18ms, then HIGH for 20–40µs.
2. The DHT11 responds with a **LOW-HIGH acknowledgment** pulse.
3. It then sends **40 bits of data** (5 bytes):
- Byte 1: Humidity integer
- Byte 2: Humidity decimal (always 0 for DHT11)
- Byte 3: Temperature integer
- Byte 4: Temperature decimal (always 0 for DHT11)
- Byte 5: Checksum (sum of bytes 1–4)
💡 Fortunately, you don't need to handle this protocol manually — the **DHT library** handles it all for you!
Wiring with Arduino & Code
**Module Version (3 pins):**
- **VCC** → Arduino 5V (or 3.3V)
- **DATA** → Arduino Digital Pin 2
- **GND** → Arduino GND
**Install the library**: In Arduino IDE → Sketch → Include Library → Manage Libraries → Search "DHT sensor library" by Adafruit → Install. Also install "Adafruit Unified Sensor".
**Arduino Code:**
#include <DHT.h>
#define DHT_PIN 2
#define DHT_TYPE DHT11
DHT dht(DHT_PIN, DHT_TYPE);
void setup() {
Serial.begin(9600);
dht.begin();
Serial.println("DHT11 Sensor Ready!");
}
void loop() {
delay(2000); // DHT11 needs 1-2 sec between readings
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(); // Celsius
Serial.println("Error reading DHT11!");
return;
}
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(humidity);
Serial.println("%");
}
Building an IoT Dashboard with ESP32
Take it to the next level by connecting the DHT11 to an **ESP32** and sending live data to a web dashboard!
**What you'll need:**
- ESP32 DevKit board
- DHT11 sensor module
- WiFi connection
- Blynk / ThingSpeak / custom web server
**ESP32 Wiring:**
- DHT11 DATA → GPIO 4
- DHT11 VCC → 3.3V
- DHT11 GND → GND
**Basic ESP32 Code (with Serial output):**
#include <WiFi.h>
#include <DHT.h>
#define DHT_PIN 4
#define DHT_TYPE DHT11
const char* ssid = "YourWiFi";
const char* password = "YourPassword";
DHT dht(DHT_PIN, DHT_TYPE);
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nWiFi Connected!");
Serial.println(WiFi.localIP());
}
void loop() {
delay(2000);
float temp = dht.readTemperature();
float hum = dht.readHumidity();
if (!isnan(temp) && !isnan(hum)) {
// Send to ThingSpeak, Blynk, or your API here
}
}
🌐 **Next Step**: Use **ThingSpeak** (free for up to 3 million messages/year) to visualize your data in beautiful charts online!
Tips & Best Practices
- **Wait at least 1 second** between readings — the DHT11 has a 1Hz sampling rate.
- **Keep the sensor away from heat sources** (motors, voltage regulators, direct sunlight) for accurate readings.
- **Use a 10kΩ pull-up resistor** on the data line if using the bare sensor (modules have it built-in).
- **Don't use in high-humidity environments** — the DHT11 caps at 80% RH. Use DHT22 for those cases.
- **For outdoor use**, consider a protective enclosure with ventilation holes to protect the sensor while allowing air flow.
- **Calibration**: Compare readings with a known accurate thermometer and apply offset in code if needed.

