The DHT11 is a digital temperature and humidity sensor that provides accurate readings of temperature in Celsius and humidity in percentage. It is a low-cost, easy-to-use sensor that communicates via a single-wire digital interface. The DHT11 is widely used in applications such as weather stations, HVAC systems, and home automation projects due to its reliability and simplicity.
The DHT11 sensor is designed for basic temperature and humidity sensing applications. Below are its key technical details:
Parameter | Value |
---|---|
Operating Voltage | 3.3V to 5.5V |
Operating Current | 0.3mA (measuring), 60µA (standby) |
Temperature Range | 0°C to 50°C |
Temperature Accuracy | ±2°C |
Humidity Range | 20% to 90% RH |
Humidity Accuracy | ±5% RH |
Sampling Period | 1 second |
Communication Protocol | Single-wire digital interface |
The DHT11 sensor typically comes with four pins. Below is the pinout description:
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5.5V) |
2 | DATA | Digital data output (connect to microcontroller) |
3 | NC (Not Connected) | No connection (leave unconnected) |
4 | GND | Ground (0V reference) |
Note: Some DHT11 modules may have only three pins (VCC, DATA, GND) with an onboard pull-up resistor. Always check the specific module's datasheet.
The DHT11 sensor is straightforward to use in a circuit. Below are the steps and best practices for integrating it into your project:
Below is an example code to read temperature and humidity data from the DHT11 using an Arduino UNO. This code uses the popular DHT
library.
// Include the DHT library
#include <DHT.h>
// Define the DHT11 pin and type
#define DHTPIN 2 // Pin connected to the DATA pin of DHT11
#define DHTTYPE DHT11 // Specify the sensor type (DHT11)
// Initialize the DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600); // Start serial communication
Serial.println("DHT11 Sensor Initialization");
dht.begin(); // Initialize the DHT sensor
}
void loop() {
delay(2000); // Wait 2 seconds between readings
// Read temperature and humidity
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if the readings are valid
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Print the results to the Serial Monitor
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" °C");
}
No Data or Incorrect Readings:
"Failed to read from DHT sensor!" Error:
Inconsistent Readings:
Sensor Not Responding:
Q1: Can the DHT11 measure negative temperatures?
A1: No, the DHT11 can only measure temperatures in the range of 0°C to 50°C.
Q2: How often can I take readings from the DHT11?
A2: The DHT11 has a sampling period of 1 second, so you should wait at least 1 second between readings.
Q3: Can I use the DHT11 with a 3.3V microcontroller?
A3: Yes, the DHT11 operates within a voltage range of 3.3V to 5.5V, making it compatible with 3.3V systems.
Q4: What is the difference between DHT11 and DHT22?
A4: The DHT22 offers a wider temperature range (-40°C to 80°C) and higher accuracy compared to the DHT11, but it is more expensive.
By following this documentation, you can effectively integrate the DHT11 sensor into your projects and troubleshoot common issues.