NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Microcontroller Programming » Example Code for Humidity & Temperature Sensor - DHT11 / DHT22
April 06, 2012 by dtolan ![]() |
Hello, Has anyone written up the code (Nerdkit compatible "C") to read the output from the DHT11/DHT22 sensor - It is a inexpensive Humidity & Temperature sensor - Here is the datasheet - http://www.adafruit.com/datasheets/DHT22.pdf Please excuse the vendor - I did not see a humidity sensor available from Nerdkits - or I would have picked it up here |
---|---|
April 07, 2012 by pcbolt ![]() |
@ dtolan - I don't remember seeing anything on these forums about that particular model. It uses a Variable Pulse Width protocol (proprietary?) to communicate with the MCU. Nice thing is it is a single wire bus line and aside from a start trigger, the communication is one way. It is not as simple as other more established protocols so you will need to do some interesting programming to make things work. You will definitely need to implement timer and pin change interrupts, but if you break everything down into manageable subroutines, it should work fine. There are 3 Nerdkit tutorials you should go through if you are not familiar with interrupt programming... "Real Time Clock", "Keyboard" and "ODB II". If you are up for the challenge...keep posting here I'm sure you can get assistance. |
April 07, 2012 by esoderberg ![]() |
dtolan, These functions might help. I used them to measure the pulse width for a two axis accelerometer, but they should give you a start for any pulse width measurement. The functions below allow for pulse width measurement on two pins, PC4 and PC5. First to set up the interrupts:
And then the interrupt that is now called whenever PC4 or PC5 changes:
|
April 07, 2012 by dtolan ![]() |
Thank you for the feedback , I was thinking that measuring the pulse width was the way to go, and the examples provided should help out a lot. Thanks again Dan |
May 10, 2012 by reddog30jen ![]() |
I would really love to see someone post code for this sensor as well. I purchased the DHT11 to add into my weather station I am making for a school project.(In/Out Temp+Humidity+barometric pressure+wind speed) After realizing that the coding for it would be rather difficult I decided to go with analog sensors. I would still like to see the type of code required to get the data from this digital sensor. I am trying a variation of esoderberg's code above to read pulse width from wind sensor from Inspeed which is basically a reed switch but havn't tried it yet, also not sure if it will work. Any input anyone?? |
Please log in to post a reply.
Did you know that you can build an analog amplifier with one transistor and a few resistors? Learn more...
|