DS18B20 Thermometer Error Compiling

Hi,

I just started testing a simple thermometer sketch and build i did from the book “Beginning Arduino” using 2 DS18B20. I downloaded the onewire.h and DallasTemperature.h library but not sure if that’s what’s causing my problem with loading the sketch i got from the book. I’m getting an Error Compiling. (I attached a Picture of schematic to)

Here is my code:

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

//Data line goes to digital pin 3
#define ONE_WIRE_BUS 3

//Setup a oneWire instance to communication with any
//OneWire device (no just Maxim/Dalls temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);

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

//arrays to hold device addresses
DeviceAddress insideThermometer, outsideThermometer;

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

  //Start up the library
  sensors.begin();

  //locate device on the bus
  Serial.print("Locating devices...");
  Serial.print("Found ");
  Serial.print(sensors.getDeviceCount(), DEC);
  Serial.println(" devices. ");

  if (!sensors.getAddress(insideThermometer, 0))
  {
    Serial.println("Unable to find address for Device 0");
  }

 if (!sensors.getAddress(outsideThermometer, 1))
  {
    Serial.println("Unable to find address for Device 1");
  }

//print the address of both devices
Serial.print("Device 0 Address: ");
printAddress(insideThermometer);
Serial.println();

Serial.print("Device 1 Address: ");
printAddress(outsideThermometer);
Serial.println();
Serial.println();
}

//function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
  for (int i = 0; i < 8; i++)
  {
    //zero pad the address if necessary
    if (deviceAddress[i] < 16) Serial.print("0");
    Serial.print(deviceAddress[i], HEX);
  }
}

//function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp C: ");
Serial.print(tempC);
Serial.print(" Temp F: ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
}

//main function to print information about a device
void printData(DeviceAddress deviceAddress)
{
  Serial.print("Device Address: ");
  printAddress(deviceAddress);
  Serial.print(" ");
  printTemperature(deviceAddress);
  Serial.println();
}




void loop()
{
  //call sensors.requestTemperatures() to issue a global temperature
  //request to all devices on the bus
  Serial.print("Requesting temperature...");
  sensors.requestTemperatures();
  Serial.println("DONE");
  delay(750);

  //print the device information
  printData(insideThermometer);
  printData(outsideThermometer);
  Serial.println();
  delay(1000);
}

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks .. Tom... :)

TomGeorge: Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks .. Tom... :)

Thanks a bunch Tom. That helped a lot. Thanks again boss

Hi I tested your code work well with one wire , using the water proof one.. no problem compiling latest IDE 1.6.8

make sure you select right arduino comport all that :)

post your error :)

and this is the output to serial :

Requesting temperature...DONE Device Address: 2878F75C060000CB Temp C: 32.63 Temp F: 90.72 Device Address: 28FF9D567704006C Temp C: 27.75 Temp F: 81.95

Requesting temperature...DONE Device Address: 2878F75C060000CB Temp C: 33.00 Temp F: 91.40 Device Address: 28FF9D567704006C Temp C: 27.75 Temp F: 81.95

Hi, We need to see copy of your compile errors.

Thanks.. Tom.. :)

Think I have fixed the Error code and it's compiling. But my output is showing this and my temp sensor is not changing in temperature:

Location devices...Found 0 devices. Unable to find address for Device 0 Unable to find address for Device 1 Device 0 Address: 00000000000000 Device 1 Address: 00000000000000

Requesting temperature...DONE Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60 Device Address: 0000000000000000 Temp C: -127.00 Temp F: -196.60

Bump

have a look at the picture i posted, try connect your sensors like that, see how you go.
pin 1 and 3 of ds18b20 both go to ground data pin connected to 4.7k to 5v and the green data
wire connect to pin 3 on arduino … see diagram

The -127 suggests the sensors are not, or improperly, connected. Clearly, you need to check your wiring but, before you do, run it briefly and see if the sensors get seriously hot. If so, switch off and conclude that the polarity is reversed. Yes, it does happen, but you may not have done any damage. Despite reply #3,and while your code timing is does not actually preclude it, parasitic power mode is never a good idea, and it is safer to use the normal method.

hi Nick,

I never got the conventional method to work :). my temperature probe , in the refrigerator and working well .

I can't comment, but I do note that you refer to the conventional method as conventional!

:) just my bad english Nick .