DS18B20: Weird Readings


New Member
Hi guys,

I am relativley new to PIC AXE system and have found learning basic a bit of a challenge, since i am used to programing in C and Assembler.

I am working on a project currently that is using the DS18B20 digital temprature sensor with the PIC AXE 18X. and trying to use the sensor as a kind of thermostat ie trigger some outputs when the temprature reaches a certain temprature, say 40 Degrees Celcius.
With a ambient temprature of around 25 degrees.

and am using the following code and the 3 wire connection set up shown on the DS18B20 datasheet(http://www.maxim-ic.com/quick_view2.cfm?qv_pk=2812) for a single DS18B20 connected to input pin 0 of the PIC AXE 18X on a cable length of aprox 2m(computer ribbion data cable) at this length i would not of expected any significant effect from capacitance betwen the cables or voltage drop from cable resistance.

readtemp12 0, b1
pause 750
From reading the the second part of the manual, the DS18B20 data sheet, and some forum posts I thought that the value returned by DS18B20 would be near 25 degrees when the ambient temprature was close to this (no heat source in contact with the sensor). However after using the "debug" command i discovered the sensor was returing a value of 80 instead of 25.

I am puzzled as to what could cause such a large difference for a sensor that is suposed to reflect the temprature it is in contact with almost the same value ie if the temprature of a piece of pipe connected to the sensor was 50 degrees the DS18B20 should return close to 50 degrees.

Am I missing something, does the DS18B20 need to be initalised so that it gives 25 degrees when it is in an environment of 25 degrees?

Is there any way to correct the difference in actual temp and measured temp?

Any thoughts or possible solutions would be greatly appreciated.

Thanks in Advance,



If you use readtemp it will give the correct temperature.
If you use readtemp you need to divide by 1.6, hence 80 /1.6 = 50. In Picaxe maths use 80*10/16
readtemp12 0, b1
b1 = b1 *10 /16
pause 750

or just
readtemp 0,b1
pause 750


Michael 2727

Senior Member
Readtemp12 is the Hi Res command (12 bit) and needs a W (WORD)
to store the info (0.125 ºC Res ), then has to be split high byte low byte etc.

Plain Readtemp will put the DEG ºC value into the b variable
selected, the splitting is done for you. In 1 DEG ºC resolution.


Actually, ReadTemp12 has a resolution of 0.0625 and needs to be divided by 16 to get degrees C.
The reason you are getting 80 is because you are using a byte (b1) and losing the top byte due to overflow.
At a guess, your temperature (based on a low byte of 80) is 21C.
21 X 16 = 336
336-256=80 (the value you are seeing.)

ReadTemp12 0,w1 will return 336 (at 21C)

ReadTemp 0,b0 will return 21 (at 21C).