Temperature and Humidity Sensor(DHT11)
This sensor measures ambient temperature and humidity, outputting the data as a digital signal. It utilizes a capacitive humidity sensor and a thermistor for measurements.
Specifications
- Operating Voltage: 3.3V ~ 5V
- Measurement Range: Temperature (0°C ~ 50°C) / Humidity (20% ~ 90%)
- Error Range: Temperature (±2°C) / Humidity (±5%)
Required Hardware
- DHT11
- Arduino
Connection
DHT11 | Arduino |
---|---|
+ | 5V |
OUT | D2 |
- | GND |
Library
- DHT sensor library (Arduino Libraries)
Example Code
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
}