How To Connect DHT11 Temperature And Humidity Sensor To Arduino

Table of contents:

How To Connect DHT11 Temperature And Humidity Sensor To Arduino
How To Connect DHT11 Temperature And Humidity Sensor To Arduino

Video: How To Connect DHT11 Temperature And Humidity Sensor To Arduino

Video: How To Connect DHT11 Temperature And Humidity Sensor To Arduino
Video: DHT11 Temperature & Humidity sensor with Arduino - Tutorial 2024, December
Anonim

The DHT17 temperature and humidity sensor is a popular and cheap sensor that can be used over a fairly wide range of temperatures and relative humidity. Let's see how to connect it to the Arduino and how to read data from it.

DHT11 temperature and humidity sensor
DHT11 temperature and humidity sensor

Necessary

  • - Arduino;
  • - DHT17 temperature and humidity sensor.

Instructions

Step 1

So, the DHT11 sensor has the following characteristics:

- range of measured relative humidity - 20..90% with an error of up to 5%, - range of measured temperatures - 0..50 degrees Celsius with an error of up to 2 degrees;

- response time to changes in humidity - up to 15 seconds, temperature - up to 30 seconds;

- the minimum polling period is 1 second.

As you can see, the DHT11 sensor is not very accurate, and the temperature range does not cover negative values, which is hardly suitable for outdoor measurements in the cold season in our climate. However, its low cost, small size and ease of use partially offset these disadvantages.

The figure shows the appearance of the sensor and its dimensions in millimeters.

Appearance and dimensions of the DHT11 sensor
Appearance and dimensions of the DHT11 sensor

Step 2

Consider the connection diagram of the DHT11 temperature and humidity sensor to the microcontroller, in particular, to the Arduino. On the picture:

- MCU - microcontroller (for example, Arduino or similar) or single board computer (Raspberry Pi or similar);

- DHT11 - temperature and humidity sensor;

- DATA - data bus; if the length of the connecting cable from the sensor to the microcontroller does not exceed 20 meters, then it is recommended to pull this bus to the power supply with a 5, 1 kOhm resistor; if more than 20 meters, then another suitable denomination (smaller).

- VDD - sensor power supply; permissible voltages from ~ 3.0 to ~ 5.5 volts DC; if power supply ~ 3.3 V is used, then it is advisable to use a supply wire no longer than 20 cm.

One of the sensor leads - the third - is not connected to anything.

The DHT11 sensor is often sold as a complete assembly with the necessary piping - pull-up resistor and filter capacitor.

Diagram of connecting DHT11 sensor to microcontroller
Diagram of connecting DHT11 sensor to microcontroller

Step 3

Let's put together the considered scheme. I will also connect a logic analyzer to the circuit so that I can study the timing diagram of the communication with the sensor.

DHT11 sensor and Arduino
DHT11 sensor and Arduino

Step 4

Let's go the simple way: download the library for the DHT11 sensor (link in the "Sources" section), install it in the standard way (unpacking it into the / libraries / directory of the Arduino development environment).

Let's write such a simple sketch. Let's load it into Arduino. This sketch will output the RH and Temperature messages read from the DHT11 sensor to the computer's serial port every 2 seconds.

Sketch for working with a DHT11 temperature-humidity sensor
Sketch for working with a DHT11 temperature-humidity sensor

Step 5

Now, using the timing diagram obtained from the logic analyzer, let's figure out how the information exchange is carried out.

The DHT11 temperature and humidity sensor uses a single-wire serial interface to communicate with the microcontroller. One data exchange takes about 40 ms and contains: 1 request bit from the microcontroller, 1 bit of the sensor response and 40 data bits from the sensor. The data includes: 16 bits of humidity information, 26 bits of temperature information, and 8 check bits.

Let's take a closer look at the timing diagram of the Arduino communication with the DHT11 sensor.

It can be seen from the figure that there are two types of impulses: short and long. Short pulses in this exchange protocol mean zeros, long pulses - ones.

So, the first two pulses are the Arduino's request to DHT11 and, accordingly, the sensor's response. Next comes 16 bits of humidity. Moreover, they are divided into bytes, high and low, high on the left. That is, in our figure, the moisture data is as follows:

0001000000000000 = 00000000 00010000 = 0x10 = 16% RH.

Temperature data similar to:

0001011100000000 = 00000000 00010111 = 0x17 = 23 degrees Celsius.

Check bits - the checksum is just the summation of 4 received data bytes:

00000000 +

00010000 +

00000000 +

00010111 =

00100111 in binary or 16 + 23 = 39 in decimal.

Recommended: