Skip to content

How To Calibrate Sensors

Published On:
Oct 10, 2025
Last Updated:
Oct 14, 2025

More often than not, when designing embedded systems, you’ll come across the need to calibrate a sensor. Calibration is required when the sensor output does not directly give you the required measurement (e.g. it gives you a voltage, but you need to convert it to a temperature), or when accuracy is required above and beyond the base (i.e. non calibrated) accuracy that the sensor manufacturer provides. This page covers the different ways to calibrate sensors.

Linear One Point Calibration

Linear one point calibration is the simplest form of calibration. It makes the assumption that the sensor is linear and goes through the origin. You are fitting a straight line in the form y=axy = ax (note there is no +b+ b term, which means the line goes through the origin).

Linear Two Point Calibration

Linear two point calibration is the next step up from linear one point calibration. It is simple and only requires two points of data. It makes the assumption that the sensor is linear, but does not assume it must go through the origin. We fit a straight line in the form y=ax+by = ax + b using two points of data, which is just enough to uniquely determine the line.

Linear Best Fit

Linear best fit is the method of fitting the data the best you can with a straight line. The straight line is commonly written as y=ax+by = ax + b, where aa is the slope and bb is the y-intercept. The line is usually fit using the least squares method. This is where we find the line which minimizes the sum of the squared residuals. Minimizes the sum of the squares is not the only way, but is one of the most popular techniques. One reason is that typically a residual that is twice as large as a another residual is more than twice as bad1. Squaring the residuals penalizes larger residuals more than smaller residuals and gives them more weight.

Requires a source of truth, a reference sensor which you can consider to be the “true” value.

Whilst Excel and other spreadsheet programs can do a linear best fit, I almost always prefer to write up a simple Python script (that creates graphs) as it gives me more control and flexibility. I normally type (or automate) the data into a CSV file during calibration and read that in (Python can also read spreadsheet files if you want to use that instead).

The R2R^2 value is a measure of how well the data fits the line. The closer the R2R^2 value is to 1, the better the fit.

Residuals are the left over variation in the data after accounting for model fit.

residuals=datamodel\text{residuals} = \text{data} - \text{model}

One purpose of residual plots is to identify patterns still apparent in the data even after fitting a model. This may give you some useful insight into how you can further improve the model.

Polynomial Best Fit

Polynomial best fit is the method of fitting the data the best you can with a polynomial curve. The polynomial curve is commonly written as y=a0+a1x+a2x2+...+anxny = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n, where a0,a1,...,ana_0, a_1, ..., a_n are the coefficients of the polynomial.

Non-Linear Best Fit

Further Reading

See the Linear Curve Fitting page for more information on linear least squares regression.

Footnotes

  1. David Diez, Christopher Barr, & Mine Çetinkaya-Rundel. 7.3: Fitting a Line by Least Squares Regression. LibreTexts Statistics. Retrieved 2025-10-10, from https://stats.libretexts.org/Bookshelves/Introductory_Statistics/OpenIntro_Statistics_(Diez_et_al)./07%3A_Introduction_to_Linear_Regression/7.03%3A_Fitting_a_Line_by_Least_Squares_Regression.