Table of Contents
KEY TAKEAWAYS
- Calibration maps raw sensor readings to known reference values, correcting for offset and gain errors.
- Single-point calibration corrects offset only; two-point calibration corrects both offset and gain.
- Store calibration coefficients in EEPROM or flash so they persist across power cycles.
- Digital sensors come factory-calibrated but may still need field calibration for highest accuracy.
Part of the Complete Guide to Sensors for Embedded Systems series.
A sensor is only as good as its calibration. Even factory-calibrated sensors can drift over time, and analog sensors always need user calibration. This article covers practical calibration techniques you can implement in your embedded firmware — from simple offset correction to multi-point polynomial fitting.
Why Calibration Matters
Every sensor has two types of errors. Offset error is a constant shift: the sensor reads 2°C too high at every temperature. Gain error is a scaling problem: the sensor reads correctly at 0°C but is 5% off at 100°C. Without calibration, these errors compound and make your readings unreliable.
Manufacturing tolerances cause initial errors. Aging, contamination, and mechanical stress cause drift over time. Environmental factors (temperature, humidity, vibration) affect sensor behavior. Calibration measures these errors against known references and corrects them in firmware.
For a weather station displaying room temperature, ±1°C error might be acceptable. For an industrial process controlling a chemical reaction, ±0.1°C matters. For a medical thermometer, calibration is a regulatory requirement. Know your application’s accuracy requirements before deciding how much effort to invest in calibration.
Single-Point Calibration
The simplest technique: measure one known reference and apply a constant offset.
Place your temperature sensor in a known environment — for example, an ice-water bath at exactly 0°C. If the sensor reads 0.7°C, your offset is -0.7°C. In firmware, subtract 0.7 from every reading.
This corrects offset error but not gain error. The correction is only accurate near the calibration point. At 100°C, the true error might be different. For many applications (room temperature monitoring, relative humidity), single-point calibration is sufficient.
Implementation: read the raw sensor value at the reference point, calculate the offset (reference_value – raw_value), store the offset in EEPROM, and apply it to every subsequent reading: corrected = raw + offset.
Two-Point Calibration
Two-point calibration corrects both offset and gain errors by measuring two known reference points and computing a linear correction.
For a temperature sensor, use ice water (0°C) and boiling water (100°C, adjusted for altitude). Record the raw sensor readings at both points: raw_low and raw_high. The corrected reading is:
corrected = (raw – raw_low) × (ref_high – ref_low) / (raw_high – raw_low) + ref_low
This is equivalent to calculating slope (gain correction) and intercept (offset correction) of a linear equation. Two-point calibration is accurate for sensors with linear or near-linear transfer functions — which includes most modern temperature and pressure sensors.
Store both raw_low and raw_high (or the calculated slope and intercept) in EEPROM. Provide a firmware calibration mode that walks the user through the process: “Place sensor in reference 1, press button. Place sensor in reference 2, press button.”
Multi-Point and Polynomial Calibration
For highly nonlinear sensors (NTC thermistors, some pressure sensors), two points are insufficient. Multi-point calibration measures 5-10 reference points across the full range and fits a polynomial curve.
A quadratic fit (y = ax² + bx + c) requires at least 3 points. A cubic fit (y = ax³ + bx² + cx + d) requires at least 4 points. Least-squares fitting minimizes the total error across all calibration points.
For NTC thermistors, the Steinhart-Hart equation is a well-known calibration model: 1/T = A + B×ln(R) + C×(ln(R))³. You measure resistance at three known temperatures, solve for coefficients A, B, C, and store them. This provides ±0.01°C accuracy across a wide range.
Alternative: use a lookup table with linear interpolation between points. Store raw-to-calibrated value pairs in flash memory. For each reading, find the two nearest entries and interpolate. This avoids floating-point math — important on 8-bit microcontrollers without FPU.
Implementing Calibration in Firmware
A practical calibration system needs: a calibration mode (triggered by button press or serial command), reference value input (keypad, serial terminal, or preset values), EEPROM storage for coefficients, and automatic application of correction to every reading.
Store calibration data in a struct with a magic number (version marker) so firmware can detect if calibration has been performed. If the magic number is absent, use default factory values.
For production devices, calibration happens on the manufacturing line. A test fixture exposes each unit to known references, the firmware enters calibration mode, coefficients are computed and stored, and a “calibrated” flag is set. End users should not normally need to recalibrate unless the sensor drifts significantly.
Best practice: add a checksum to calibration data so corrupted EEPROM values are detected. If the checksum fails, fall back to defaults and flag an error.
📖 Related: Analog vs Digital Sensors in Embedded Systems • Pressure Sensors for Embedded Systems: Types, Selection, and Interfacing
Going further: Before calibrating, clean the raw readings — see Filtering Noisy ADC Readings for the standard embedded filters.
Going further: For a worked example with real Instron data and a rubber-pad mount that fixes repeatability, see our FlexiForce sensor calibration guide.

Vivek Bhageria — Lead Firmware R&D Engineer, 12+ years. Ex-Bosch (automotive powertrain), MusicTribe (real-time audio), medical devices. M.Tech BITS Pilani. I write at NerdyElectronics — practical, register-level embedded systems for engineers who want to understand what’s actually happening under the hood.



