Go Down

Topic: Class for DHT11, DHT21 and DHT22 (temperature & humidity) (Read 62 times) previous topic - next topic

robtillaart

Apr 14, 2011, 11:21 pm Last Edit: Oct 13, 2014, 12:00 pm by robtillaart Reason: 1
Last week I posted a DHT class on the playground - http://arduino.cc/playground/Main/DHTLib - that supports both DHT11 and DHT22 sensors.

Although the protocol / handshake is the same for both sensors the dataformats used differ unfortunately.  The DHT22 has a wider range and higher resolution. The class is rewritten completely from scratch but inspired by earlier work of George Hadjikyriacou (see also - http://arduino.cc/playground/Main/DHT11Lib ) . The class has two read functions called read11(PIN) and read22(PIN) to read the different sensors. This way one instance of the class can serve multiple, and even mixed sensors. The code of the lib is straightforward and can be stripped if one only has DHT11 or only DHT22's.

As always, comments and remarks are welcome.


update 2013-08-26: support for DHT21


update 2014-06-01: improved timing  -> 0.1.10 version


update 2014-06-26: DHT33/44 support  -> 0.1.13 version

latest version - https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib -  

Note: attached 0.1.13 version is (for now) latest that is compatible with pre 1.0 Arduino.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Graynomad

I have no immediate need to use these sensors but can certainly see some in my future so this will be very useful.

I may have to strip it down to the basics for a tiny85 if that's possible (I'll look at the code when the time comes).

Thanks.

______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

GaryP

Postman just dropped a notification, my order is waiting at the post office., My DHT11 will be tested this weekend.
Finally, I almost forget that it was on its way...

Cheers,
Kari
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

GaryP

#3
Apr 15, 2011, 10:12 pm Last Edit: Apr 16, 2011, 10:05 am by GaryP Reason: 1
OK!

Get the package from post office, and just for curiosity ( http://arduino.cc/forum/index.php/topic,58585.0.html ) I had to check this component.
And it has four pins, no marking for nro 1 or any other.

Datasheet is not helping either, it shows similar component, and I have a problem with reading through all that text, how to identify pin nro 1.
Any tips? Thanks!

Cheers,
Kari

EDIT. Find it! And it works. I'm in a hurry until tomorrow, so I just tested it with the first code found...
The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

simkard

Hi,

This is the good pinout for DHTxx components (which is strangely not written in the datasheet ...)



See ya !

Go Up