Temperature & Humidity Monitoring with DHT11
Interface a single-bus digital sensor to acquire calibrated environmental humidity and temperature telemetry in real time.
Greenhouse climate regulators, museum HVAC preservation systems, and food cold-chain storage monitoring.
The DHT11 uses a capacitive humidity sensing element and a thermistor connected to an onboard 8-bit chip. It transmits 40 bits of serial data over a single bidirectional wire with parity checksum.
Pin Connection & Wiring Table
| Component Pin / Terminal | Microcontroller Pin (ESP32 / Arduino) | Wiring Note |
|---|---|---|
| VCC (+) | 3.3V or 5V | Power supply |
| DATA / OUT | GPIO 15 / Pin 2 | Digital single-bus data line |
| GND (-) | GND | Common ground |
Step-by-Step Plug & Play Assembly
Identify the 3 pins on the DHT11 breakout board: VCC, DATA, and GND.
Connect VCC to 3.3V and GND to the GND terminal on ESP32.
Connect the DATA pin to GPIO 15.
Install the "DHT sensor library by Adafruit" via Arduino Library Manager.
Complete Tested Source Code
// NovaCircuit Project 3: DHT11 Temperature & Humidity Sensor
#include "DHT.h"
#define DHTPIN 15
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
Serial.println("DHT11 Environmental Sensor Initializing...");
dht.begin();
}
void loop() {
delay(2000); // DHT11 requires at least 1-2 seconds between readings
float humidity = dht.readHumidity();
float temperature = dht.readTemperature(); // Celsius
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Error: Failed to read from DHT sensor! Check wiring.");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity, 1);
Serial.print("% | Temperature: ");
Serial.print(temperature, 1);
Serial.println(" °C");
}The DHT library handles the timing-sensitive microsecond pulses required by the sensor protocol. readHumidity() and readTemperature() parse the 40-bit frame into human-readable metric values.
Expected Physical Output
- •NaN readings: Verify DATA pin connection and check if DHT11 is receiving adequate voltage (try 5V if 3.3V is unstable).
- •Readings update too slowly: DHT11 hardware response time is 1-2 seconds; avoid querying faster than once per 2000ms.
- •Keep the sensor away from liquid water immersion; it measures airborne water vapor, not direct liquid immersion.
Related Book Chapter & Hardware Kit
Covered in depth within Chapter 6: Sensors and Their Applications. Build this easily with the Sensor Explorer Kit.