Project SummaryNumerous studies have shown that the indoor temperature and relative humidity at workplace significantly impacts workers' comfort and productivity. The first step towards optimizing these two ambient parameters is their reliable measurement. This project describes an inexpensive technique of using the DHT11 sensor for measuring temperature and relative humidity in parallel. It uses the PIC16F628A microcontroller to read the sensor output and display the results on a 16x2 character LCD.
Project DescriptionDHT11 is the most inexpensive sensor currently available in the market that provides calibrated digital outputs for temperature and relative humidity. It is available in a single row 4-pin package and operates from 3.5 to 5.5V power supply. It can measure temperature from 0-50 °C with an accuracy of ±2°C and relative humidity ranging from 20-95% with an accuracy of ±5%, thus making it suitable for indoor applications. The sensor has got its own proprietary 1-wire protocol to communicate with a host microcontroller.
The following timing diagram describes the protocol involved in the communication between a MCU and the DHT11 sensor.
The MCU initiates data transmission by issuing a “Start” signal. The MCU first pulls the data line low for at least 18 ms and then pulls it high for next 20-40 μs. When the line is released by the MCU the sensor responds to the “Start“ signal by pulling the line low for 80 μs followed by a logic high signal that also lasts for 80 μs. Remember that the MCU pin must be configured to input after finishing the “Start“ signal. Once detecting the response signal from the sensor, the MCU is ready to receive data from the sensor. The sensor then sends 5 bytes of data continuously in the data line with the most significant bit first for each byte. The 5 bytes of data consists of,
Data = Integer Byte of RH + Decimal Byte of RH + Integer Byte of Temp. + Decimal Byte of Temp. + Checksum Byte
For DHT11 sensor, the decimal bytes of temperature and humidity measurements are always zero. Therefore, the first and third bytes of received data actually give the numeric values of the measured relative humidity (%) and temperature (°C). The last byte is the checksum byte which is used to make sure that the data transfer has happened without any error. If all the five bytes are transferred successfully then the checksum byte must be equal to the last 8 bits of the sum of the first four bytes, i.e.,
Checksum = Last 8 bits of (Integer Byte of RH + Decimal Byte of RH + Integer Byte of Temp. + Decimal Byte of Temp.)
Now lets talk about the signal conditions used by DHT11 for transmitting data. In order to send a bit of data, the sensor first pulls the line low for 50 μs and then raises it to high for 26-28 μs (for sending “0″), or for 70 μs (for sending “1”). So the width of the positive pulse carries information about 1 and 0.
At the end of the last transmitted bit, the sensor pulls the data line low for 50 μs and then releases it. It is now ready to receive another start signal from the MCU.