20 Sensor Calibration Techniques
More
Depth: Practitioner
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
20.1 Start With the Measurement Story
This section: Start With the Measurement Story — Calibration is the moment a sensor reading becomes accountable.
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.
Watch the probe move from a reference bath to the plotted correction. The strip asks whether a tidy output number still agrees with a known physical input.
-
A sensor reading is compared with a known reference.
-
Without that check, its error can hide inside a clean number.
-
Measure the error, correct the raw link, and repeat the test.
-
Keep the correction only while fresh evidence shows it still holds.
A sensor reading is compared with a known reference, then checked again. The repeat check tests whether the calibration result holds for this example.
The first panel puts a probe in a known bath beside a measurement display. The next shows that its plotted readings can sit off the reference line. The third compares the probe with the reference again; the last shows a corrected line kept inside a checked band. The steps below explain how to record the reference, correction, and repeat test. A clean line is evidence only for the conditions actually tested.
20.2 In 60 Seconds
This section: In 60 Seconds
This chapter has four practical stops:
- First identify the error shape: offset, gain, nonlinearity, noise, or drift.
- Then choose the lightest defensible correction: one-point, two-point, or multi-point calibration.
- Next store the coefficients with evidence, schedule recalibration, and account for drift.
- 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
This section: Key Concepts
- Calibration: the process of comparing a sensor’s output against a known reference standard and applying correction factors to make readings accurate.
- 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.
- 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.
- 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.
- Two-Point Calibration: a calibration technique using two reference values to simultaneously correct offset and gain errors across a defined measurement range.
- Reference Standard: a known, traceable measurement source (ice-water bath at 0°C, boiling water at a temperature determined by local altitude and pressure, certified weights) used as ground truth during calibration.
- 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.
- 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
This section: 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
This section: 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
This section: Prerequisites
- Sensor Specifications: Accuracy vs precision
- Signal Processing: Understanding sensor errors
20.6 Every Sensor Needs Calibration
This section: Every Sensor Needs Calibration — Even the best sensors have manufacturing variations.
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 Type | Description | Fixable with Calibration? |
|---|---|---|
| Offset (Bias) | Constant error at all values | Yes - one-point calibration |
| Gain (Scale) | Error proportional to reading | Yes - two-point calibration |
| Nonlinearity | Curved error across range | Partially - multi-point calibration |
| Noise | Random variation | No - requires filtering |
| Drift | Error changes over time | Requires periodic recalibration |
Checkpoint: 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
This section: One-Point Offset Calibration — When to use: Sensor reads consistently high or low by a fixed amount.
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 CalculatorTry: One-Point Offset Calculator
20.8 Two-Point Offset and Gain
This section: Two-Point Offset and Gain — When to use: Sensor has both offset error AND scale error.
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
This section: Putting Numbers to It
Two-point calibration corrects both gain and offset errors. Let = reference (true) value and = 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
This section: Practical Calibration References — We just used one and two reference points to correct simple errors.
| Measurement | Reference | Accuracy | Notes |
|---|---|---|---|
| Temperature | Ice water (0°C) | +/-0.1°C | Use crushed ice, stir |
| Temperature | Boiling water (100°C*) | +/-0.5°C | *Altitude dependent |
| Temperature | Room thermometer | +/-0.5°C | Use NIST-traceable reference |
| Humidity | Saturated salt (75.3% RH) | +/-0.5% | Sodium chloride (NaCl) solution |
| Humidity | Saturated salt (32.8% RH at 25°C) | +/-0.5% | Magnesium chloride (MgCl₂) |
| Pressure | Weather station data | +/-1 hPa | Compare with local airport |
| Distance | Tape measure | +/-1mm | Fixed 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
This section: Multi-Point Calibration — When to use: Sensor has nonlinear response that two-point calibration cannot correct (as demonstrated in the worked example below).
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:
- Record several pairs: known reference value and raw sensor reading.
- Fit a polynomial or create a lookup table from those pairs.
- Copy only the final coefficients or table into the microcontroller.
- 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
This section: Polynomial Calibration Explorer
20.13 Storing Calibration Data
This section: 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
This section: Best Practices for Sensor Calibration
20.14.1 Calibration Checklist
- Document everything: Date, reference instrument, environmental conditions, coefficients.
- Use stable conditions: Allow sensor to warm up (30 min for gas sensors), avoid drafts.
- Average multiple readings: Take 10—20 readings at each calibration point to reduce noise.
- Use accurate references: Your reference must be more accurate than your sensor.
- Verify after calibration: Validate against a third reference NOT used in calibration.
- Recalibrate periodically: Follow the schedule guidelines below for your sensor type.
- Store coefficients safely: Non-volatile memory (EEPROM/flash) with backup.
- Avoid overfitting: Too many polynomial terms can amplify noise between calibration points.
20.15 Calibration Schedule Guidelines
This section: Calibration Schedule Guidelines — Read the schedule as a set of starting intervals modified by exposure and consequence.
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 Type | Recommended Interval | Trigger Events |
|---|---|---|
| Temperature | Every 6 months | After shipping, extreme temps |
| Humidity | Every 3 months | After high humidity exposure |
| Pressure | Every 12 months | After altitude changes |
| Gas sensors | Every 3-6 months | After contamination |
| pH sensors | Before each use | After storage |
| Load cells | Every 12 months | After overload events |
This section:
Checkpoint: 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.034and offset-1.86.
20.16 Try It: Calibration Drift EstimatorTry: Calibration Drift Estimator
This section: Try It: Calibration Drift Estimator
20.17 ESP32 Two-Point Calibration
This section: ESP32 Two-Point Calibration — This example walks through an illustrative calibration procedure for a DHT22 temperature sensor in a greenhouse monitoring scenario.
This example walks through an illustrative calibration procedure for a DHT22 temperature sensor in a greenhouse monitoring scenario. 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
| Reference | Setup | Expected Reading | Notes |
|---|---|---|---|
| Low point | Dry, temperature-controlled air near 0.0°C; measure the air beside the DHT22 with the reference probe | 0.0°C +/- 0.1°C | Allow air to circulate, wait 5 min for equilibrium |
| High point | Dry, temperature-controlled air near 45.0°C; measure the air beside the DHT22 with the reference probe | 45.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? This greenhouse needs 0—50°C readings, and 100°C is outside both that application range and the DHT22’s specified temperature range. Use references that bracket the intended operating range; a correction fitted outside it may extrapolate poorly.
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 air-temperature probe side by side in dry, temperature-controlled air at each measured setpoint. Do not immerse the DHT22; wait until both air readings stabilize, then take 20 readings over at least 2 minutes.
Data collection should be slow and repeatable:
- Put the sensor and reference thermometer in the low-temperature air chamber.
- Wait for thermal equilibrium.
- Collect 10-20 readings and average them.
- Repeat the same process in the high-temperature air chamber.
Example averages: low-temperature air raw value 2.20°C, high-temperature air raw value 43.80°C.
Step 3: Calculate Calibration Coefficients
Using the averaged readings:
scale = (45.0 - 0.0) / (43.80 - 2.20) = 1.0817offset = 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.
This section:
Checkpoint: 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 CheckerTry: Calibration Validation Checker
This section: Try It: Calibration Validation Checker
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
This section: 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
This section: 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!
This section: 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 StorageCheck your understanding: Calibration Errors and Storage
This section: Check: Calibration Errors and Storage
20.23 Try It: Calibration Method AdvisorTry: Calibration Method Advisor
This section: Try It: Calibration Method Advisor
20.24 Match: Calibration Concepts
This section: Match: Calibration Concepts
20.25 Order: Two-Point Calibration Steps
This section: Order: Two-Point Calibration Steps — The ice-water and warm-bath examples below apply to immersion-rated temperature probes.
The ice-water and warm-bath examples below apply to immersion-rated temperature probes. For the DHT22 above, place it and the reference air probe together in dry, temperature-controlled air.
20.26 Label the Diagram
This section: Label the Diagram
20.27 Code Challenge
This section: Code Challenge
20.28 Calibration Decision Guide
This section: Calibration Decision Guide — Use the guide by fixing the consequence and field access before selecting a method.
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.
This section:
Checkpoint: 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
This section: Calibration and Zero-Span — The calculators above show one-point, two-point, and multi-point calibration in the main workflow.
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
This section: Summary
Key calibration takeaways:
- All sensors benefit from calibration - Even factory-calibrated ones.
- One-point for offset - Simple constant correction.
- Two-point for offset + gain - Linear correction.
- Multi-point for nonlinearity - Polynomial or lookup table.
- Recalibrate regularly - Sensors drift over time.
20.31 Key Takeaway
This section: 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
This section: 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
This section: Concept Relationships
| Core Concept | Related Concepts | Why It Matters |
|---|---|---|
| Offset Error | Bias, Zero Point | Constant shift at all values |
| Gain Error | Scale Factor, Span | Proportional error increasing with reading |
| Nonlinearity | Polynomial Fit, Lookup Tables | Cannot be fixed with two-point calibration |
| Drift | Aging, Temperature, Recalibration Schedule | Calibration degrades over time |
Common Pitfalls
This section: 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
This section: What’s Next
Find help
3 reviewed answers.
Where should I start in a module?
Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.
Modules and pathsReviewed
What can I try when a project does not work?
Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.
When you are stuckReviewed
How do interactive examples work?
Use the interactive guide to check how examples and simulations work before changing your project.
Interactive examples guideReviewed
