I bought from FunGizmos few DS18S20 temperature sensors to test for my small robot project and last week they finally got into my hands but only today I had the time to try them out.
To connect the sensors to the Arduino board I choose the parasite mode which derive power directly from the data line ( no need for an external power supply anymore
), below are the pinouts, the electronic scheme and a photo of the circuit (though, really simple as I used a breadboard) :
After a little bit of research of Dallas’s one-wire interface and downloading the onewire library from Arduino.cc I came out with a nice function to detect all the DS18S20 and DS18B20 sensors from a one-wire bus.
Here is the detection and temperature reading code : tutorialpedia.
A sample of their output :
–Search started–
Device is a DS18S20 : 10-1D-30-F9-01-08-00-51
–Search ended–
for the detection code and
Temp = 79.25 F or 26.25 C
Temp = 79.14 F or 26.19 C
Temp = 79.14 F or 26.19 C
Temp = 79.25 F or 26.25 C
for the temperature retrieving code.
Other helpful links :
* onewire.h library
* Dallas DS18S20 official document



Thank you, this is exactly what needed!
The link on tutorialpedia doesn’t appear to work. Is this code posted some place else? Thanks!
Hi Chris,
I fixed the link. It works now
Thanks
Sorin
Thanks!!!
Thank you for the example. I was not getting realistic results however and traced it to the getTemperature routine. I do not know why for sure I was getting wildly high temps from your code as is, but this is how I changed it:
float getTemperature(byte* address){
int tr;
byte data[12];
float temp;
writeTimeToScratchpad(address);
readTimeFromScratchpad(address,data);
//put in temp all the 8 bits of MSB
tr = data[1];
//check for negative temperature
if (data[1] > 0×80){
tr = !tr + 1; //two’s complement adjustment
tr = tr * -1; //flip value negative.
}
temp = tr * 256 + data[0]; //MSB + LSB
temp = temp / 16.0; // think this was cpc, but not sure about reading reserved byte
return temp;
}
Hello dear friends.
Mi problem is that I can’t read temperatures over 52 °C and I put the sensor (ds18b20) very near of a welder!!.
The CRC is good.
When I energize the circuit the first data is 85°C (LSB=50h, MSB=05h, TH=75, TL=70, CF=127, Reser1=255, Reser2= (change any times from 2 to 16, but many times is only 12), Reser3=16, and CRC= change).
And with ice the lowest temperature is 20°C arghhh
Is the ds18b20 not working? any idea?
Heellpppp!!
Franklin
Hi Sorin,
The tutorial appears to have meen mangled… is there any chance you could put it back up?
Thanks heaps for a great resource!
Andy
Hi Andy,
Now it should be ok. I’ll move the code back into the blog in few days.
Sorin
@ Franklin: Ground pin 3! see http://milesburton.com/index.php?title=Dallas_Temperature_Control_Library#Installation
Thansk for that – it’s great & works a treat.
I did however come across an issue – below freezing it doesn’t go below -1.25 C. As soon as it hit that, the next reading is -0.31 C. I tried it in the freezer and it kept jumping back up, but less & less frequently as time goes by as it tends towards its final temperature. It’s almost as though the integer part of the temperature is wrong. I’m afraid I’m not smart enough to fix it. I graphed it in excel so I can show you what’s happening, but can’t paste it in here I guess, but can email or whatever to anyone.
Thanks, Simon.
Hi Simon,
Try to ground pin 3 as tinux suggested. I’ll run some more tests tomorrow because I’m off work
and will get back and modify the post if it is the case.
Best wishes
Sorin
Thanks for this, very helpful in getting up and running with these sensors!
Hi Sorin, Hope the exams went well. Did you get a chance to try it? I confirmed it’s not a grounding issue – almost certain it’s coding.
Regards,
Simon.