Posts: 87
Joined: Wed Sep 14, 2016 11:11 am

how to calibrate DS18B20 "corectly" ?

Fri Dec 29, 2017 5:18 pm


i have final project on uni, and i use DS18B20 as my final project. I try to calibrate this sensor and i use termometer as my "reference". I use w1thermsensor to the sensor.
so, here the problem. let's say Ds18b20 give me result 23.7 celsius and termometer is 22.9 celsius. I use simple math on python, 23.7 - xxxx number = 22.9 celsius (just like on termometer ), but my teacher said "it's wrong!. This is not how you calibrate sensor. You need to make functio (not programing function, but math function )". The question is, how to calibrate this sensor corectly ?
should i take average number from 10 data ( as example ) ?
or i should take "median" number from same data ?
thanks for your help.

User avatar
Posts: 3362
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

Re: how to calibrate DS18B20 "corectly" ?

Fri Dec 29, 2017 5:30 pm

You need to understand the response of the sensor. Check the sensor reading against thermometer reading at several different temperatures, covering the entire range of interest. Plot the sensor reading against the thermometer reading. Is the error constant, linear, square law, or worse? Write an appropriate calibration function using the data you collected as parameters. You should always re-run the calibration at different times to make sure that there aren't any other stray influences.
Questions you could ask yourself:
What is the sensor accuracy?
What is the thermometer accuracy?
What accuracy do I need?
"Thanks for saving my life." See
“Raspberry Pi is a trademark of the Raspberry Pi Foundation”

User avatar
Posts: 3580
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: how to calibrate DS18B20 "corectly" ?

Sun Dec 31, 2017 10:09 pm

Ah so this is the second part.

There are many ways to calibrate.
1) Ask your Teacher to teach you and show you have to calibrate for this instance. That's what they are for.

2) Two point and Three Point calibration.
You need the curve/line to calibrated it too, you put that as a mathematical function y=mx+c
Or something more complicated.

Just take various point over and slightly beyond the range you need.
Take an average (mean normally) and work out your error too for linear if possible or another fit if needed.
You then shift your readings to this line in the program.

3) If factory calibrated, reference and use their information. Check it is performing to they specifications.

4) See 1) but....
Note this is a 'digital thermometer' sensor, it is based on many measurements over time to get it's reading, it is not a thermocouple that normally gives you a voltage output that you need to calibrate via a calibration curve.

Return to “Advanced users”