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.
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.
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?
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.
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 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?
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 to OneWire::reset_search()'
Can you please tell me what the issue is here? (I'm going crazy trying to debug it!).