Temperature and humidity (DHT11) sensor
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 temperature. There is also a very basic chip inside which does analog to digital conversion and spits out a digital signal on the data pin with the temperature and humidity.
DHT11 vs DHT22
both the DHT sensors look a bit similar and have the same pinout, but have different characteristics. Here are the specs:
DHT11 -
Ultra low cost
3 to 5V power and I/O
2.5mA max current use during conversion (while requesting data)
Good for 20-80% humidity readings with 5% accuracy
Good for 0-50°C temperature readings ±2°C accuracy
No more than 1 Hz sampling rate (once every second)
Body size 15.5mm x 12mm x 5.5mm
4 pins with 0.1" spacing
DHT22 / AM2302 (Wired version) -
Low cost
3 to 5V power and I/O
2.5mA max current use during conversion (while requesting data)
Good for 0-100% humidity readings with 2-5% accuracy
Good for -40 to 80°C temperature readings ±0.5°C accuracy
No more than 0.5 Hz sampling rate (once every 2 seconds)
Body size 15.1mm x 25mm x 7.7mm
4 pins with 0.1" spacing
DHT sensors have four pins
VCC - red wire Connect to 3.3 - 5V power
Data out - white or yellow wire
Not connected
Ground - black wire
DHTxx Sensor Library -
Arduino IDE - Sketch→Include Library→Manage Libraries…
Enter “dht” in the search field and look through the list for “DHT sensor library by Adafruit.” Click the “Install” button, or “Update” from an earlier version.
Now select Examples→DHT→DHTtester sketch
If you're using a DHT11 sensor, comment out the line that sets the type:
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
and uncomment the line that says:
#define DHTTYPE DHT11 // DHT 11
Upload the sketch and you can see output on serial monitor
You should see the temperature in C and humidity. You can see changes by breathing onto the sensor which should increase the humidity.
You can add as many DHT sensors as you line on individual pins, just add new lines such as
DHT dht2 = DHT(pin, type);
below the declaration for the initial dht object, and you can reference the new dht2 sensor to get temperature in C and humidity data.