Go Down

Topic: Dallas DS18B20 unstable reading (Read 1 time) previous topic - next topic

I'd appreciate any thoughts on how to pin down a problem I'm having getting reliable readings from some of my DS18B20s.  I'm running a number of these for home automation sensing purposes, for instance monitoring boiler and water flow temperatures, usually without any problem.   However, I have a couple of sensors at around 5m distance that are giving me problems.

Here's the situation:

  • Two Arduinos, one Mega (with Ethernet shield) and one Uno (no shield)

  • Each reading between 3 (Mega) and 6 (Uno) sensors

  • Datalines for Mega sensors on ports 6, 7 & 8

  • One sensor per port

  • Each sensor connected using dedicated CAT5e cable

  • Maximum sensor distance from Arduino around 5m

  • Sensors continually powered (ie, not parasitic) @ 5v, with the data line pulled up using 4k7 resistors using an external strip board

  • Sensors being read every 10 seconds using standard OneWire.h library



I have had no problems with the reliability or accuracy of the sensors on the Uno.  I have equally had no problems with one of the sensors on the Mega, which is at a distance of perhaps 3m.  The problem comes with the two other sensors on the Mega, which are perhaps slightly further at around 5m.  They behave as follows:


  • On powerup, sensors read around 15 degrees C more than ambient

  • Over the next 2-3 minutes, the sensor readings progressively reduce to ambient

  • The sensors function correctly for the next 2-3 days, after which time they fail to read



I have tried increasing the temperature conversion delay from the 188mS recommended for 10 bit resolution to 300mS, but without any measurable effect.

Would appreciate any pointers of what to explore.  Others have clearly managed reliable comms at several 10s of metres, so I can't believe the problem is distance alone.  Could it be capacitance, or side effects from the use of the external board?  Any thoughts appreciated

robtillaart

Try replacing the resistor with a 2K2 one (or even 1K)
As the wires become longer the digital pulses get malformed (shark-fin 's iso square waves)
Lowering the resistor pulls the signal faster to +5V giving a cleaner signal.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Erdin

Reading 15 degrees more than ambient temperature ? You should check the error or checksum or whatever.
When the communication with the sensor failed, the value is not the temperature and it should be ignored.

Well that was what had me puzzled Erdin - the CRC is valid on all these readings.  This includes those initial ones much higher than ambient and the zero readings I get after 2-3 days.  CRC checking code below:

Code: [Select]

boolean readScratchPad(byte sensorNum) {
  // Read the temperature
  oneWire[sensorNum].reset();
  oneWire[sensorNum].skip();
  oneWire[sensorNum].write(READSCRATCH);
 
  for (int i = 0; i < 9; i++) sensBuffer[i] = oneWire[sensorNum].read();
 
  if (oneWire[sensorNum].crc8(sensBuffer, SCRATCHPAD_CRC) != sensBuffer[SCRATCHPAD_CRC]) {
    return false;
  }
  else return true;
}


I will try Rob's suggestion of a stronger pullup, but would be grateful for any ideas of why I'm getting the high readings for the first 2-3 minutes

Erdin

I think something basic is wrong.

What library do you use? Perhaps the library is faulty.
Did you use an old version that someone has uploaded years ago ?
Use the OneWire library. http://playground.arduino.cc/Learning/OneWire
And use either the example code that came with it, or the DallasTemperature library.

Sometimes the CRC could be wrong, perhaps there was a power glitch or so. That is not a problem.
But reading the wrong temperature is simply not possible.

Is the voltage below the minimum voltage ?
Did you decouple the voltage at the sensor ?

I have used an older version of the OneWire library, with some minor modifications that wouldn't affect signal processing.  I will have a look at Paul's latest library.

Voltage is 5v, so nothing obvious there, but can you clarify your comment about decoupling the voltage at the sensor?  My pullup resistor is currently at the Mega end, and I can easily move to be adjacent to the sensor, but I'm not sure that is what you meant by 'decoupling'.

Erdin

That pullup resistor is fine.

Normally a sensor via a long wire is used with a 100nF capacitor to 5V and GND at the sensor.
To 'decouple' the power line from high frequency noise.

But after reading the datasheet, it seems that the DS18B20 has an internal capacitor to avoid noise. The examples don't show an external capacitor since that is not needed for this sensor.   :smiley-eek:

Please use the new Arduino version 1.0.5 and the newest libraries for OneWire and (if needed) the DallasTemperature. Check the returned error code.
I think it is just not possible to make a DS18B20 to send the wrong temperature. Or perhaps when the DS18B20 is half-roasted.

Go Up