March 1, 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.
Here’s my source code, to get you started right away:
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.
2011/04/14: asmika uploaded a custom variant with the following changes:
“I have rewritten the code a bit, so it can be used with ds18s20 (therm_18bs20.c. Small changes / fixed passing of LCD.H as they pass my test print. even small changes in the code change the display. ”
Can be obtained from here: tempi
October 7, 2012
The code has been updated to correctly parse the sensor’s data. See the new article here. The code from 2009, above, is obsolete, do not use!