The DHT11 Sensor V2 is a low-cost, digital temperature and humidity sensor that provides reliable readings for environmental monitoring. It is widely used in various applications such as weather stations, home automation systems, and HVAC control. The sensor is known for its ease of use and is particularly popular among hobbyists and educators for use in small projects.
Pin Number | Name | Description |
---|---|---|
1 | VCC | Power supply (3.3 to 5V DC) |
2 | DATA | Serial data output |
3 | NC | Not connected |
4 | GND | Ground |
#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("Failed to read from DHT sensor!");
return;
}
// Compute heat index in Celsius (isFahrenheit = false)
float heatIndex = dht.computeHeatIndex(temperature, humidity, false);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature: ");
Serial.print(temperature);
Serial.print("°C Heat index: ");
Serial.print(heatIndex);
Serial.println("°C");
}
Q: Can I use the DHT11 sensor outdoors? A: Yes, but it should be protected from direct sunlight and water.
Q: How long does the DHT11 sensor last? A: With proper use, the DHT11 can last for several years.
Q: Can I use multiple DHT11 sensors on the same microcontroller? A: Yes, each sensor will require a separate digital pin for the data signal.
Q: How do I calibrate the DHT11 sensor? A: The DHT11 is factory calibrated and does not typically require additional calibration. If precision is critical, consider using a more accurate sensor.
Q: What is the operating range of the DHT11 sensor? A: The DHT11 operates from 0 to 50°C for temperature and from 20% to 80% for humidity, with specified accuracy ranges.