DS18B20 temperature sensors oscillating between -127 and actual temperature

I've got an issue with 3 temperature sensors connected to an Arduino UNO using I2C, been working fine for a week or so but now two of the temperatures are flicking between -127 and the actual reading about once a second roughly. I thought it might be a loose wire but I've checked everything inside the enclosure and re soldered a couple of connectors what were crimped or in screw terminals but it's still playing up. Could it be a fault on the arduino or the temperature sensors? Can I test them before spending money on new ones?

(deleted)

How often are you reading the temperature?

DS18B20

temperature sensors connected to an Arduino UNO using I2C

Which?

pure DS18B20 sensors don't use I2C they use the onewire-protocol.
If you use them with I2C this would mean that there has to be an additional microcontroller that does the translation from onewire to I2C or it might be a different sensor but not a DS18B20.

Measuring with a DS18B20 takes about 700 to 800 milliseconds. So if you request after a shorter period this might causes problems.

Another thing is that the onewire-bus needs a pull-resistor between datapin and Vcc.
If you use very long wires (more than 5-10 meters) with a star-topology then elctric reflections can become a size that readings become unreliable.

So there are a few things to clear before more advice can be given.
It is always a good idea to post the complete sketch. This answers a lot of questions

best regards Stefan

It is always a good idea to post the complete sketch. This answers a lot of questions

I will second that and add that a detailed schematic is also welcome.

How to ask a programming question.

Read the how to use this forum-please read sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

There is a pull up resistor between the data pin and Vcc. Annoyingly this had been working fine on the test bench by the computer for about 4 weeks. I then installed it into a plastic enclosure and wired the relays outputs up and it's been fine for a week or so. Making me think it's a loose connection but wiggling the wires inside the enclosure didn't make any difference to the pattern of the reading flashing -127 it seems to be always about once a second, so it might be the 700-800 millisecond delay I need to program into the code. But why did this not happen when it was wired up and left running for 4 weeks by the computer? Also it's only the 2nd and 3rd sensor that are reading -127. Sensor 1 always reads correctly and they are all connected to the same data pin, pin 2, and pull up resistor, and share a common ground and +Vcc?

Just to check, you are supplying the devices with a true VCC and not trying to use parasite power mode, right?

don't know if this might be the reason in your case.

Once I had some sensors of an application with 15 sensors connected to one bus reporting -127 because condenswater was between the pins of some sensors.

The pull-up-resistor should be connected to the most far away sensor.

best regards Stefan

the +V and ground to the sensors comes from the Arduino Uno, the relay board if connected to separate 9v power supply.

Just to update this thread. I've turned the solar controller back on now the weathers a bit sunnier and it was fine for a couple of days. But now all 3 sensors seem to be stuck on -127. I was going to alter the code, so that it read the temp from the sensor, and only update the value if it's not -127. I know this will slow down the refresh rate and accuracy, but as long as I get a reading updated every minute or so that will be fine, it's only to control a solar pump and diverter valve to split the heat from the solar panels to a hot water storage tank and hot tub.

Hi,
What solar controller and what does it have to do with your 3 DS18B20s?

Can you please tell us your applicaton?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Read the Maxim (Dallas) 1-Wire datasheet and look at the 1-Wire library.
The 1-Wire (never really one wire, but either 2 or 3) data protocol needs very precise timing to work and cleverer people than me do it by bit-banging.
It's old technology, but works really well.
If you don't mind running some cables, you can have a rock-solid system, but as StephanL38 said, you need to follow the rules with the all-important pullup resistor.

The solar controller is what I have made using the Arduino, temperature sensors and a relay board. Basically it turns on a 12v pump if the temperature in the solar collector is more than 10C hotter than the thermal store it is currently connected to and heating/ charging. But unlike off the shelve units it also activates a 3port diverter valve so when store 1 reaches a setpoint say 45C, it switches to heating store 2 to a setpoint say 30C, then returns back to store 1 until a maximum safe temperature is reached in the store say 80C, then if goes back to store 2. Store 1 is a 200litre hot water tank and store 2 is a 4000l hot tub. Obviously on a really sunny day it could boil the 200l tank but as a safety devise if 80C is reached in store 1 it will switch to store 2, a 9Kw solar panel will never boil 4000l of water there's not enough sunlight hours in a day, and it looses heat at night

Could be something with your unknown code or unseen wiring.

Hi,
Thanks finally for the whole picture.
So can you PLEASE post a copy of your code?
Can you PLEASE post a copy of your circuit?

How far is it between your solar thermal collector panels and the UNO?
What DS18B20 sensors are you using?
The TO92 case PCB ones or the metal encased sealed units.

Tom... :grinning: :+1: :coffee: :australia:

on very long wires the readings can become unstable. That is one possible reason for changing values between -127 and a real measurement. A star topology of the sensor-wires creates more "distortion" than a single-line topology. star-topology means multiple meter long wires to each sensor connected together at your microcontroller.

My personal experience with onewire is that reducing the value of the pullup-resistor can help to solve problems like this. The datasheet says 4,7 kOhm für the pull-up-resistor. I have installed 21 DS18B20 sensors in my heating system. The wiring is estimated 20m long. All sensors are connected to the line with short pieces of wire 10 to 20 cm long. (stubs)

I had the -127-issue on some sensors. So I reduced the pullup-resistor from 4,7 kOhm to 2 kOhm and now it is working fine. And I'm using it with real powersupply of each sensor not parasitic-power-mode. This is essential if you reduce the pullup-resistor.

Do you have an oszilloscope? I know not that measuring-device every arduino user has laying around. But in this case can be helpful to see if the signal gets bended too much from ideal rectangular pulses to rounded pulses. With decreasing the pullup-resistance I could watch on the oscilliscope how the signal-shape changed into direction of more rectangular.

best regards Stefan

Hi,
Have you run the code that checks the DS18B20 addresses?
That would be a good independent bit of code to see if your hardware is working correctly.

Tom.. :grinning: :+1: :coffee: :australia:

I've managed to remove the board and bring it into the house and connect it directly to my desktop Pc uploaded the new code with the lines added to ignore a temperature reading of -127 and re connected it. Now the temperature sensor with the longest cable about 8m is jumping from the actual reading of 28C to 84C? I might give the 2K resistor a try. How can I easily draw my schematic and upload it to make sure I've not done something stupid with the power feeds?

I do not understansd why drawing a schematic can be dangerous in any way except with religious content of a certain flavor?

So just draw a schematic by hand. This will be absolutely sufficient.

"Power-feeds" is not a common technical term what does it mean in this context?
best regards Stefan