Chapters

20 Sensor Calibration Techniques

sensors
sensor
types
calibration

20.1 Start With the Measurement Story

Calibration is the moment a sensor reading becomes accountable. Start with a known reference, measure the error, adjust the relationship between raw value and real quantity, and keep evidence that the correction still holds.

20.2 In 60 Seconds

Sensor calibration corrects manufacturing variations so readings match reality. One-point calibration fixes constant offset errors (sensor always reads 2.3°C high). Two-point calibration fixes both offset and scale errors using two reference values (ice water at 0°C, boiling water at 100°C). Store calibration coefficients in non-volatile memory and recalibrate periodically since sensors drift over time.

The mathematical gist. The DHT22’s catalog-typical 0.100 °C step has sigmaq=0.0289\\sigma_q=0.0289 °C RMS. The chapter’s two-point scale of 1.0817 stretches each corrected rung only to 0.108 °C. Its 1.68 °C validation residual is about 58.2times58.2\\times the unrounded quantisation floor and exceeds the 0.5 °C HVAC tolerance, so rounding cannot explain the stated nonlinearity.

Math Bridge · guided foundationsIs the calibration miss just a digital step?Let Phoebe compare the DHT22 validation residual with its quantisation floor.
Chapter Roadmap

This chapter has four practical stops:

  1. First identify the error shape: offset, gain, nonlinearity, noise, or drift.
  2. Then choose the lightest defensible correction: one-point, two-point, or multi-point calibration.
  3. Next store the coefficients with evidence, schedule recalibration, and account for drift.
  4. Finally validate on an ESP32-style greenhouse example and use the quizzes to check the workflow.

Checkpoints recap the decision points. Deep-dive calculators are useful once the basic workflow is clear.

20.3 Key Concepts

Start with Calibration: the process of comparing a sensor’s output against a known reference standard and applying correction factors to make readings accurate. Then Offset Error: a constant additive error where the sensor always reads too high or too low by the same amount regardless of the measured value; corrected by one-point calibration. Next Gain (Scale) Error: a proportional error where the sensor’s reading diverges from truth at a rate proportional to the measured value; requires at least two reference points to correct. After that One-Point Calibration: a calibration technique using a single reference value to correct offset error; appropriate when the sensor’s gain is known to be accurate. Continue by Two-Point Calibration: a calibration technique using two reference values to simultaneously correct offset and gain errors across a defined measurement range. Continue by Reference Standard: a known, traceable measurement source (ice-water bath at 0°C, boiling water at 100°C, certified weights) used as ground truth during calibration. Continue by Drift: the gradual change in a sensor’s calibration over time due to ageing, mechanical stress, or environmental exposure; requires periodic recalibration to maintain accuracy. Finally Non-Volatile Memory (NVM): storage (EEPROM, flash) that retains calibration coefficients after power-off so the sensor does not need to be recalibrated every time it starts up.

Learning Objectives

After completing this chapter, you will be able to:

  • Justify why sensor calibration is necessary for production IoT systems and identify which error type each technique corrects
  • Execute one-point and two-point calibration procedures using reference standards
  • Implement calibration routines in MicroPython on ESP32 and store coefficients in non-volatile memory
  • Design a calibration maintenance schedule for deployed sensors based on sensor type and environment

20.4 For Beginners: Sensor Calibration

Calibration is like setting your bathroom scale to zero before weighing yourself. Every sensor has small manufacturing differences, so two identical temperature sensors might give slightly different readings in the same room. Calibration corrects these differences by comparing the sensor’s reading against a known reference value and applying a simple correction formula to get accurate results.

20.5 Prerequisites

20.6 Every Sensor Needs Calibration

~25 min | Intermediate | P06.C08.U06

Even the best sensors have manufacturing variations. Two DHT22 sensors from the same batch might read 0.5°C apart when measuring the same temperature. Calibration corrects these individual differences.

Low-cost deployments need this discipline because variation arrives from several places at once. Production spread can make devices from the same run disagree. Different sensing principles can respond differently under similar conditions. Shipping, storage, assembly, shock, humidity, heat, cold, and ageing can change a response after the bench test. Analog sensors also inherit ADC reference and quantization errors, while inertial sensors add mounting and axis-alignment error. Treat recalibration as part of the release plan, not as a one-time lab activity.

Types of Sensor Errors:

Error TypeDescriptionFixable with Calibration?
Offset (Bias)Constant error at all valuesYes - one-point calibration
Gain (Scale)Error proportional to readingYes - two-point calibration
NonlinearityCurved error across rangePartially - multi-point calibration
NoiseRandom variationNo - requires filtering
DriftError changes over timeRequires periodic recalibration

Physics PhoebeCheckpoint: Error Shape First

You now know:

  • Offset, gain, nonlinearity, noise, and drift are different failure modes, so they should not all receive the same correction.
  • A 0.5°C disagreement between two DHT22 sensors is a calibration problem; random noise still needs filtering.
  • Calibration starts with a trusted reference and ends with evidence that the correction still holds.

20.7 One-Point Offset Calibration

When to use: Sensor reads consistently high or low by a fixed amount.

Method:

Start by Measure a known reference value. Then Calculate the offset: offset = sensor_reading - true_value. Finally Subtract offset from all future readings.

One-point calibration is a zero-shift correction:

Start by Put the sensor at one trusted reference value, such as ice water at 0°C. Then Compute offset = sensor_reading - reference_value. Finally For every future reading, use corrected = raw - offset.

Example: if the sensor reads 2.3°C in ice water, subtract 2.3°C from future readings.

20.7.1 Interactive: One-Point Offset Calculator

20.8 Two-Point Offset and Gain

When to use: Sensor has both offset error AND scale error.

Method:

Start by measure two known reference values (low and high). Then calculate scale and offset. Finally apply linear correction: corrected = raw * scale + offset.

Two-point calibration fits a straight line:

Start by measure the sensor at a low reference and a high reference. Then compute scale = (ref_high - ref_low) / (raw_high - raw_low). Next compute offset = ref_low - raw_low * scale. Finally apply corrected = raw * scale + offset.

This fixes both a zero offset and a gain/span error.

20.9 Putting Numbers to It

Two-point calibration corrects both gain and offset errors. Let RR = reference (true) value and MM = measured (raw sensor) value. Given ice water (0°C) reads 1.8°C and boiling water (100°C) reads 98.5°C:

The scale is (100 - 0) / (98.5 - 1.8) = 1.034.

The offset is 0 - 1.8 * 1.034 = -1.86.

The corrected formula is corrected = raw * 1.034 - 1.86. At room temperature, a raw reading of 24.5°C becomes 23.5°C. Without calibration, the 1.0°C error would violate many HVAC control requirements.

20.9.1 Two-Point Calibration Calculator

Enter your sensor’s raw readings at two known reference points to compute the calibration coefficients and test a correction.

20.10 Practical Calibration References

MeasurementReferenceAccuracyNotes
TemperatureIce water (0°C)+/-0.1°CUse crushed ice, stir
TemperatureBoiling water (100°C*)+/-0.5°C*Altitude dependent
TemperatureRoom thermometer+/-0.5°CUse NIST-traceable reference
HumiditySaturated salt (75.3% RH)+/-0.5%Sodium chloride (NaCl) solution
HumiditySaturated salt (32.8% RH at 25°C)+/-0.5%Magnesium chloride (MgCl₂)
PressureWeather station data+/-1 hPaCompare with local airport
DistanceTape measure+/-1mmFixed distance reference

We just used one and two reference points to correct simple errors. The next question is what to do when the error curve bends between those points.

20.11 Multi-Point Calibration

When to use: Sensor has nonlinear response that two-point calibration cannot correct (as demonstrated in the worked example below).

The following example uses NumPy for polynomial fitting. On resource-constrained microcontrollers, compute the coefficients on a PC and hard-code them, or use a simple lookup table with linear interpolation between points.

For nonlinear sensors, fit the correction curve on a laptop first:

  1. Record several pairs: known reference value and raw sensor reading.
  2. Fit a polynomial or create a lookup table from those pairs.
  3. Copy only the final coefficients or table into the microcontroller.
  4. Verify the correction at points that were not used to create the fit.

On small IoT devices, avoid doing the full polynomial fitting at runtime.

20.12 Polynomial Calibration Explorer

Enter 3—5 calibration points (reference vs raw) and see how a quadratic polynomial fits the data. Adjust individual points to observe how nonlinearity affects the correction curve.

20.13 Storing Calibration Data

Best Practice: Store calibration coefficients in non-volatile memory (EEPROM/flash):

Store at least these fields with the coefficients:

  • Sensor ID or serial number.
  • Calibration date and next due date.
  • Scale and offset values.
  • Reference instrument used.
  • Environmental conditions if they matter.

At startup, load these coefficients before publishing any sensor readings.

20.14 Best Practices for Sensor Calibration

20.14.1 Calibration Checklist

Start with Document everything: Date, reference instrument, environmental conditions, coefficients. Then Use stable conditions: Allow sensor to warm up (30 min for gas sensors), avoid drafts. Next Average multiple readings: Take 10—20 readings at each calibration point to reduce noise. After that Use accurate references: Your reference must be more accurate than your sensor. Continue by Verify after calibration: Validate against a third reference NOT used in calibration. Continue by Recalibrate periodically: Follow the schedule guidelines below for your sensor type. Continue by Store coefficients safely: Non-volatile memory (EEPROM/flash) with backup. Finally Avoid overfitting: Too many polynomial terms can amplify noise between calibration points.

20.15 Calibration Schedule Guidelines

Read the schedule as a set of starting intervals modified by exposure and consequence. A temperature sensor’s six-month interval is shortened by shipping or extreme temperature because either can change mechanical stress or calibration. Humidity and gas sensors receive shorter default intervals because high-humidity exposure and contamination can alter their sensing films or chemistry. A pH probe is checked before each use because storage state and electrode condition directly affect the next measurement, while a load cell’s annual interval is immediately overridden by an overload event. When applying the table, record both the calendar due date and the trigger event that can bring it forward; then validate the device against an appropriate reference before returning it to service. This keeps recalibration tied to plausible drift mechanisms rather than treating the listed interval as a warranty.

Sensor TypeRecommended IntervalTrigger Events
TemperatureEvery 6 monthsAfter shipping, extreme temps
HumidityEvery 3 monthsAfter high humidity exposure
PressureEvery 12 monthsAfter altitude changes
Gas sensorsEvery 3-6 monthsAfter contamination
pH sensorsBefore each useAfter storage
Load cellsEvery 12 monthsAfter overload events

Physics PhoebeCheckpoint: Linear Calibration Math

You now know:

  • One-point calibration corrects a constant offset such as 2.3°C.
  • Two-point calibration uses two references, such as 0°C and 100°C, to compute both scale and offset.
  • In the worked example, raw readings of 1.8°C and 98.5°C produce scale 1.034 and offset -1.86.

20.16 Try It: Calibration Drift Estimator

Sensors drift over time due to aging, contamination, and environmental stress. Estimate when your sensor will exceed its accuracy tolerance and needs recalibration.

20.17 ESP32 Two-Point Calibration

This example walks through a real calibration procedure for a DHT22 temperature sensor deployed in a greenhouse monitoring system. We cover the physical setup, the math, the code, and how to validate the result.

Scenario: You are deploying 20 DHT22 sensors in a commercial greenhouse. Each sensor will trigger HVAC adjustments, so accuracy matters — a 2°C error could stress plants or waste energy. Your reference instrument is a NIST-traceable digital thermometer accurate to +/-0.1°C.

Step 1: Prepare Reference Points

ReferenceSetupExpected ReadingNotes
Low pointCrushed ice + water slurry in insulated container0.0°C +/- 0.1°CStir continuously, wait 5 min for equilibrium
High pointWarm water bath at greenhouse max temp45.0°C (from reference thermometer)Use 45°C, not 100°C — closer to operating range gives better results

Why 45°C instead of 100°C? The DHT22 operates between 0—50°C in a greenhouse. Calibrating at 100°C (outside operating range) introduces extrapolation error. Always calibrate within or near the expected operating range.

Step 2: Collect Raw Readings

The schedule and drift tools above tell you when to recalibrate. Now we will walk through one complete calibration record for a sensor that actually affects greenhouse control.

Place the DHT22 and reference thermometer side by side in each bath. Wait 3 minutes for the sensor to stabilize, then take 20 readings over 2 minutes:

Data collection should be slow and repeatable:

  1. Put the sensor and reference thermometer in the low bath.
  2. Wait for thermal equilibrium.
  3. Collect 10-20 readings and average them.
  4. Repeat the same process in the high bath.

Example averages: low bath raw value 2.20°C, high bath raw value 43.80°C.

Step 3: Calculate Calibration Coefficients

Using the averaged readings:

  • scale = (45.0 - 0.0) / (43.80 - 2.20) = 1.0817
  • offset = 0.0 - 2.20 * 1.0817 = -2.38
  • Final correction: corrected = raw * 1.0817 - 2.38

Step 4: Apply and Validate

Validate with a third reference point that was not used for calibration:

  • Room reference: 22.5°C.
  • Raw average: 21.45°C.
  • Corrected value: 21.45 * 1.0817 - 2.38 = 20.82°C.
  • Validation error: 1.68°C, which fails a 0.5°C greenhouse tolerance.

This exposes nonlinearity, so the sensor needs multi-point calibration or a better sensor.

The Validation Catch: This is why Step 4 matters. Two-point calibration assumes the sensor error is linear. When validation at a third point reveals significant residual error (>0.5°C for DHT22), you need multi-point calibration instead.

Physics PhoebeCheckpoint: Production Evidence

You now know:

  • A calibration record needs the sensor ID, date, scale, offset, reference instrument, validation error, and next calibration date.
  • The greenhouse example uses 20 DHT22 sensors and chooses 45.0°C because it is inside the operating range.
  • Validation is separate from fitting: 21.45 * 1.0817 - 2.38 = 20.82°C, which misses 22.5°C by 1.68°C.

20.18 Try It: Calibration Validation Checker

After calibrating a sensor, test it against a third reference point to verify accuracy. Enter your calibration coefficients and a validation measurement to determine if your calibration is adequate or if you need a different approach.

Step 5: Store Coefficients in Flash

Save the calibration record, not just the two numbers:

  • Sensor ID: DHT22_GH_014.
  • Date: 2026-02-07.
  • Scale: 1.0817.
  • Offset: -2.38.
  • Reference instrument ID.
  • Validation error and next calibration date.

This makes deployed readings auditable and repeatable.

20.19 Lesson from This Example

The validation step (Step 4) caught a problem that two-point calibration alone would have missed. In production, always validate against a reference point that was NOT used for calibration. If the validation error exceeds your application’s tolerance (here, 0.5°C for greenhouse HVAC), switch to multi-point calibration or select a more linear sensor (e.g., the SHT31 has better linearity than the DHT22).

20.20 Common Calibration Pitfall

Temperature and humidity affect many sensor types beyond the one you are calibrating. A pressure sensor calibrated in a heated lab may behave differently at outdoor deployment temperatures. Always note the ambient conditions during calibration and recalibrate if the deployment environment differs significantly from the calibration environment.

20.21 For Kids: Meet the Sensor Squad!

Temperature Terry was feeling embarrassed. “I keep saying it is 2.3 degrees when it should be zero!” he told the Squad while sitting in a bowl of ice water.

“Do not worry, Sammy!” said the microcontroller. “That is totally normal. Every sensor is a little bit different from the factory. We just need to calibrate you!”

“Cali-what?” asked the LED.

Max explained: “We dip Sammy in ice water — we KNOW that is 0 degrees. If Sammy says 2.3, we learn his offset. Then we dip him in boiling water — we KNOW that is 100 degrees. If Sammy says 98.5, we learn his scale. Now I can do math to fix every future reading!”

the battery pulled out a notebook. “We write down today’s date, what references we used, and the calibration numbers. In six months, we do it again because sensors can drift over time — like a clock that slowly gets behind.”

“And ALWAYS use a reference that is MORE accurate than the sensor you are calibrating,” Max added. “Otherwise, it is like asking someone who is MORE lost for directions!”

20.22 Check: Calibration Errors and Storage

20.23 Try It: Calibration Method Advisor

Describe your sensor scenario and get a recommended calibration approach.

20.24 Match: Calibration Concepts

20.25 Order: Two-Point Calibration Steps

20.26 Label the Diagram

20.27 Code Challenge

20.28 Calibration Decision Guide

Use the guide by fixing the consequence and field access before selecting a method. Low-risk, easily reached equipment may justify a quick one-point correction when validation shows only offset. Industrial or regulated work raises the evidence burden: choose two points when slope is uncertain, and move to multi-point or temperature-compensated calibration when residuals bend across the operating range. Access changes the lifecycle decision as well as the laboratory method; a remote installation may justify more validation and a longer-lived reference record because an early revisit is expensive. After the guide recommends a strategy, compare it with the observed error shape, the reference uncertainty, and the application’s allowable error. The result should be the smallest method that passes independent validation, not automatically the most elaborate curve available.

Physics PhoebeCheckpoint: Choose the Smallest Defensible Method

You now know:

  • One-point calibration is a 2—5 min per sensor fix when only offset is present.
  • Two-point calibration takes 10—15 min per sensor and handles offset plus gain.
  • Multi-point calibration takes 20—30 min per sensor and is justified when nonlinear residuals remain after validation.

20.29 Calibration and Zero-Span

The calculators above show one-point, two-point, and multi-point calibration in the main workflow. Continue to Calibration Taxonomy and Zero-Span Correction when you need to decide which error model is defensible before storing coefficients. That page separates the deeper material: offset versus gain versus curvature, zero-and-span arithmetic, residual checks, overfitting, traceability, hysteresis, and calibration expiry.

20.30 Summary

Key calibration takeaways:

Start with All sensors benefit from calibration - Even factory-calibrated ones. Then One-point for offset - Simple constant correction. Next Two-point for offset + gain - Linear correction. After that Multi-point for nonlinearity - Polynomial or lookup table. Finally Recalibrate regularly - Sensors drift over time.

20.31 Key Takeaway

Sensor calibration should be treated as lifecycle evidence: define the reference, range, correction, uncertainty, drift, and retest trigger before relying on readings.

20.32 Try It Yourself

Beginner: You have a DHT22 that reads 23.8°C while your reference thermometer reads 22.0°C. Calculate the offset and write one line of code to apply it. Then check: if the DHT22 reads 30.5°C, what is the corrected temperature?

Intermediate: Using the MicroPython code from the worked example above, calibrate a sensor with ice water (0°C) and a warm bath (40°C). Your raw readings average 1.5°C at the low point and 38.9°C at the high point. Calculate the scale and offset, then predict the corrected reading if the sensor outputs 25.0°C.

Advanced: An MQ-135 gas sensor gives these readings at known CO₂ concentrations: (400 ppm, raw=120), (800 ppm, raw=280), (1200 ppm, raw=390), (1600 ppm, raw=460), (2000 ppm, raw=505). Plot these points — is the relationship linear? Fit a quadratic polynomial and calculate the predicted concentration when the sensor outputs raw=350.

20.33 Concept Relationships

Core ConceptRelated ConceptsWhy It Matters
Offset ErrorBias, Zero PointConstant shift at all values
Gain ErrorScale Factor, SpanProportional error increasing with reading
NonlinearityPolynomial Fit, Lookup TablesCannot be fixed with two-point calibration
DriftAging, Temperature, Recalibration ScheduleCalibration degrades over time

Common Pitfalls

20.33.1 1. Using Unstable Reference Standards

Calibrating a sensor against a reference that has not been verified against a primary standard propagates the reference’s error into the calibrated sensor. Always trace reference standards to national measurement standards (NIST/NPL) or use certified reference materials.

20.33.2 2. Calibrating Only at One Temperature

A one-point offset calibration at 25 C assumes the offset is constant across the sensor’s range. Many sensors have temperature-dependent offset. Perform calibration at the actual expected operating temperature, or characterize and compensate for the temperature coefficient in firmware.

20.33.3 Allow Warm-Up Before Calibration

Many sensors require a warm-up period (2-30 minutes) for internal electronics to stabilize. Calibrating during warm-up captures an unstable reference reading and produces incorrect coefficients. Always wait for the manufacturer’s recommended stabilization time before taking calibration reference readings.

20.33.4 Reference-Only Validation Risk

Verifying calibration only at the two reference points used to derive the coefficients provides false confidence. Linearity errors are not visible at calibration endpoints. Always verify the calibrated output at 3-5 intermediate values spanning the measurement range.

20.34 What’s Next

If you want to…Read this
Decide which calibration model is defensibleCalibration Taxonomy and Zero-Span Correction
Practice calibration hands-on with an ESP32 simulatorSensor Calibration Lab (Wokwi)
Learn signal filtering to complement calibrationSensor Data Processing
Understand sensor specifications that calibration correctsSensor Specifications
Apply calibration in a complete IoT sensor deploymentSensor Labs: Implementation and Review