The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin. This sensor is widely used in various applications due to its simplicity and affordability.
Parameter | Value |
---|---|
Operating Voltage | 3.3V to 5.5V |
Max Current | 2.5mA |
Humidity Range | 20-90% RH |
Temperature Range | 0-50°C |
Humidity Accuracy | ±5% RH |
Temperature Accuracy | ±2°C |
Sampling Rate | 1Hz (once every second) |
Interface | Digital single-bus |
Pin Number | Pin Name | Description |
---|---|---|
1 | VCC | Power supply (3.3V to 5.5V) |
2 | Data | Serial data output |
3 | NC | Not connected |
4 | GND | Ground |
+-------------------+
| |
| DHT11 Sensor |
| |
+-------------------+
| | | |
| | | |
VCC Data NC GND
| | |
| | |
5V D2 GND
| | |
| | |
+---+-------+
|
10kΩ
|
VCC
#include "DHT.h"
#define DHTPIN 2 // Pin connected to the Data pin of DHT11
#define DHTTYPE DHT11 // Define the type of DHT sensor
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
delay(2000); // Wait a few seconds between measurements
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" *C");
}
By following this documentation, users should be able to effectively integrate and troubleshoot the DHT11 temperature and humidity sensor in their projects.