The DHT11 is a basic, ultra-low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and provides a digital signal on the data pin (no analog input pins needed). It's fairly simple to use but requires careful timing to grab data. The DHT11 is widely used in hobbyist projects with microcontrollers such as Arduino boards due to its ease of interfacing and low cost.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3-5.5V DC) |
2 | DATA | Serial data output |
3 | NC | Not connected |
4 | GND | Ground |
Connecting the DHT11:
Programming the Arduino:
#include "DHT.h"
#define DHTPIN 2 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
float humidity = dht.readHumidity();
// Read temperature as Celsius (the default)
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
// Compute heat index in Celsius (isFahrenheit = false)
float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.print(F("°C Heat index: "));
Serial.print(heatIndex);
Serial.println(F("°C"));
}
Q: Can the DHT11 sensor be used outdoors? A: The DHT11 is not waterproof and is designed for indoor use. If you need to measure outdoor humidity, place it in a protected location.
Q: How long should I wait between readings? A: The DHT11 requires at least 1 second between readings for the data to be accurate.
Q: What is the lifespan of the DHT11 sensor? A: With proper use, the DHT11 sensor can last for several years. However, its performance may degrade over time, especially if exposed to extreme conditions.
Q: Can I use a longer cable to connect the DHT11 to an Arduino? A: Yes, but you may need to use a pull-up resistor to ensure signal integrity, especially if the cable is longer than 20 cm.
Q: Is calibration required for the DHT11 sensor? A: The DHT11 comes pre-calibrated from the factory. However, for critical applications, you may want to calibrate it against a known humidity and temperature source.