About this project
The DHT11 humidity and temperature sensor make it really easy to add humidity and temperature data to your DIY electronics projects. It's perfect for remote weather stations, home environmental control systems, and farm or garden automation systems. In this tutorial, I'll explain how the DHT11 measures humidity and how to connect the DHT11 to an Arduino along with some example code you could use in your own projects.
Technical details
- 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
- Good for 0-50°C temperature readings
- 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
Wiring
- VCC: 3.3 - 5V power supply (sometimes 3.3V isn't enough, in which case try 5V)
- Data out: digital pin 2
- Ground: ground
Ignore the 3rd pin on the 4-pin sensor, it's not in use. Place a 10K ohm resistor between VCC and the data pin as a pull-up. This isn't needed for the 3-pin PCB-mounted module.
Programming
Install the DHT sensor library by Adafruit from the Arduino Library Manager (Sketch → Include Library → Manage Libraries…), then upload:
#include "DHT.h"
#define Type DHT11
int sensePin=2;
DHT HT(sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
void setup()
{
Serial.begin(9600);
Serial.println("DHT11 Temperature and Humidity Sensor Test_RAC");
HT.begin();
delay(setTime);
}
void loop()
{
humidity=HT.readHumidity();
tempC=HT.readTemperature();
tempF=HT.readTemperature(true);
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature ");
Serial.print(tempC);
Serial.print("°C ");
Serial.print(tempF);
Serial.println("°F ");
delay(2000);
}