Problem with DS18B20 output:

Sorry to bump into an old thread, but i have a similar problem.
(moderator: split of from Problem with DS18B20 output: - Sensors - Arduino Forum )

I'm using OneWire and milesburton library to read from multiple ds18b20 sensors.
The problem is that on some of those sensors temperature slightly fluctuates between readings, eg. (raw format from milesburton library):

2432 (19C)
2448 (19.125C)
2432 (19C)
2432 (19C)
2448 (19.125C)
2432 (19C)

Sensor resolution is set to 11 bits. Sadly, my setup goes against any "best practice":
7 sensors in total
Star network topology (i could wire 3 sensors in a non start topology, but i cannot change wiring of 4 others)
Cable length varies from 50cm to 18 meters. Some if those cables run near power cables (220v), cannot change that.
1k pull up resistor (tried with 0.5 - 2k, does not seem to impact it)
Voltage seems to run at 5.22v - 5.25v

So what are my options to get more stable readings?:

  1. Do some kind of software based post-processing (eg.: read values 5 times, and take an average or median)?
  2. Rewire each sensor on separate pin to avoid star topology?
    3)... ?

I never use 11 bit resolution, but the results look pretty normal to me. You might try the default 12 bit resolution or, at the other extreme, print an int instead of the float.

If the cable length or proximity to power cables was a problem, you would have far more obviously bad readings than this. The standard pullup resistor is 4.7k. and 2.2k is used for longer lengths. The device will work over a wider voltage range.

Taking averages is doable if you can spare the time, but I submit it is unwarranted, and you haven't explained why it is warranted. What you are seeing is the limit in resolution inherent in the device. Changing the wiring won't fix anything and defeats the purpose.

The resolution when using 11 bits is 0.125C so it's only fluctuating by one step, which looks pretty good given the conditions. Without showing more samples how do you know it's not just between values? As Nick_Pyner says, use 12-bits and/or do some averaging.