The DHT11 is a basic, low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).
This library use DHT11 sensor to read temperature and humidity on on Atmega micro.
Setup the data port connected to the micro pin, and call the function to get humidity and / or temperature.
DHT11
- Power supply 3.5-5.5V DC
- Measuring range Humidity: 20-90%RH
- Measuring range Temperature: 0-50 Celsius.
Setup parameter are stored in file dht11.h
Code
Notes
- read risk disclaimer
- excuse my bad english
Thank you for the code!
ReplyDeleteIt's usefull.
For others: Look for the newest version.
Now it's avr_lib_dht_03.zip
the code can not work for me ...
ReplyDeleteto me this code works on most ATmega family. if it does not works, double check wiring, check that your DHT11 works with other devices and libraries (like arduino), then use some kind of debugging tecnique (like uart output), to check where the code stucks.
Deletegood work.
Salam,
ReplyDeleteI am using DHT11 with atmega 16 on 3.3v supply. The microcontroller gives control signal between (3.3V and 0V i.e correct) But dht11 responds by giving signals between 3.3V (high value) and 1.5V(low value). Any idea why this might happening?
Thank u in advance for ur help!
It could be your power suppy, try to supply all your devices at 5V.
DeleteDHT11 datasheet, Electrical Characteristics: Power supply: DC 3.5~5.5V.
Thanks for the quick response.
ReplyDeleteI tried doing as u suggested. Now i run everything on 5 V but the problem has persisted.
Now the dht11 responds between 5.0 (high) and 3.2V (low).
Any other ideas ?
you should check using a scope the response and compare your DHT11 to atmega communication line with the on contained in the datasheet.
Deletea simpler method should be use the uart to debug the code, to check where it stucks.
Hi,
ReplyDeleteI test this code with atmega128 but I always have checksum error. Do you have any Idea what is wrong?
thanks in advance
Hello.
DeleteAre you using avrgcc? Have you check your wiring? What kind of checksum error do you mean?
yes, my wiring seems right. exactly in this line of code:
Deleteif ((uint8_t)(bits[0] + bits[1] + bits[2] + bits[3]) == bits[4])
my program return always -1.
and it is my output example:
output example:
1st 8 bit, 2nd 8 bit, 3rd 8 bit, 4th 8 bit, checksum 8 bit
27 109 128 6 198
27 108 0 27 24
I think I write in a wrong page. I am using this library:
Deletehttp://davidegironi.blogspot.de/2013/02/reading-temperature-and-humidity-on-avr.html#.Vm7L_dIrJpg
Can you check the bus lines with a scope or a logic analyzer?
DeleteMay vladan vesý October 3, 2015 comment of the post you have linked help?
I dont have the tools but I checked it with reading the signal with input capture. I think i recieve 38 pulse and the pulses should be more than 40 .
Deletehas it any meaning?
here is example of dh11 header and inputcapture:
Deletebits[0]= 21(00010101) ic= 00011111
bits[1]= 80(01010000) ic= 00000000
bits[2]= 0 (00000000) ic = 00011001
bits[3]= 162(10100010) ic= 0000000-
bits[4] = 0 ic= -
You have to measure the pulse time, which must fit the datasheet timing table.
Deletethanks for the time you gave to me.
DeleteI exactly did that. I wrote here the result.
0=20clk =50+27 micro second(almost...)
What pulse are you speaking of? If you take as example the Aosong DHT11 datasheet, the first Host signal must have a length of almost 18ms (milliseconds).
Deleteyes I have that. I write the example pulse queue I recieved. I have 250000 clk per second.and these are clk between each 2 raising edge:
Delete2-29503-(handshaking)24-35-(40 bit data)19-20-31-19-20-19-20-19-19-20-19-20-19-20-19-20-19-20-19-31-31-20-19-20-19-19-20-19-20-19-20-19-20-19-31-19
I think all should be more than 40 but they are 39.
I send the 18 ms signal with dht11/12 header version 3 you wrote.
Deleteand recieve the information both by inputcapture and this header.
the give back diffreent result and any way I have checksum error.
Most of the time the DHT sensor comunication errors comes to incorrect signal timing. But if you have checked that the bus fits the datasheet, it could be your sensor. Check it with another micro, or even check it with another library.
DeleteIt happens to me to get checksum error sometimes, but it was due to emf noise.
Hey Davide !! I am also getting -1 for both the values !! Please Help !! I dont have pulse n all Knowledge...!!
DeleteHello. Can you check the bus lines with a scope or a logic analyzer?
DeleteThis comment has been removed by the author.
ReplyDeletemy code stucks on while loop after storing the result...please help
ReplyDeleteHello, see my comment below.
Deletewhat do you think the problem is ???
ReplyDeleteHello. Double check your wiring. Check you F_CPU. Check your ATmega fuses. Check if the sensor is working using other hardware.
DeleteCan you explain me please.. I am using DHT11 with atmega16, which file I have to use from your uploads?
ReplyDeleteHello, you can use the avr_lib_dht_02.
DeleteHi Davide, I was wondering if your library would work on Atmega1284?
ReplyDeleteThank you!
Sorry I didn't give a reason. I'm working on my final project for a class of mine in college. And I want to try to get the DHT11 to communicate with my Atmega1284 in order to create an Automated Windows/Shutter Opener/Closer
DeleteThank you again!
Hello, It should work. I've compiled it for ATmega1284P, it compiles except for the uart library, i suggest you to check the new P.Fleury library or find a ATmega1284 working one. Unluckly I've not any ATmega1284 to try it on. If i doesn't work double check your F_CPU. Let us know how it goes. Good work.
DeleteHi Davide, thank you for the response. It doesn't seem to work for my Atmega1284. I tried including P.Fleury library for UART too. It doesn't seem to work still. Do you have any other suggestion? Thank you
DeleteActually it does work, but I get a warning for my F_CPU. Do you happen to know what to do for this?
DeleteHere is an attach picture to let you know what I mean.
http://i.imgur.com/r6iY1TB.png
Also when I get it working, how would I know that it is working correctly without having to display it on an LCD screen? I want to check if it is working like on a serial monitor just to test it out. Thank you
F_CPU, have you defined it in your compiler? What do you use as compiler and IDE? Take a look here: http://www.avrfreaks.net/forum/fcpu-0
DeleteFor the serial monitor you could use the uart output, something like the P.Fleury uart library should do the work.
Hey Davide, thank you for the help I have another question now.
DeleteHow do you display the temperature and humidity on an LCD Screen?
http://i.imgur.com/Xn9h08U.png
I am also using Atmel Stuido as my IDE.
I wanted to know how I can display the output on an LCD Screen. Thank you.
Hello, you can use the P.Fleury LCD library, you can find it here http://homepage.hispeed.ch/peterfleury/avr-software.html. Then you can simply use lcd_puts instead of uart_puts. Note that the uart library you are using there is from P.Fleury too. He's a "cool kid!" :)
DeleteHey david I'm using an Atmega 328P and your library but it seems as if the value for temperatures and Humidity never get updated. And I seem to stay in the while loop forever. Any idea why this would happen? Thanks again.
ReplyDeleteHello, have you check the updated version of this library?
DeleteApologies, I didnt mention it in my comment. Yeah I'm using dht 03 your updated version and I'm using a DHT 11 with 3 pins(Like here http://imgur.com/9BQAi0y). Any ideas? Thanks again.
DeleteThis comment has been removed by the author.
ReplyDeleteHey David
ReplyDeleteI am working on Atmega16 and using an LCD to show the data. But while compiling using Atmel STudio 7.0 there is always an error of "dht/dht.h" not found.
I also tried to remove the header file and copied the entire thing to main.c
However now I am getting un referenced error on dht.gettemperatureandhumidity code...
Can you help me please..
Hello, you have to add the dht to your liker. Eclipse just do it when you add it to the project. Try it.
DeleteThis comment has been removed by a blog administrator.
ReplyDelete