Because of their low cost and small size, DHT11 humidity and temperature sensors are perfect for lots of different DIY electronics projects. Some projects where the DHT11 would be useful include remote weather stations, home environment control systems, and agricultural/garden monitoring systems. The DHT11 is a digital sensor that lets you easily get relative humidity and temperature readings in your projects. In this post, I’ll first go into a little background on what humidity is, then I’ll explain how the DHT11 measures humidity. After that, I’ll show you how to connect the DHT11 to the Arduino and give you some example code so you can use the DHT11 in your own projects.

DHT11 Technical Specifications:

  • Humidity Range: 20-90% RH
  • Humidity Accuracy: ±5% RH
  • Temperature Range: 0-50 °C
  • Temperature Accuracy: ±2% °C
  • Operating Voltage: 3V to 5.5V

The DHT11 Datasheet:

Circuit Basics PDF Icon DHT11 Datasheet

What is Relative Humidity?

The DHT11 humidity and temperature sensor measures relative humidity (RH) and temperature. Relative humidity is the ratio of water vapor in air vs. the saturation point of water vapor in air. The saturation point of water vapor in air changes with temperature. Cold air can hold less water vapor before it is saturated, and hot air can hold more water vapor before it is saturated. The formula for relative humidity is as follows:

Relative Humidity = (density of water vapor / density of water vapor at saturation) x 100%

Basically, relative humidity is the amount of water in the air compared to the amount of water that air can hold before condensation occurs. It’s expressed as a percentage.  For example, at 100% RH condensation (or rain) occurs, and at 0% RH, the air is completely dry.

How the DHT11 Measures Humidity and Temperature

The DHT11 calculates relative humidity by measuring the electrical resistance between two electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate (usually a salt or conductive plastic polymer) with the electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes while lower relative humidity increases the resistance between the electrodes. Inside the DHT11 you can see electrodes applied to a substrate on the front of the chip:

DHT11 Temperature and Humidity Sensor Inside Front with Cover Removed

The DHT11 converts the resistance measurement to relative humidity on an IC mounted to the back of the unit and transmits the humidity and temperature readings directly to the Arduino. This IC also stores the calibration coefficients and controls the data signal transmission between the DHT11 and the Arduino:

DHT11 Temperature and Humidity Sensor Inside Back with Cover Removed

The temperature readings from the DHT11 come from a surface mounted NTC temperature sensor (thermistor) built into the unit. To learn more about thermistors and how to use them on the Arduino, check out our Arduino Thermistor Temperature Sensor Tutorial.

The DHT11 uses one signal wire to transmit sensor readings to the Arduino digitally. The power comes from separate 5V and ground wires. A 5K – 10K Ohm pull-up resistor is connected from the signal line to 5V to make sure the signal level stays high by default (see the datasheet for specifics on how the signal is sent).

There are two different variations of the DHT11 sensor you might come across. One type has four pins, and the other type is mounted to a small PCB that has three pins. The PCB mounted version with three pins is nice since it includes a surface mounted 10K Ohm pull up resistor for the signal line:

Comparison of three pin DHT11 vs four pin DHT11

How to Set Up the DHT11 on an Arduino

The DHT11 is really easy to connect to the Arduino:

DHT11 Humidity and Temperature Sensor Connections for Arduino

Code for Serial Monitor Output of Readings

Before we can use the DHT11 on the Arduino, we need to install the DHTLib library, which contains all of the functions we will need to get the humidity and temperature readings from the sensor. It’s easy to install. Just download the DHTLib.zip file below, and open up the Arduino IDE. Then go to Sketch>Include Library>Add Library and select the DHTLib.zip file.

Circuit Basics ZIP Icon DHTLib

After the library is installed, upload this example program to the Arduino, and open the serial monitor. You should see the humidity and temperature readings displayed at one second intervals:

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}

This simple program will take humidity and temperature data from the sensor and print it to the serial monitor. What if you don’t need to actually see the humidity and temperature readings, but need them to calculate or control other things? Just use DHT.humidity and DHT.temperature as variables in any function and include the following lines of code in your program to initialize the sensor. The DHT11 signal pin (in #define DHT11_PIN 7) can be changed to any other available digital pin:

#include <dht.h>

dht DHT;

#define DHT11_PIN 7

void setup(){
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  delay(1000);
}

To see how we use the DHT11 sensor outputs as variables in other functions, see our article How to Set Up an Ultrasonic Range Finder on an Arduino where we take the temperature and humidity readings from the DHT11 and input them into a formula that improves the accuracy of an ultrasonic range finder.

Output Humidity and Temperature Readings to an LCD Display

If you do want the actual humidity and temperature readings from the DHT11, a nice way to display them is on a 16X2 LCD. To do this, first follow our tutorial on How to Set Up an LCD Display on an Arduino, then upload this code to the Arduino:

#include <dht.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

dht DHT;

#define DHT11_PIN 7

void setup(){
  lcd.begin(16, 2);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  lcd.setCursor(0,0); 
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humidity: ");
  lcd.print(DHT.humidity);
  lcd.print("%");
  delay(1000);
}

Note: I’ve recently updated this program to add a degree symbol (“°”) and “C” after the temperature reading, and a “%” sign after the humidity.

Watch the video tutorial for this project here:

If you have any questions about how to set up a DHT11 humidity and temperature sensor on your Arduino, just leave a comment below and I will answer it as soon as possible. If you find Circuit Basics useful, please subscribe to us! Just leave your email address at the top of this post and we will let you know as soon as we publish new articles. Also, please share this article if you know anybody else that might find it helpful!

Need an easy-to-use way to design circuits and layout PCBs?