Problems reading Dallas D18B20 onewire temp sensor...

Hi all -

I am having trouble reading the address ID from Dallas D18B20 sensors -
I’m trying to do the project below:

http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20

The sketch I’ve shown below is the one i’m trying to run.
But I never get any addresses of located sensors.
I’ve got the OneWire library in, sketch compiles and uploads OK.
As his troubleshooting suggests, I’ve done the Blink example (with my 7 year old, as an intro to electronics for him)
The Blink runs fine, as do other sketches.
I think it’s specific to the Dallas chip or what the sketch is listening for on pin 2

Is there some secondary layer of troubleshooting I can undertake to figure out what’s wrong?
Like some sort of testing of pin 2 to be sure it’s getting input from the breadboard,
or some other way I can read data from the Dallas chip to make sure it’s not blown?

Thanks in advance for helping me learn the baby steps to solve the problem on my own.

/* YourDuino Example: Find Address of a DS18B20 Temperature Sensor
Cut and paste the address to a text file for later use.
V1.1 01/17/2013
Questions: terry@yourduino.com

Connections:
DS18B20 Pinout (Left to Right, pins down, flat side toward you)

/-----( Import needed libraries )-----/
#include <OneWire.h>

/-----( Declare Constants and Pin Numbers )-----/
#define SENSOR_PIN 2 // Any pin 2 to 12 (not 13) and A0 to A5

/-----( Declare objects )-----/
OneWire ourBus(SENSOR_PIN); // Create a 1-wire object

void setup() /****** SETUP: RUNS ONCE ******/
{
Serial.begin(9600);

discoverOneWireDevices(); // Everything happens here!
}//–(end setup )—

void loop() /****** LOOP: RUNS CONSTANTLY ******/
{
// Nothing happening here
}

/-----( Declare User-written Functions )-----/
void discoverOneWireDevices(void) {
byte i;
byte present = 0;
byte data[12];
byte addr[8];

Serial.print(“Looking for 1-Wire devices…\n\r”);// “\n\r” is NewLine
while(ourBus.search(addr)) {
Serial.print("\n\r\n\rFound ‘1-Wire’ device with address:\n\r");
for( i = 0; i < 8; i++) {
Serial.print(“0x”);
if (addr < 16) {

  • Serial.print(‘0’);*
  • }*
    _ Serial.print(addr*, HEX);_
    _
    if (i < 7) {_
    _
    Serial.print(", ");_
    _
    }_
    _
    }_
    _
    if ( OneWire::crc8( addr, 7) != addr[7]) {_
    _
    Serial.print(“CRC is not valid!\n\r”);_
    _
    return;_
    _
    }_
    _
    }_
    _
    Serial.println();_
    _
    Serial.print(“Done”);_
    ourBus.reset_search();
    _
    return;_
    _
    }_
    _//( THE END )***_

Read this and fix up your code: How to post code properly

Pete

rabin:
Based on example at:
http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

Rather than use something based on the the Hacktronics programme, it might be better to go to the source and use the real thing, which works just fine.

// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial: 
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>


OneWire  ds(3);  // Connect your 1-wire device to pin 3

void setup(void) {
  Serial.begin(9600);

  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");

    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
           lcd.print('0');
      }
      Serial.print(addr[i], HEX);

      if (i < 7) {
        Serial.print(", ");
        lcd.print(",");
      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

Needless to say, you need to get the wiring right but be assured that the DS18B20 can take abuse - like wiring it the wrong way round.

I'll give that a whirl....

Tried loading and compiling it, but got an error about lcd.print(","); not being declared in the scope.

I don't have an LCD, so I'm going to have to compare the other code that prints to the Serial monitor...something must be different...

Thanks for the quick answer!

Just remove the references to lcd.

Sorry about that. Clearly, the code was not as virginal as I had suggested! I have just checked and, if you delete the two lines

lcd.print(",");

it should compile OK, and just prints on the PC screen.

The original is at the Hacktronics site, which I highly recommend. I found their stuff by far the best to get the DS18B20s going. Their methodology makes more sense (to me) than the others.

I have tried this code to try and get the address to my ds18b20 temperature sensor and all I ever get is "Looking for 1-wire devices...

That's it. " It never pulls up anything. I have tried different forms of the code. But never get anything. I have to ds18b20 hooked up via White-pin 3 Black-grnd red-5.5v White and red 4.7 resistor. If anyone has any recommendations or something to try I am all ears. I have tried several wiring arrangements but nothing has worked.

What you are doing sounds reasonable, as does the wiring. I assume the sensor came with that cable connected. If not, you might ensure the wiring is kosher at the sensor end. If power is reversed, the sensor gets very hot but can survive the abuse.

I have tried everything. I have tried all kinds of wiring arrangements. I have also tried many different address locating code. I have not been successful at all. I am really starting to get a little frustrated. I would not have thought I would be having this much trouble with this temp probe. If anyone has any suggestions on how to get the DS18B20 temp probe working I am all ears.

oceanlife83: I would not have thought I would be having this much trouble with this temp probe. .

You shouldn't. There are only three things that can go wrong

  1. The code. I had some grief with others but the kosher original Hacktronics stuff is fine and I cannot recommend it highly enough.

  2. The wiring. Trust me, it is possible to get it wrong twice but, after that, it gets harder.

  3. The sensor. The DS18B20 can take abuse like improper wiring but I don 't know for how long. If you have only one, you could save yourself a lot of frustration by investing $5 in getting another.

I use the DS18B20 for aquarium sensing and I just used an existing library to make things simpler. Try a library example sketch first, or a proven vanilla sketch.

I have tried the example code listed above to discover the address of my one wire sensor. The code is defective and will not compile. So far NONE of any of the code I have found for the one wire snesors will compile. I am using the latest version of the Arduino language. The Hacintosh example above will not work. Does anyone have an actual working sketch that will read the address of the one wire sensors and also read the temperature from them.

Jim

This is the standard Hacktronics address finder. It compiles and it works. If you cannot get it to work, it will be entirely down to pilot error, so check your wiring and make sure the signal wire is where is it should be, or change line 9 to suit.

// This sketch looks for 1-wire devices and
// prints their addresses (serial number) to
// the UART, in a format that is useful in Arduino sketches
// Tutorial: 
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

#include <OneWire.h>

OneWire  ds(3);  // Connect your 1-wire device to pin 3

void setup(void) {
  Serial.begin(9600);

  discoverOneWireDevices();
}

void discoverOneWireDevices(void) {
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  
  Serial.print("Looking for 1-Wire devices...\n\r");
  while(ds.search(addr)) {
    Serial.print("\n\rFound \'1-Wire\' device with address:\n\r");

    for( i = 0; i < 8; i++) {
      Serial.print("0x");
      if (addr[i] < 16) {
        Serial.print('0');
      }
      Serial.print(addr[i], HEX);

      if (i < 7) {
        Serial.print(", ");

      }
    }
    if ( OneWire::crc8( addr, 7) != addr[7]) {
        Serial.print("CRC is not valid!\n");
        return;
    }
  }
  Serial.print("\n\r\n\rThat's it.\r\n");
  ds.reset_search();
  return;
}

void loop(void) {
  // nothing to see here
}

Below is minimal code for 2xDS18B20.

/*
     DERIVED FROM Mark McComb, Hacktronics
 //  http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
 //  code uses Arduino Serial stuff, for shield on Freetronics EtherTen.

 Use your own DS18B20 addresses, pins etc.
 
 */
#include <OneWire.h>
#include <DallasTemperature.h>

// Ben Bullen group red sleeves 
byte InThermo[8] =  {
  0x28, 0x69, 0xC2, 0xB0, 0x03, 0x00, 0x00, 0X9F};
byte OutThermo[8] = {
  0x28, 0x7A, 0x8B, 0xC0, 0x03, 0x00, 0x00, 0x2F};

#define ONE_WIRE_BUS 3   //pin 3

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

float InTemp, OutTemp, tempC;    
float diff;

void setup() {
  Serial.begin(9600);
 
  delay(2000);
  sensors.begin();
  sensors.setResolution(InThermo, 12);
  sensors.setResolution(OutThermo, 12);
}

void loop() {

    //get the values from the DS8B20's 
    sensors.requestTemperatures();

InTemp = (sensorValue(InThermo));
OutTemp = (sensorValue(OutThermo));  
    diff = OutTemp - InTemp;

    Serial.print(InTemp);
    Serial.print("    ");
    Serial.print (OutTemp);
    Serial.print("    ");
    Serial.println(diff);
    
    delay(1000);
    
}  // loop ends here

//sensorValue function
float sensorValue (byte deviceAddress[])
{
tempC = sensors.getTempC (deviceAddress);
  return tempC;
}

Hi, If you get compile errors you probably don't have the Libraries installed correctly.

Sorry for the hassles! I've shipped thousands of those waterproof sensors with only 2 that didn't work. PLease make sure these are right:

  • LIBRARIES are installed OK, and VERiFY gets NO compile errors. Then code uploads OK
  • HARDWARE: The pinout is understood, the pullup resistor is really about 5000 ohms
  • SOFTWARE: The Hacktronics or my code example finds the DS18B20 and reports the address.

Then run one of the examples that gives you temperature results! MAYBE you have a bad sensor. Do you have only one??