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 OneWire Arduino Library, connecting 1-wire devices (DS18S20, etc) to Teensy, and also Arduino 1-Wire Tutorial.
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!
// 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");
}
I can't speak highly enough of Hacktronics and my code below is almost identical where it counts. You might find something useful
// 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);
}
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.
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.
MTSkier:
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.
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.