DS18B20 Reading -127

Hi all,

I am running a system of 3 sensors(turbidity, water level, temperature) with an Arduino Leonardo. I've got the turbidity and water level sensors working fine, but the temperature sensor is giving me problems.

Set Up: I have set up the DS18B20 waterproof sensor using external power. I have set up the circuit as seen in the following tutorial. The power is coming from the Arduino 5V pin. http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html

The Arduino is on the other side of the room from the sensor. I've used wire nuts to connect the sensor wires to 22 gauge wire to reach the Arduino. The gauge of the sensor wire seems to be only 26.

In addition to trying to read from the sensor, I have tried to get the address using this tutorial. http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

Result: When I try to read the address, nothing comes out of the COM port.

When I try to read the temperature, the only things I am able to get from the sensor are -127 and 0 with an occasional nan.

Some google searching seems to say that the -127 is a bad connection. And getting 0 might also suggest the same thing. However, I have two sensors so I tried plugging the wires from the second sensor directly into the Arduino. The result is the same.

At this point I'm at a loss as to what to do next. Can anyone suggest some troubleshooting steps? Does anyone have any idea what the problem could be?

Thanks for any help.

ddileona:
I have set up the DS18B20 waterproof sensor using external power. I have set up the circuit as seen in the following tutorial. The power is coming from the Arduino 5V pin.

What do you mean by that?

The 127 means a bad connection, but I think it may also mean good connection with a bad choice of cable. I had no end of grief using the same sensors with extra cable. I think the Hacktronics code is the best, so stick with it. Use the address sniffer with the original cable only, then try the sensor reading code, still with that cable. Once you have proven that, try a longer cable. The popular choice is CAT5 cable. I don’t think there is any science in this, it is just quality cable that is cheap.

In response to your question, you can set up this sensor with external power or in parasite power mode. I have chosen to use external power because it allows you read the sensor faster.

The source of the power is the Arduino 5V pin. This sensor takes power from 3V to 5.5V according to its spec sheet.

Does that answer your question?

OK. From an Arduino user's view, "external power" implies power external to Arduino. You are right to stay away from parasitic power, it usually spells trouble.

I suggest connecting DS sensor directly to arduino and read the device address.
This works for me, I have just checked it:

// Search addresses of sensors DS18B20

#include <OneWire.h>

OneWire onewire(12);   // sensor pin change if needed

void setup()
{
  while(!Serial);
  Serial.begin(9600);
}

void loop()
{
  byte address[8];
  
  onewire.reset_search();
  while(onewire.search(address))
  {
    if (address[0] != 0x28)
      continue;
      
    if (OneWire::crc8(address, 7) != address[7])
    {
      Serial.println(F("1-Wire bus connection error!"));
      break;
    }
    
    for (byte i=0; i<8; i++)
    {
      Serial.print(F("0x"));
      Serial.print(address[i], HEX);
      
      if (i < 7)
        Serial.print(F(", "));
    }
    Serial.println();
  }
  
  while(1);
}

As a result you would have its address.
Does it work?

I added a few Serial.println() commands so that I could monitor the progress of the code.

I also added a onewire.reset() line before onewire.reset_search() because the OneWire library page seemed to suggest it was a good idea.

Everything runs through fine until it gets to onewire.reset_search(). Then it just hangs there. (In other words, it never gets into the while loop.) It is doing it right now and has been for a couple of minutes. Is it supposed to take that long?

Stick with the Hacktronics stuff you have

Success!

I'm running the hacktronics code and it works. The key was to get the power into the right row on the breadboard (face - palm).

Skylurker,

I downloaded your code (see above) to find the DS18B20 device address. After modifiying the pin address (i,e, OneWire onewire(2); ) and setting the path to the #include library then compiling I get the following error;

SensorAddress.cpp.o: In function loop': D:\AppArduino/SensorAddress.ino:17: undefined reference toOneWire::reset_search()'

Can you please tell me what the issue is here? (I'm going crazy trying to debug it!).

Thanking you ion advance for your assistance.

Regards,

Sciencez

It sounds like a library problem.

Make sure the library is in the libraries folder along with all the other libraries.

Restart the Arduino IDE so that it can find the new library.