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











June 1st, 2009 at 5:43 pm
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.
June 1st, 2009 at 7:25 pm
Hi again my e-mail is carlos_lopez753@hotmail.com, give your e-mail and talk about this circuit, thanks
June 1st, 2009 at 7:59 pm
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!
June 2nd, 2009 at 9:03 am
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.
July 24th, 2009 at 1:39 pm
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
September 29th, 2009 at 8:17 am
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
September 29th, 2009 at 7:28 pm
Carlos & Ahmet, my email address is radu.motisan@gmail.com
Send me your circuit diagrams, and I’ll see what I can do.
September 29th, 2009 at 7:30 pm
Adrian, simply choose two input pins on the atmega128 and connect two separate sensors.
October 17th, 2009 at 6:38 am
At the beginning you must add 4k7 Ohm resistor between the DQ and VDD.
October 21st, 2009 at 3:13 pm
Didn’t realise it was that simple
Thank you Radu.
October 22nd, 2009 at 3:33 pm
I admire to your writing
November 24th, 2009 at 8:52 pm
need some help with the display.
the above circuit does not work for me
November 24th, 2009 at 8:53 pm
the display does not show anything, even the dimmer does not work
any suggestion?
November 24th, 2009 at 8:55 pm
Hi seek,
See http://www.pocketmagic.net/?p=447 for more details on the LCD usage.
November 27th, 2009 at 9:58 pm
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
November 27th, 2009 at 10:12 pm
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
November 27th, 2009 at 10:18 pm
Thanks Radu!
Can you please provide a updated .hex including your latest changes, please?
regards
seek
November 27th, 2009 at 10:20 pm
Unfortunately I don’t have the compiler on this computer, but I should be able to do it tomorrow.
What microcontroller are you using?
November 27th, 2009 at 10:24 pm
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
November 29th, 2009 at 5:03 pm
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
November 29th, 2009 at 8:30 pm
error code interrupt/exception caught (code = 0xc00000fd, addr = 0×4217b3)
November 30th, 2009 at 10:04 pm
Hi Radu,
I’d love to continue my studies, but doing so means I need the newly build .hex file.
ö) seek
December 2nd, 2009 at 10:16 pm
any news yet?
December 4th, 2009 at 7:33 am
hopefully you’re ok radu, maybe on holiday?
December 9th, 2009 at 7:56 pm
still no working version…
a bit disapointed
December 9th, 2009 at 9:05 pm
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.
December 10th, 2009 at 7:33 am
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?
December 10th, 2009 at 2:04 pm
Well simple tasks become complicated when you work 14 hours per day, but I’ll do my best.
Radu
December 10th, 2009 at 8:24 pm
i’m confident you’ll do this perfectly, radu
hm, maybe the spam checking system should be overhauled ,-)
December 20th, 2009 at 5:58 pm
Hi Radu!
Any news on the new Version yet?
January 4th, 2010 at 5:49 pm
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….
February 21st, 2010 at 10:33 am
sir i made the connections as it is but still my lcd is not working.please do the needfull help
February 21st, 2010 at 10:35 am
sir iam doing 1 wire temperature sensor project, i made the connections but still my lcd is not working.please help me.
February 22nd, 2010 at 9:36 pm
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.
February 23rd, 2010 at 5:24 am
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
February 23rd, 2010 at 4:02 pm
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 .
February 25th, 2010 at 12:42 pm
sir i got stuck up with my lcd display. please help me
February 25th, 2010 at 12:59 pm
Len, the problem is that my code is for the HD44780 LCD. I don’t have any LM016L arround.
February 25th, 2010 at 2:48 pm
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.
March 7th, 2010 at 4:30 pm
sir i am trying to simulate the project using proteus but i am not getting anything on the display please help me.
March 7th, 2010 at 4:31 pm
sir can i use any 2*16 lcd using this code,is this possible.
March 8th, 2010 at 12:16 pm
Hi len, this code is for the hd44780 LCD display only.
March 8th, 2010 at 6:50 pm
sir do you have the proteus simulation file,can u please post it sir.
March 8th, 2010 at 6:51 pm
sir how could i simulate the code it is by avr studio or any other software.
March 8th, 2010 at 6:55 pm
please post the proteus simulation file.
April 21st, 2010 at 9:18 am
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!