DHT22 Temperature and Humidity Sensor
A DHT22 sensor (Temp and Humidity) |
There is no much to say about the pinout. It has been kept same pinout pattern to all of these sensors which is awesome !!!.
Later on we will see that besides the same pinout they also use the same communication technique, which is amazing, especially when you want to do
an upgrade to your project without changing anything to your pcb.
It has 4 pins as it is shown below (fig2) , where 2 of them are used for power supply , 1 of it for the communication, and the remaining is left open.
As you can see from below, DHT11 is slightly smaller in compasison the other two, but the pins have exactly the same spacing and functionallity.
|
Power supply pin. It can handle voltages from 3.3 to 6VDC |
||
Data communication pin. (Input/Output) Requires a pull up resistor of 4.7K | ||
Not connected.(Float) | ||
Ground pin. | ||
These sensors are constisted of two different sub-sensors, one for meausing temperature and one for measuring humidity.
The temperature measument is made by a high-precision NTC thermistor, which changes it's resistance according temperature.
There are two types of thermistors NTC and PTC.
NTC stands for “Negative Temperature Coefficient”,
which means that it's resistance decreases with an increase of the temperature.
PTC does the opposite, it increases it's resistance, with an increase of the temperature. “Positive Temperature Coefficient”.
As for the humidity it uses a capacitive wet sensor, usually it consists of two electrodes and between them a
conductive plastic polymer, whereas it increases it's resistance propotional to the relative humidity.
Higher relative humidity decreases the resistance, and lower relative humidity increases the resistance.
At this point we should mention that each sensor is calibrated in a very accurate humidity and temperature calibration room,
and the calibration coefficients are stored in the form of a program in the microcontroller.
So during a read, these calibration coefficients are called within the sensor, the internal microcontroller process the data
and sends you the final accurate measurement at data pin. (Awesome because in some other sensors i do it manually)
Below are both sensors disassembled...
|
By first sight, you can notice a pretty obvious difference which is the size. But is this the only difference that these modules have?
|
On the left side there are the characteristics of each module taken by their datasheet.
It is pretty obvious that DHT22 has more accurate measuments at temperature and humidity than DHT11, and a
wider temperature operating range.
As for the drawbacks, DHT22 is a little bit bigger than DHT11, and it has slower sample rate in comparison DHT11, which is 0.5Hz (every two seconds) for DHT22 and 1Hz (every second) for DHT11.
Also one big advantage for buying a DHT11 sensor is it's cost, which is 1/3 of DHT22.
But honestly i would prefer DHT22 just because it's accuracy.
Below i have re-created the communication data timing diagram and added some color, so to be more easier for our eyes.
|
Above is the communication timing diagram. Timing is CRUSIAL.
The communication looks similar to ONE-WIRE from maxim intergated, but it is not. ( I will speak of it, in a following tutorial, on DS18B20 sensor.)
So lets analyze what we have to do, to speak to a DHT sensor.
When the bus is idle, it is in high state condition. This is because of the pull up resistor. (Look at typical connection below.)
Step 1. MCU must pull low the bus for at least 18mSec and after that to release the bus. (I use 20mSec)
Step 2. DHT will respond within 40uSec by pulling the bus low for 80uSec and then pull it high for another 80uSec. (Something like.. get,set,go)
Step 3. DHT will start transmitting each bit, by sending a pulse duration of 50-54uS low with 24-26uS high for '0' and 50-54uS low with 70-71uS high for '1'
Step 4. When all 40 bits are sent, DHT releases the bus (idle state) and enters sleep mode. (Low power consumption ~20uA)
|
When DHT will start transmitting data, it will send a packet of 40 bits (5 bytes in total) and always MSB first.
It starts sending the humidity (high-low bytes) continues with the temperature (high-low bytes) and the finally sends the parity byte, where this byte
is the sum of the four. This is really handy, because checking the parity byte you ensure that your reception was correct and it wasn't corrupted.
For DHT11 sensor the low bytes of humidity and temperature are always zero. Also remember that the received bytes are in BCD Format
Below is an example of how the data is decoded.