PocketMagic

PocketMagic

Where Technology meets magic

PocketMagic RSS Feed
 

ATMega8 and DS18B20 (digital temperature sensor)

By Radu Motisan Posted on March 1st, 2009

"The DS18B20 Digital Thermometer provides 9 to 12–bit centigrade temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and gound) for communication with a central microprocessor. It has an operating temperature range of –55°C to +125°C and is accurate to +-0.5°C over the range of –10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply." Read more about this sensor, here.

Since I had two DS18B20 sitting among my other electronic components, I've decided to hook one up to my ATMega8 test board and see if I manage to get some temperature readings. One wire to a microcontroller's pin, and two other wires for 5V power.

Now we're ready to go... well not quite, this is a digital sensor and first we need to understand the way it communicates.

I've also found some good resources online here. If the link doesn't work for you, see the attached PDF.

Here's my source code, to get you started right away:
atmega8_lcd_temp.zip

UPDATE 2009/11/27: Changed delay function in therm_ds18b20.c .Download here.

Bottom line, this sensor offer some impressive results, and works very well. It is a good addition to any microcontroller board for gathering some extra environment parameters, and all at the expense of a single PIN on the microchip.

Radu Motisan

By Radu Motisan

46 Responses to “ATMega8 and DS18B20 (digital temperature sensor)”

  1. 1
    Carlos:

    Hi friend y need your help, the connections of lcd does not work, i was built all the hole circuit and it does not work, what function has the PORTB |= 1, this pin in your circuit diagram does not have connection, y simulate the circtuit with proteus 7.5, help me please, i from mexico, thaks a lot fried, e-mail me please withe the hole funtional circuit, thanks.

  2. 2
    Carlos:

    Hi again my e-mail is carlos_lopez753@hotmail.com, give your e-mail and talk about this circuit, thanks

  3. 3
    Radu Motisan:

    hola Carlos,

    are you trying to connect the LCD to the Micro controller or do you also need the temperature sensor?

    What microcontroller are you using and what LCD?

    You can also check http://www.pocketmagic.net/?p=447

    adiós!

  4. 4
    Carlos:

    Hi Radu i’m again, i use the same MCU Atmega 8 and LCD is HD44780 is the same like yours, i make all the circuit with proteus, and it does not work, can you speak spanish? i’m not write and speak english very well, can you give me your e-mail, for give you the diagram, i tried 4 times for make the circuit and not display nothing, it work but does not display the temperature, help me please, can you give the right circuit diagram, o can you tell me what can i do for resolve the problem, thanks my friend my e-mail is carlos_lopez753@hotmail.com,

    Take Care Radu see you.

  5. 5
    Adrian Banks:

    Hi there,
    I’m in the process of building a multi function temperature display using an Atmega 128 board and a TFT display from http://www.shop-en.display3000.com/index.html. Do you know how to wire in two DS18B20 chips into the above board?
    Any help would be greatefully appreciated
    Kind regards
    Adrian

  6. 6
    Ahmet Nas:

    Hi.
    I made all the circuit with proteus but it didn’t work. I think i have same problem with Carlos. I need to know how to repair this circuit. Can you make contact with me.
    My mail
    ahmetnas@gmail.com

    Thank You

  7. 7
    Radu Motisan:

    Carlos & Ahmet, my email address is radu.motisan@gmail.com

    Send me your circuit diagrams, and I’ll see what I can do.

  8. 8
    Radu Motisan:

    Adrian, simply choose two input pins on the atmega128 and connect two separate sensors.

  9. 9
    Piotr:

    At the beginning you must add 4k7 Ohm resistor between the DQ and VDD.

  10. 10
    Adrian Banks:

    Didn’t realise it was that simple :)
    Thank you Radu.

  11. 11
    asansör kiralama:

    I admire to your writing

  12. 12
    seek:

    need some help with the display.
    the above circuit does not work for me

  13. 13
    seek:

    the display does not show anything, even the dimmer does not work
    any suggestion?

  14. 14
    Radu Motisan:

    Hi seek,

    See http://www.pocketmagic.net/?p=447 for more details on the LCD usage.

  15. 15
    seek:

    Hi Radu,
    After displaychange i get some result on the lcd.
    But it always shows T=+127.9375 C

    Thanks for fast response!
    Greets
    seek

  16. 16
    Radu Motisan:

    Ok, that problem is caused by the delay function inside therm_ds18b20.c

    I’ve updated the source code, see:
    http://www.pocketmagic.net/wp-content/uploads/2009/03/therm.ZIP

  17. 17
    seek:

    Thanks Radu!
    Can you please provide a updated .hex including your latest changes, please?

    regards
    seek

  18. 18
    Radu Motisan:

    Unfortunately I don’t have the compiler on this computer, but I should be able to do it tomorrow.

    What microcontroller are you using?

  19. 19
    seek:

    I do use the Atmega8 linke you.
    Same problem here, no compiler available.
    Thanks for your fast response the solving the problem.
    I’ll check again by tomorrw.

    Regards
    seek

  20. 20
    seek:

    I tried to compile it myself using winAVR, but i’m getting an error like “interrupt …”
    Therefore I’ll wait until you provide the .hex file with your actual changes.
    regards
    seek

  21. 21
    seek:

    error code interrupt/exception caught (code = 0xc00000fd, addr = 0×4217b3)

  22. 22
    seek:

    Hi Radu,
    I’d love to continue my studies, but doing so means I need the newly build .hex file.
    ö) seek

  23. 23
    seek:

    any news yet?

  24. 24
    seek:

    hopefully you’re ok radu, maybe on holiday?

  25. 25
    seek:

    still no working version…
    a bit disapointed

  26. 26
    Radu Motisan:

    Hi seek, sorry for the late reply: I didn’t have the chance to re-compile the hex yet. Please provide more details on the error messages you’re getting, so I can try to assist you in fixing those.

  27. 27
    seek:

    well radu, was mentioned before, you can’t compile the set you provided weather the original one, nore the one with the new files you uploaded.
    this is the error code: error code interrupt/exception caught (code = 0xc00000fd, addr = 0×4217b3)

    you should be able to set up a new .hex aren’t you?

  28. 28
    Radu Motisan:

    Well simple tasks become complicated when you work 14 hours per day, but I’ll do my best.

    Radu

  29. 29
    seek:

    i’m confident you’ll do this perfectly, radu
    hm, maybe the spam checking system should be overhauled ,-)

  30. 30
    seek:

    Hi Radu!

    Any news on the new Version yet?

  31. 31
    seek:

    Well, after one and a half month of no further updates it seems like the project is dead, if it wasn’t that before at all.
    someone could say disapointing, i’ll say: you ever learn….

  32. 32
    len:

    sir i made the connections as it is but still my lcd is not working.please do the needfull help

  33. 33
    len:

    sir iam doing 1 wire temperature sensor project, i made the connections but still my lcd is not working.please help me.

  34. 34
    Radu Motisan:

    Len, do you have a reset button too? Is the LCD working after you press the RESET button?

    I am planning to update the LCD code, but didn’t have the time for it yet.

  35. 35
    len:

    sir i dont have reset button,i’ll make the changes.please can you send me the code to my email id in a single zip folder i am confused with many files over here which one to use .please sir

  36. 36
    len:

    sir i am using 16*2 lcd – LM016L lcd please do the needful help,i am using proteus 7.1version i dont find any reset button in it.I have already sent u my circuit diagram please suggest me any changes required.please send me the code to my gmail id .

  37. 37
    len:

    sir i got stuck up with my lcd display. please help me

  38. 38
    Radu Motisan:

    Len, the problem is that my code is for the HD44780 LCD. I don’t have any LM016L arround.

  39. 39
    len:

    sir can u please mail me the complete modified code of the project for hd44780 lcd,i’ll try to change the lcd and test the project.

  40. 40
    len:

    sir i am trying to simulate the project using proteus but i am not getting anything on the display please help me.

  41. 41
    len:

    sir can i use any 2*16 lcd using this code,is this possible.

  42. 42
    Radu Motisan:

    Hi len, this code is for the hd44780 LCD display only.

  43. 43
    len:

    sir do you have the proteus simulation file,can u please post it sir.

  44. 44
    len:

    sir how could i simulate the code it is by avr studio or any other software.

  45. 45
    len:

    please post the proteus simulation file.

  46. 46
    ravish shetty:

    Radu, nice job. can you provide me the same for lpc2131 ARM processor?
    really needed help bcoz have a project to be submitted by coming Wednesday.
    if not on ARM processor can you provide me with the same for atmega 8?
    please reply as i have to get ready by monday!

Leave a Reply

Please copy the string I5J7qQ to the field below:

Blog options

Translator

English flagFrench flagGerman flagItalian flagPortuguese flagRussian flagSpanish flag
By N2H

Categories

Archives

Tags

Sponsored Links

Subscribe!

Get more followers

Our Sponsors