OCFreaks!

Basics of Interfacing DHT11/DHT22 Humidity and Temperature Sensor with MCU

DHT11/DHT22 are pretty well known sensors for sensing relative humidity and Temperature. These are digital sensors are based on a custom protocol which use a single wire/bus for communication. The primary difference between DHT11 and DHT22 is that, DHT22 has higher resolution and is more accurate as compared to DHT11. Other than that, the pinout and programming is same for both. In this tutorial we will go through basics of protocol/communication process for DHTxx sensors. Also, do note that the protocol used by DHTxx is NOT same as 1-wire bus by Dallas Semiconductor.

Specifications & DHT11 Vs DHT22:

Parameter DHT11 DHT22
Temperature measurement range 0 to 50 Deg.C -40 to 80 Deg.C
Temperature Accuracy +- 1 to 2 Deg.C +- 0.5 Deg.C
Relative Humidity Range 30% to 90% 0% to 100%
Relative Humidity Accuracy +- 4% to 5% +-2 to 5%
Operating Voltage 3.3V to 5V 3.3V to 5V
Resolution 8 bits 16 bits
Sampling period >=1 sec >=2 sec

DHT22 & DHT11 Pinout:

The DATA wire used for communication between microcontroller and DHT11/DHT22 is pulled HIGH using a 4.7K or 10K pull-up resistor. This is to bring the bus in an IDLE state when there is no communication taking place. A continuous HIGH on the line denote an IDLE state. The microcontroller acts as the bus master and hence is responsible for initiating communication (i.e. Read). DHTxx Humidity and Temperature sensor always remain as slave and responds with data when MCU asks for it. The protocol used for communication is simple and can be summarized as follows:

Communication Process:
  1. When the Line is IDLE the microcontroller pulls it to a LOW for 18ms.
  2. After this MCU pulls it HIGH for around 20 to 40us.
  3. DHTxx will detect it as a START from the MCU and responds by pulling the line LOW for 80us.
  4. Next, DHTxx will pull it HIGH for 80us which indicates that it is ready to send data or “get ready”.
  5. Next it will send 40 bits of Data. Each bit starts with a 50us LOW followed by 26-28us for a “0” or 70us for a “1”.
  6. After communication ends, the Line is pulled HIGH by the pull-up resistor and enters IDLE state.

DHTxx Data Format

When Humidity and Temperature sensor sends data, it sends the MSB first. The 40bits of data is divided into 5 bytes. For DHT11 sensor 2nd and 4th byte is always Zero. The significance of these bytes is as follows:

Note that the probing interval must not be less than 1 second for DHT11 and not less than 2 seconds in order to get valid data.

Exit mobile version