DHT22 Shows wrong values... how do I address this?

I recently debugged a similar issue with DHT22 sensor. I found the following details that was not obvious from the data sheet:

DataSheet: https://www.sparkfun.com/datasheets/Sensors/Temperature/DHT22.pdf
1. Extra pulse before start:

After MCU start signal the DHT22 responds like this:

_

    21      75      26      26      26      71       66
    __      __      __      __      __      __      __
   /  \    /  \    /  \    /  \    /  \    /  \    /  \  . . . 
__/    \__/    \__/    \__/    \__/    \__/    \__/    \ . . .

17      71      30      40      40      40      40

There is an extra ~20us low and high signal before the real start of 70us down and 70us up.

Rest of the 0/1 pulse width is correct. After a 40us low, a high of ~30us is 0 and ~70us is 1.

The first issue was that the pre pulse of 20us down and up was not accounted correctly. So the actual start pulse was
detected as 1 and error out because we will count the bits one off and not read the last bit to match the checksum.

2. Values are 16-bit int and not 8-bit parts of integral and decimal respectively:

Second issue that was not obvious from the data sheet was that the response is actually a 16-bit integer in hex and not two 8-bit parts.

Example:

40 bit response sequence from DHT 22 sensor

00000010 01101011 00000001 00011111 10001101
      02       6B       01       1F       8D

Humidity = 0x026B  Temperature = 0x011F Checksum = 0x8D
Checksum = 0x02 + 0x6B + 0x01 + 0x1F = 0x8D (ok)

Humidity in 16-bit hex is 0x026b, decimal 619 which is 61.9%
Temperature in 16-bit hex is 0x011F, decimal 287 which is 28.7 C

With the above understanding the sensor works as expected and provides pretty accurate values for temperature and humidity.

My experiment involves coding for these sensors from scratch for PIC micro-controller in C and using sdcc compiler. Hence I have not used any existing libraries. However I do benefit from the arduino library code and forums for my education. Thanks to all forum contributors.

1 Like