DHT-11 & One wire bus

 

DHT-11 is a temperature & humidity sensor in one package. It utilizes exclusive digital-signal-collecting-technique and humidity sensing technology, assuring its reliability and stability. Its sensing elements is connected with 8-bit single-chip computer. Every sensor of this model is temperature compensated and calibrated in accurate calibration chamber and the calibration-coefficient is saved in type of program in OTP memory, when the sensor is detecting, it will cite coefficient from memory. Small size & low consumption & long transmission distance(20m) enable DHT-11 to be suited in all kinds of harsh application occasions.

Characteristics:

  • Low Cost
  • Supply voltage 3 to 5V
  • Max current 2.5mA (while requesting data)
  • 20-80% humidity range with 5% accuracy
  • 0-50C temperature range with +-2C

Inside the package looks like this:

 

SDC11305 Inside DHT-11

The interesting thing in this module is the protocol that uses to transfer data. All the sensor readings are sent using a single wire bus which reduces the cost and extends the distance.

In order to send data over a bus you have to describe the way the data will be transferred, so that transmitter and receiver can understand what says each other. This is what a protocol does. It describes the way the data are transmitted. 

On DHT-11 the 1-wire data bus is pulled up with a resistor to VCC. So if nothing is occurred the voltage on the bus is equal to VCC.

Request:

To make the DHT-11 to send you the sensor readings you have to send it a request. The request is, to pull down the bus for more than 18ms in order to give DHT time to understand it and then pull it up for 40uS.

Response:

What comes after the request is the DHT-11 response. This is an automatic reply from DHT which indicates that DHT received your request. The response is ~54uS low and 80uS high.

Data:

What will come after the response is the sensor data. The data will be packed in a packet of 5 segments of 8-bits each. Totally 5×8 =40bits.

First two segments are Humidity read, integral & decimal. Following two are Temperature read in Celsius, integral & decimal and the last segment is the Check Sum which is the sum of the 4 first segments. If Check Sum's value isn't the same as the sum of the first 4 segments that means that data received isn't correct.

How to Identify Bits:

Each bit sent is a follow of ~54uS Low in the bus and ~24uS to 70uS High depending on the value of the bit.

Bit '0' : ~54uS Low and ~24uS High

Bit '1' : ~54uS Low and ~70uS High

End Of Frame:

At the end of packet DHT sends a ~54uS Low level, pulls the bus to High and goes to sleep mode.

 

Logic Analyzer Snapshots

In the following image you can see the request sent from the MCU to the DHT and following the packet. Because the request has very long duration as you can see is about 20mS and packet received is in uS we can't view the data bits.

If we zoom at the data bits we can read the values. You can see after the Request follows the Response, and Data bits. I have drawn some color notes to be more understandable.

If we decode the above data we have.

Humidity 0b00101011.0b00000000 = 43.0%

Temperature 0b00010111 = 23 C.

The last two segments can't be seen in this image because of zoom.

 

Implementation:

What we have to do to read a DHT-11 sensor is:

  1. Send request
  2. Read response
  3. Read each data segment and save it to a buffer
  4. Sum the segments and check if the result is the same as CheckSum

If the CheckSum is correct, the values are correct so we can use them. If CheckSum is wrong we discard the packet.

To read the data bits can use a counter and start count uSeconds of High level. For counts > 24uS we replace with bit '1'.  For counts <=24 we replace with bit'0'

 

Here you can find some code to read DHT-11 using an Atmega8 at 16Mhz

DOWNLOAD HERE

Related Posts

11 thoughts on “DHT-11 & One wire bus

  1. Thanks! This is extremely helpful! I just wanted to point out that you kept calling the integer bytes "integral". I was finding that to be quite confusing, and was initially wondering how the output from the sensor related to calculus! 😛 Thanks again my friend.

  2. hi, i wanna ask, how does the program will be if im using 89c51? i think it will uses keil c language. i use 11.0592 Mhz xtal. what should i do or modify in the program, to make it works for my device.

  3. hi i wanna ask with u,, how the formula to calculate the temperature and humidity sensors are processed?
    is equal to

          f = e / es * 100

     

    i'm confused

  4. great tutorial sir! i'm working on DHT11 now and i have a problems to get the signal on oscilloscope, how did you get those signal ? pardon my english. thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *