Sunday, November 10, 2013

Temperature & umidity sensor (DHT11)




According to LadyAda this is an extremely low-cost temperature and humidity sensor. Bah, for me 6 Euros are not nothing. Probably, other more sophisticated sensors are much more expensive… or they simply robbed me :-( 










From the data sheet I found that the pin out is as follows (from left to right w.r.t. the photo above):



1- Vcc (3.3V to 5.5V)
2- Data signal
3- Not connected (some people advice to connect it to GND)
4- GND



Technical characteristics



Temperature range: 0°C-50°C

Precision: ±1°C (at 25°C) and ±4% RH (at 25°C)

Power consumption: 0.5mA-2.5mA

Power consumption (standby): 100uA-150uA

Sampling rate: 1Hz


Interfacing with Arduino

According to the data sheet it is better to use a pull-up resistor on data signal and a 100nF capacitor between Vcc and GND to filter out spurious signals during the initialization phase.
Here is the wiring schema made using Fritzing. Remark that the sensor in the figure is not DHT11 but DHT22 since there was only this one in the Fritzing parts library (I should speak of this great program in a future post.). However, they have both the same purpose and same pin out. The only differences are size and performances.


This sensor is extremely slow. Indeed, one can get new data once every two seconds. The advantage is that it is very easy to communicate with and it requires almost no external components.

The communication protocol

DHT11 uses a one-wire two-way serial communication protocol. The Master (M) sends a start signal sending low data pin for at least 20uS (uS = microseconds) and then it passes the signal to high for 20-40 uS and wait for the DHT11 response.

The DHT sends an ack signal by passing data pin to low for 80uS. Then, it passes to high for 80uS and prepare sending data.

The data is 40 bits long. The transmission of one bit starts with a start signal consisting in passing the data pin to low for 40uS. Data pin to high means that it is transmitting a bit.
Bits are encoded according to the length of high signal between two start signals.

"1" is 70uS long
"0" is 26-28uS long

Of course these values should be taken with a 10% fuzziness i.e. "0" is anything between 23 and 31 uS and "1" is between 62 and 78 uS.

Data format

bit 0-7   : Humidity integral part (H1)
bit 8-15 : Humidity decimal part (H2)
bit 15-23: Temeprature integral part (T1)
bit 24-31: Temperature decimal part (T2)
bit 32:39: checksum (C)

Checksum is the sum of first four bytes of data message i.e. C = H1 + H2 + T1 + T2.



As a starting point I took the excellent library and test examples given by Ladyada here. However, I would like to start a larger project and write a generic library for sensors. So stay tuned, it will arrive sooner or later.

No comments :

Post a Comment