Arduino DHT11 Sensor (Humidity & Temperature) Interfacing

In this tutorial, you’ll learn how to interface Arduino with DHT11 Sensor (Humidity & Temperature Sensor) and use it for monitoring humidity and temperature applications. We’ll discuss how to install and use the Arduino DHT11 Library and its functions.

Then, we’ll create a couple of Arduino DHT11 code example projects to practice what we’ll learn in this tutorial. In the first example, we’ll print out the humidity & temperature readings to the serial monitor. And in the second project, we’ll use Arduino DHT11 + LCD 16×2 I2C to print the readings. Without further ado, let’s jump right into it!

Table of Contents

  1. Arduino DHT11 & DHT22 Sensors
  2. DHT11 Sensor Working Principles
  3. DHT11 Sensor Pinout
  4. Arduino DHT11 Sensor Wiring
  5. Arduino DHT11 Library – Installation Steps
  6. Arduino DHT11 Code Example
  7. Arduino DHT11 With LCD 16×2 I2C (Temperature & Humidity)
  8. Wrap Up

Arduino DHT11 & DHT22 Sensors

The DHT11 & DHT22 sensors are Digital Humidity & Temperature sensors, hence the name DHTxx. Both sensors do the exact same thing while the DHT22 has some better specs than the DHT11 in terms of accuracy and range. This makes the DHT22 a bit more expensive solution than the DHT11 which is a very low-cost humidity & temperature sensor.

DHT11 Sensor ModuleDHT22 Sensor Module
DHT11DHT22
Operating Voltage3.3 – 5.5v3.3v – 5v
Max Current Consumption2.5mA2.5mA
Temperature Range0 – 50°C-40 to 80°C
Temperature Accuracy± 2°C± 0.5°C
Humidity Range20 – 95%0 – 100%
Humidity Accuracy± 5%± 2-5%
Sampling Rate1Hz (one reading every 1 second)0.5Hz (one reading every 2 seconds)
Body Size15.5mm x 12mm x 5.5mm15.1mm x 25mm x 7.7mm
PriceVery LowMore Expensive
AdvantagesVery Low-Cost
Higher Sampling Rate Than DHT22
Better Measurement Ranges
Higher Accuracy

In this tutorial, we’ll only focus on the DHT11 sensor and learn how to interface it with Arduino. We’ll first discuss how the DHT11 sensor works internally, then we’ll move to install the Arduino DHT11 library and create a couple of example demo projects using Arduino and the DHT11 sensor.

In another tutorial, we discussed the DHT22 sensor interfacing with Arduino in detail with some code example projects. If you’d like to check it out, it’s linked below.

???? Also Read
Arduino DHT22 Code Examples & Tutorial

This tutorial will give you more in-depth information about the DHT22 sensor, how it works, and how to interface it with Arduino using the DHT22 library. You’ll also find a couple of Arduino DHT22 code example projects using UART and I2C LCD for monitoring Humidity & Temperature.


DHT11 Sensor Working Principles

Inside the DHT11 sensor’s module, you’ll find an NTC thermistor and a humidity-sensing component on one side of the internal board. On the back side of the board, you’ll find a small microcontroller that handles data acquisition, processing, and transmission over the 1-Wire digital protocol as specified in the datasheet of the DHT11 sensor.

DHT11 Temperature Sensor

Temperature Sensing is handled by the integrated NTC thermistor inside the DHT11 module. The NTC (Negative Temperature Coefficient) Thermistor is a resistor that has a negative proportion relationship with the temperature. The resistance of the NTC drops as the temperature increases and vice versa as indicated in the diagram below.

Arduino-DHT11-Temperature-Sensor-NTC

The internal microcontroller is responsible for reading the internal NTC thermistor and calculating the corresponding temperature value using the characteristics curve of the NTC, then it sends the digital temperature value over the 1-Wire data line (once per second).

DHT11 Humidity Sensor

Humidity Sensing is handled by the internal humidity sensing component inside the DHT11 sensor’s module. The humidity sensing component in the DHT11 sensor utilizes a moisture-sensitive capacitor, which changes its capacitance based on the moisture level in the air.

The DHT11 sensor’s built-in microcontroller charges and discharges the moisture-sensitive capacitor and determines its capacitance by measuring the charging/discharging time. Then it converts the capacitance value into a digital signal, which is transmitted over a 1-Wire serial interface.

Arduino-DHT11-Humidity-Sensor-Working-Principle

The DHT11 Humidity Sensor measures and outputs the relative humidity (RH%) of the surrounding environment. The formula (equation) of the relative humidity is as follows:

DHT11-Relative-Humidity-Formula-Equation

Where RH is the relative humidity, ρw is the density of water vapor at a certain temperature, and ρs is the density of water vapor at saturation at that temperature.

Relative Humidity is a measure of the amount of water vapor present in the air compared to the maximum amount of water vapor the air can hold at a given temperature. When the air reaches its saturation point, meaning it contains as much water vapor as it can hold, condensation begins to occur, resulting in the formation of dew (moisture) on surfaces.

The saturation point of water vapor in the air is influenced by the temperature. Colder air has a lower capacity to hold water vapor before reaching saturation, while hotter air can hold a higher amount of water vapor before becoming saturated.

Relative Humidity is typically expressed as a percentage (%). When the relative humidity is 100%, the air is fully saturated, leading to condensation. On the other hand, when the relative humidity is 0%, the air is completely dry, indicating the absence of water vapor.

❕ Note

The DHT11 sensor has a sampling rate of 1Hz which means that it does update the humidity & temperature readings once per second. However, you can still read the sensor multiple times per second but you’ll still get the same values because the sensor’s internal update rate (sampling) is fixed at 1Hz only. Reading the sensor at a higher rate is possible but not beneficial.


DHT11 Sensor Pinout

There are two versions of the DHT11 sensors in the market. The bare DHT11 sensor (on the right) has 4 pins, and the DHT11 sensor’s module (on the left) has 3 pins and an onboard pull-up resistor. If you’re going to use the bare DHT11 sensor, you’ll need an external 10kΩ pull-up resistor.

Arduino-DHT11-Sensor-Pinout


Arduino DHT11 Sensor Wiring

Here is the wiring diagram for the Arduino DHT11 sensor connection. I’m using a 10kΩ pull-up resistor for the pin2 of the DHT11 sensor. And note that the DHT11 sensor’s pin3 is NC (no connection) and is left floating.

Arduino-DHT11-Sensor-Wiring-Diagram

For the DHT11 Sensor’s module (that has 3 pins only), it’s basically the same thing but you’ll not have to include an external pull-up resistor. Just hook it up to +5v, GND, and the digital IO pin to read the sensor’s data.


Arduino DHT11 Library – Installation Steps

To use the DHT11 Sensor With Arduino, we’ll need to install the following 2 libraries:

  1. Adafruit Unified Sensor Library
  2. DHT Sensor Library

You can download and install the Adafruit Unified Sensor library manually from GitHub, or alternatively, install it within the Arduino IDE itself. Just open the library manager. Tools > Manage Libraries > Search for “Adafruit Unified Sensor”. Then, click Install and let it finish the installation.

Arduino-DHT11-DHT22-Sensors-Library-Install

Next, you’ll need to install the DHT Sensor Library in a similar way. Just open the library manager in Arduino IDE. Tools > Manage Libraries > Search for “DHT Sensor”. Then, click Install and let it finish the installation.

Arduino-DHT11-DHT22-Library-Install

And now, we’re ready to write some code to test Arduino DHT11 Sensor interfacing to read humidity & temperature values from the sensor. In the following two examples, we’ll interface Arduino with a DHT11 sensor and print the humidity & temperature readings on both the serial monitor and an LCD display.


Arduino DHT11 Code Example

In this example project, we’ll use Arduino with the DHT11 humidity & temperature sensor to take the measurement values and print them on the serial monitor. This is a very basic example to test that your DHT11 sensor is working properly and your connections are okay.

Wiring

Code Example

Here is the full code listing for this example.

Code Explanation

First of all, we should include the DHT.h library.

Then, we define the IO pin to be used to interface the DHT11 sensor using the 1-Wire protocol. I’ll be using the Arduino pin7 for this. And we’ll also need to specify the DHT sensor’s type (in our case it’s a DHT11 sensor). Because the library does also support other sensors from the same family like DHT22.

And we’ll create an instance of the DHT class (object) and will name it DHT11_Sensor and give it the IO pin number and sensor type.

setup()

in the setup() function, we’ll initialize the UART serial communication port @ 9600bps and the DHT11_Sensor object.

loop()

in the loop() function, we’ll call the readHumidity() function to read the relative humidity percentage of the DHT11 sensor. And we’ll also call the readTemperature() function to get the temperature reading of the DHT11 sensor (in °C). Calling the readTemperature(true) function with a true argument will return the temperature value (in °F) instead.

Then, we’ll print out the readings on the serial monitor. A delay of 1 second is inserted to slow down the sampling and printing rate but you can sample and print as fast as you can! Just remember that the DHT11 sensor’s output only changes once per second. Reducing the delay will speed up the sampling and printing process but at no additional benefit as the sensor’s output stays the same until a complete second passes.

Testing Results

Here is the result of testing this project on my Arduino UNO board as shown on the serial monitor.

Arduino-DHT11-Example-Code-Result


Arduino DHT11 With LCD 16×2 I2C (Temperature & Humidity)

In this example project, we’ll use Arduino with the DHT11 humidity & temperature sensor to take the measurement values and print them on an I2C LCD 16×2 display. This example project will use the I2C LCD 16×2 with Arduino which you can learn more about by checking the tutorial linked below.

???? Also Read
Arduino I2C LCD 16x2 Interfacing Tutorial & Library Examples

This is the ultimate guide for Arduino I2C LCD 16×2 interfacing and library functions explanation. It’ll guide you through everything you’d need to interface Arduino with an I2C LCD display.

Wiring

Here is the wiring diagram for Arduino with the DHT11 sensor and the I2C LCD 16×2 display.

Arduino-DHT11-LCD-Example-Wiring-Diagram

Code Example

Here is the full code listing for this example.

Code Explanation

First of all, we should include the DHT.h library, the I2C library ( wire.h), and the I2C_LCD library as well.

Then, we define the IO pin to be used to interface the DHT11 sensor using the 1-Wire protocol. I’ll be using the Arduino pin7 for this. And we’ll also need to specify the DHT sensor’s type (in our case it’s a DHT11 sensor). Because the library does also support other sensors from the same family like DHT22.

And we’ll create an instance of the DHT class (object) and will name it DHT11_Sensor and give it the IO pin number and sensor type. And we’ll also create an instance of the I2C_LCD class with the I2C LCD’s address and LCD’s character dimensions (16 columns, 2 rows).

setup()

in the setup() function, we’ll initialize the I2C LCD 16×2 display & turn ON its backlight, and also initialize the DHT11_Sensor object.

loop()

in the loop() function, we’ll call the readHumidity() function to read the relative humidity percentage of the DHT11 sensor. And we’ll also call the readTemperature() function to get the temperature reading of the DHT11 sensor (in °C).

Then, we’ll print out the readings on the I2C LCD 16×2 display. A delay of 1 second is inserted to slow down the sampling and printing rate but you can sample and print as fast as you can! Just remember that the DHT11 sensor’s output only changes once per second. Reducing the delay will speed up the sampling and printing process but at no additional benefit as the sensor’s output stays the same until a complete second passes.

Testing Results

Here is the result of testing this project on my Arduino UNO board as shown on the I2C LCD 16×2 display.

Arduino-DHT11-LCD-16x2-Example-Code-Demo


Parts List

Here is the full components list for all parts that you’d need in order to perform the practical LABs mentioned here in this article and for the whole Arduino Programming series of tutorials found here on DeepBlueMbedded. Please, note that those are affiliate links and we’ll receive a small commission on your purchase at no additional cost to you, and it’d definitely support our work.

Download Attachments

You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting my work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports our community.


Wrap Up

To conclude this tutorial, we can say that you can easily interface Arduino with the DHT11 sensor to read the relative humidity & temperature and use that information for various Arduino projects. You can build on top of the examples provided here in this tutorial to create so many applications, you’re only limited by your imagination. Just let me know if you’ve got further questions or need any help implementing your own project.

If you’re just getting started with Arduino, you need to check out the Arduino Getting Started [Ultimate Guide] here.

And follow this Arduino Series of Tutorials to learn more about Arduino Programming.

For more projects & ideas, check this Arduino Projects resource page.

???? Also Read
Getting Started With Arduino Programming For Beginners

This is the ultimate guide for getting started with Arduino for beginners. It’ll help you learn the Arduino fundamentals for Hardware & Software and understand the basics required to accelerate your learning journey with Arduino Programming.


FAQ & Answers

What is DHT11 Arduino?

The DHT11 is a very basic digital humidity & temperature sensor that’s used in so many Arduino projects due to its low-cost and acceptable accuracy.
The DHT11 can measure temperature within the following range (0 – 50°C) and relative humidity within the range (20-95%). The DHT11 temperature measurement has an accuracy of ± 2°C and the humidity measurement’s accuracy is around ± 5%.

How to program DHT11 on Arduino?

To program DHT11 sensor on Arduino, you need to install the following 2 libraries: (Adafruit Unified Sensor Library, and DHT Sensor Library).
Then, you can easily include the <DHT.h> library, create an instance of the DHT class, and assign to it the IO pin number to be used for the 1-Wire interface, and the sensor type (DHT11 or DHT22).
Taking the measurements will be as simple as calling the following functions: [ readTemperature() , readHumidity() ].

What temperature does DHT11 read in Arduino?

The DHT11 sensor has an internal NTC thermistor that’s used to read the surrounding environment’s temperature within the following range (0 – 50°C). So the DHT11 sensor can be used with Arduino for temperature monitoring applications as long as the “to-be-measured” temperature falls within the sensor’s range. Otherwise, the DHT22 sensor would be a better option as it has a wider temperature measurement range which is (-40 to 80°C).

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment