the DS18B20 is driving me crazy

I’m building a pool thermometer. So accurate repeatable temperature measuring is necessary. I don’t mind the +/-0.5 degree accuracy of the DS18B20 as long as i can kind of calibrate it by setting an offset with a two point line. But i need repeatable results for this.
And this is the problem. The readings i get are not consistent.
Yes. I leave the sensor in a temperature stable environment. No i don’t move it, and there is not head radiation or similar around.
I installed the sensor with an ESP-12 which is battery powered and goes to deep sleep. I use an MCP1300 to get 3.3V from a lipo cell. So i though maybe power is not stable enough and tried a wemos d1 mini.
I also used the 3.3V rail with a 4.7k resistor between VCC/D1.

The readings differ some 0.5-0.6°C between readings.
This is the outcome with one reading every second:

27.50
27.37
27.37
27.37
26.87
27.37
27.37
27.37
27.37
27.37
26.75
27.37
27.37
27.37
27.37
27.37
26.75
27.37
27.37
26.87
27.37
26.75
27.37
27.37
27.25
26.87
27.37
26.75
26.87
27.37
27.37
27.37

So it’s not consistent. Not like 10 correct readings and then 2 wrong ones. Or something like that. Sometimes it’s 2, then 2, then 3 and then 4 again. Unpredictable.

Code itself doesn’t matter it seems. If i use a complicated one, or this super simple one:

#include <OneWire.h>
#include <DallasTemperature.h>
 
#define ONE_WIRE_PIN D1
 
OneWire oneWire(ONE_WIRE_PIN);
DallasTemperature sensors(&oneWire);
 
void setup() {
  Serial.begin(115200);
}
 
void loop() {
  sensors.requestTemperatures();
  Serial.println(sensors.getTempCByIndex(0));
  delay(1000);
}

I forgot to mention: This is a cheap Aliexpress sensor. So maybe it’s just the hardware?

Oh, your data is perfectly fine - giving the lowlevel equipment, it's almost perfect. Just make some quick analysis:

cat  /tmp/a|sort|uniq -c|awk '{print $0 " " $2-a; a=$2}'
      4 26.75
      4 26.87 0.12
      1 27.25 0.38
     22 27.37 0.12
      1 27.50 0.13

So your resolution is 0.12°C and you have convection in the pool and you have ~ 1-2 digits noise. Just make a median filter over ~ 20 samples (taken in ~ 1 minute) and you'll be fine.

DS18B20 normally don't jump that much.
Could be something wrong with wiring/powering/sensing, which you didn't tell us anything about.

The DS18B20 has 16 temp steps per degree C.
Ok for a 0.1C readout, but not enough for a two decimal place readout.
Unless you oversample/average/filter, which is wise anyway.

Serial.println(sensors.getTempCByIndex(0), 1); // one decimal place
Leo..

izeman:
I forgot to mention: This is a cheap Aliexpress sensor. So maybe it's just the hardware?

Sounds like you have a fake sensor there. Genuine DS18B20 are rock solid in my experience, and being expensive there's a lot of incentive to sell fakes/counterfeit/reject/all the above.

However there could be a transmission glitch - normally the checksum would catch this, perhaps you are
using a library that doesn't check the checksum?

MarkT:
Sounds like you have a fake sensor there. Genuine DS18B20 are rock solid in my experience, and being expensive there's a lot of incentive to sell fakes/counterfeit/reject/all the above.

However there could be a transmission glitch - normally the checksum would catch this, perhaps you are
using a library that doesn't check the checksum?

Thanks. I'll check both and start with the library. Using arduino ide on different computers and shared folders there is a little mixup of libraries. And i will order a genuine part from the local store. Yes, they are expensive. One of them goes for 4.50, whereas i paid less for 5pcs sent from China. :slight_smile:

If you are going shopping, be very skeptical of any DS18B20 sensor that claims to be waterproof. Most are not designed for permanent water immersion despite what the marketing blurb says.

For any sensor that will be permanently under water, I put it inside piece of silicone rubber tubing and backfill with silicone potting compound, not the stuff you get from a hardware store, the kind used for protecting underground electrical splices. Do a Google search for "underground silicone potting".

See Magic Gel for Waterproof Electrical Connections - YouTube for an example.

Your data shows 2.26% error which is practically acceptable as anyone with logging experience will say that the response of the sensor is technically valid. However, it would be good to see the error within 2%.

GolamMostafa:
Your data shows 2.26% error which is practically acceptable as anyone with logging experience will say that the response of the sensor is technically valid. However, it would be good to see the error within 2%.

I wouldn't say so. Take a look at the graph which makes totally clear that it reads quite accurately if you take out the completly OFF values which jump 0.5-0.6 below that actual value.

If you look at the other image you see what a good working sensor does look like.

Google drive with forced autentification for two graphs ? ? ? ? ?

Anyway, as already stated, for the price it's ok.

zwieblum:
Google drive with forced autentification for two graphs ? ? ? ? ?

Sure. I did that on purpose. HAHA
No. It's just that stupid forum software that makes uploading pics a hassle.

zwieblum:
Just make a median filter over ~ 20 samples (taken in ~ 1 minute) and you'll be fine.

I can't sample over time as i ain't got time to do it. This is battery powered and needs to measure quick and fall into deep sleep directly after.

mikb55:
If you are going shopping, be very skeptical of any DS18B20 sensor that claims to be waterproof. Most are not designed for permanent water immersion despite what the marketing blurb says.

Thanks. I'll buy a bare sensor and epoxy it into a custom made sleeve. The sensor, wire and it's surroundings should never be in contact with water, and the sensors i used for testing didn't see any water either.

Well, then rethink your setup. Save the data to Flash/EEPROM/whatever you have before entereing deepsleep. Or don't use deepsleep. Or du the maths on some other place.

izeman:
Thanks. I'll buy a bare sensor and epoxy it into a custom made sleeve. The sensor, wire and it's surroundings should never be in contact with water, and the sensors i used for testing didn't see any water either.

That won't work either. Hardware store epoxy has very poor adhesion to PVC cable insulation. You need to use a potting compound specifically rated for water immersion.

mikb55:
That won't work either. Hardware store epoxy has very poor adhesion to PVC cable insulation. You need to use a potting compound specifically rated for water immersion.

Nor the sensor, neither the cable will be in contact with water. This is just to save from splash water, or to safe from electrical short.

Referring to the curves of Post#7: There is something called LQC (Log Quality Control) which when applied to the log data of Post#7, the log data could be interpreted. The way a machine responses to an excitation, a human being responses in a different way; human being responses to the average value. If someone divides the 12-hr log by 12, it is observed that the temperature is quiet stable over 1-hr time.

Makes sense, but doesn't help here. If the sensor shows values 0.5°C off, then it's just wrong. It doesn't help if MOST values or the average is ok.h

izeman:
If the sensor shows values 0.5°C off, then it's just wrong.

I agree if the result is evaluated from the view point of 'Monkey Rule'. Human intellect applies his judgement to evaluate the observed result in strict compliance to the current context which might differ from those listed in the guide book.

I don't think that a philosophic approach helps here. Let's keep it on the technical side. I ordered new genunine sensors and will test them next week. If those give the same results I'll have to look into another direction.

your sensors will always be off till you calibrate them.