Best practice for detecting errors with DS1820 thermometer sensors

I am using several DS1820 (some are DS18B20) and am having difficulty recognizing bad temperatures, and was wondering if anybody had some good ideas.
I’m using (more or less) this OneWire library, and currently have the sensors in powered mode, with a 4.7k pull-up resistor. Most of the time the sensors give an accurate reading, but occasionally there’s an 85C reading (I believe this means the sensor did not have time for conversion), but other times -0.062 or -0.05, and a host of other (usually) obviously invalid readings. I use the CRC check (like here), so it seems the CRC is ok… and I’m wondering if there is any good practice for recognizing invalid values. One method I’ve seen suggested is to take several readings and discard outliers, but this only works as long as the “error code temperatures” are significantly far away from the real temperature, and in many cases I have real readings which are not far enough away from the error reading.
Thank you for your thoughts! :smile:

Others seem to be using filter algorythms like Kalman Filter.

Hmmm… but that doesn’t really help for the situation where the real temperature and error temperature is very close right? Also, unlikely it could be implemented on a photon or?

What do you consider very close and how would you know that very close reading is in fact an error and not a correct value anyway?
If you actually are measuring in the range of 0.05°C I’d guess you wouldn’t care if it was an erronous 0.05 or an actual reading of 0.05°C plus/minus a few10th of degrees (considering the accuracy of the sensor anyway ;-))

From the datasheet

How about that?

I saw the ping on the UKF library, so I thought I’d chime in here. (FYI, I’ve never used that library in practice…) I’ve been using the DS18S20 sensors for quite some time (over a year) for a home thermostat with the Core, and haven’t been having any troubles at all with the simplistic first order lag filter (something like an average over ~4 samples if I remember right) that I’ve got on it. After I got everything setup, I haven’t ever noticed any problems. A couple things to help with the errors in general. They’re pretty sensitive to timing, so waiting a little extra longer on the conversion doesn’t hurt at all. In addition, I found that even if you are running in powered mode, with longer runs a stronger pull-up resistor (~2-3k) may be helpful. YMMV, I’m not responsible for any fires started by bad temps :smile: