I am testing out a DS18B20 Temp sensor for use in a reef controller I am working on and I am getting consistently low readings. At room temperature I am getting 2.75C, 36.95F after conversion to Fahrenheit.
Any help would be appreciated. Has anyone seen this before?
It would help if you post some code. Also your wiring could clear up stuff.
Greetings,
EriSan500
Thia is code from http://www.reefprojects.com
I noticed some of the code referring to parasite power which I do not plan to do. I am new to working with code so please be patient with me. Also the picture does not show a 4.7K pu resistor, but I do have one from 5v to the data pin (2) currently.

//Get temp data from DS18B20 ***************************************************************************************
if ( !ds.search(addr)) {
ds.reset_search();
return;
}
ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end
present = ds.reset();
ds.select(addr);
ds.write(0xBE); // Read Scratchpad
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
}
LowByte = data[0];
HighByte = data[1];
TReading = (HighByte << 8) + LowByte;
SignBit = TReading & 0x8000; // test most sig bit
if (SignBit) // negative
{
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Tc_100 = (Tc_100 * 9/5) + 3200; //Convert to fahrenheit, comment this out to display in celcius
//Display current temperature*****************************************************************************
lcd.setCursor(0,0);
Whole = (Tc_100 / 100); // separate off the whole and fractional portions
Fract = (Tc_100 % 100);
lcd.print(Whole, DEC);
delay(keypad_delay);
lcd.print(".");
delay(keypad_delay);
if (Fract < 10)
{
lcd.print("0");
delay(keypad_delay);
}
lcd.print(Fract, DEC);
delay(keypad_delay);
lcd.write(0xDF);
delay(keypad_delay);
lcd.print("F ");
delay(keypad_delay);
//Display Time******************************************************************************************
lcd.setCursor(0,10);
if((hour < 10 && hour > 0) || (hour > 12 && hour - 12 < 10)){
lcd.print(" ");
delay(keypad_delay);
}
if(hour > 12){
lcd.print(hour - 12, DEC);
delay(keypad_delay);
}
if(hour == 0){
lcd.print(12, DEC);
delay(keypad_delay);
}
if(hour > 0 && hour < 13){
lcd.print(hour, DEC);
delay(keypad_delay);
}
lcd.print(":");
delay(keypad_delay);
if(minute < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(minute, DEC);
delay(keypad_delay);
lcd.print(":");
delay(keypad_delay);
if(second < 10){
lcd.print("0");
delay(keypad_delay);
}
lcd.print(second, DEC);
delay(keypad_delay);
if(hour < 12 || hour == 0){
lcd.print("AM");
delay(keypad_delay);
}
else{
lcd.print("PM");
delay(keypad_delay);
}
There are 2 versions to my knowledge of the DS18X20 digital thermometer. Some measure an integer number of one half a degree celcius others measure an integer number of one sixteemth of a degree. You use the wrong code and the temperatures are out by a factor of 8. Does 2.75 * 8 (22 C or around 74F) sound reasonable ?. It does to me
As some kind of iluustration take a look at http://majestic81.plus.com/
The line that says Digital Thermomters. There are 5 numbers at the end of the line, the last one is 255 which is a dead value. The first is much larger than the next 3. The first one is sixteenths, the last 3 are halves because they are different types. Just a matter of changing your code to up the figures by a factor of 8
At the heart of using a DS1820, first...
You fetch two bytes from the chip. (You may fetch more than two, but two hold the temperature... in a less than obvious form)
... then...
You convert the two bytes to a single number, that being the temperature in Celcius.
Sorry I haven't better details for you here, but maybe the overview helps?
Thanks for the info guys. Using Pluggy's suggestion, I added a line of code multiplying the value * 8 right before the Fahrenheit conversion, and I seem to be getting sane readings for the room it is in.
TReading = (TReading ^ 0xffff) + 1; // 2's comp
}
Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25
Tc_100 = (Tc_100 * 8);
Tc_100 = (Tc_100 * 9/5) + 3200; //Convert to fahrenheit, comment this out to display in celcius