Pages: [1]   Go Down
Author Topic: DS18B20 Incorrect Temperature  (Read 1510 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,
I'm new to the Arduino and have been trying to setup some DS18B20 one-wire temperature sensors. I have five different sensors and non of them read correctly. I have tried the code available in the Arduino playground and http://www.pjrc.com/teensy/td_libs_OneWire.html, and also http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html.
The code from the Arduino Playground and PJRC results in a temperature of 85 C for all probes which when reading the datasheet from the sensors, that is the maximum value.
The code from Hacktronics results in a reading of -29 C to -35 C. I can touch a probe and see the temperature change. I have verified the wiring is correct and have tried both parasitic and regular 5V power.
Could it be possible that the probes are bad? Any thoughts?
Here's the code I'm currently using from Hacktronics.
Thanks!

Code:
//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 3

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x22, 0x13, 0xCB, 0x00, 0x00, 0x00, 0x59 };
DeviceAddress outsideThermometer = { 0x28, 0xE1, 0x26, 0xCA, 0x00, 0x00, 0x00, 0x46 };
DeviceAddress dogHouseThermometer = { 0x28, 0x89, 0x49, 0xCB, 0x00, 0x00, 0x00, 0xD5 };

void setup(void)
{
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
}

void printTemperature(DeviceAddress deviceAddress)
{
  float tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  } else {
    Serial.print("C: ");
    Serial.print(tempC);
    Serial.print(" F: ");
    Serial.print(DallasTemperature::toFahrenheit(tempC));
  }
}

void loop(void)
{
  delay(2000);
  Serial.print("Getting temperatures...\n\r");
  sensors.requestTemperatures();
  
  Serial.print("Inside temperature is: ");
  printTemperature(insideThermometer);
  Serial.print("\n\r");
  Serial.print("Outside temperature is: ");
  printTemperature(outsideThermometer);
  Serial.print("\n\r");
  Serial.print("Dog House temperature is: ");
  printTemperature(dogHouseThermometer);
  Serial.print("\n\r\n\r");
}
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't speak highly enough of Hacktronics and my code below is almost identical where it counts. You might find something useful

Code:
//  This Arduino sketch reads DS18B20 "1-Wire" digital
//  temperature sensors.
//  Copyright (c) 2010 Mark McComb, hacktronics LLC
//  License: http://www.opensource.org/licenses/mit-license.php (Go crazy)
//  Tutorial:
//  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
//  code uses Arduino LCD stuff, for shield on Freetronics EtherTen.
//  Serial print commands are for PLX-DAQ
//  Research your own pins!

#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8,9,56,5,6,7); // patchwire is D4 to A0 (pin14) on this proto
int flag;
// Data wire is on pin 3
#define ONE_WIRE_BUS 3
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress InThermo = { 
  0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F };
DeviceAddress OutThermo = {
  0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F };

//temperature variables
float InTemp, OutTemp, diff, drain, flow, power, tempC;

void setup(void)
{
  // start serial port
  Serial.begin(9600);

  // set up the LCD,s number of columns and rows:
  lcd.begin(16, 2);
  Serial.println("LABEL,Time,TempIn,TempOut,diff");
  // Print a message to the LCD.
  lcd.print("temp in     out");   

  // Start up the library
  sensors.begin();
  sensors.setResolution(InThermo, 12);
  sensors.setResolution(OutThermo, 12);
}

void loop(void)
{
  delay(1000);
    Serial.print("DATA,TIME,       ");
  flag = 0;
  //Get the sensor readings. There are two of them
  sensors.requestTemperatures();

  GetandPrint(InThermo);
  InTemp=tempC;
  flag = 1;

  GetandPrint(OutThermo);
  diff = tempC - InTemp;
  Serial.print (diff);
  Serial.println(" ,  ");

}

void GetandPrint(DeviceAddress deviceAddress)
{
  tempC = sensors.getTempC(deviceAddress);
  if (tempC == -127.00) {
    Serial.print("Error getting temperature");
  }
  else {
    Serial.print(tempC);
    Serial.print(" ,  ");
  }
  lcd.setCursor (1,1);
  if (flag==1)
    (
    lcd.setCursor (11,1)
      );
  lcd.print (tempC);
}




Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
temperature of 85 C

The datasheet has good explanation as to why you are getting 85c.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the info I will look at your code to see if there are any differences. Hacktronics has a great tutorial on these sensors. I ordered a couple of new sensors from sparkfun they will hopefully be here today. I'll try checking everything with the datasheets as well.
Thanks again for the help.
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good luck, all should work out fine. I forgot to point out that the 85 is not the maximum value, it is the maximum temperatrure at the highest order of accuracy. The maximum is 125.

More particularly, 85 is the value you see when you do a power-on reset and, while I don't know the detail of you circumstance, that is probably what you are seeing and is nothing to worry about. You hardly ever see this in normal use.

The code from the Arduino Playground and PJRC results in a temperature of 85 C for all probes which when reading the datasheet from the sensors, that is the maximum value.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did notice that the max temperature was 125C instead of 85C after reviewing the data sheets. It was interesting I tried the sensor again using one sketch and as soon as I uploaded it read 85C then dropped to -35C.
On the upside, my new sensors came in from Sparkfun and I'm getting great readings now. I was trying to save a couple bucks and bought the first set from ebay. I've read where its a toss up on whether you'll get good ones or not.
Thanks agian Nick for all of your help.

Logged

Pages: [1]   Go Up
Jump to: