Lite / Building Machines That Respond / Week 21
Two-point calibration
Your cheap sensor reads 118 in melting ice and 870 in boiling water. Can two cups of water turn it into a thermometer?
Why should I care?
Real sensors differ from their datasheets and from each other. Calibration measures your actual sensor against things whose values you know, so your machine reports the truth. It is how scientific instruments, kitchen scales and weather stations are kept honest.
- Convert a raw reading to a physical quantity with a two-point calibration.
- Calculate the calibration's slope and offset from two reference points.
- Explain why calibration points should span the range you care about.
Safety: Simulation only. Boiling water scalds: in the apply challenge, use safe reference temperatures and a trusted thermometer instead.
Predict
A sensor reads 100 counts at 0 °C and 900 counts at 100 °C. It now reads 500. Assuming a straight line, what is the temperature?
- 50 °C
- 55.6 °C
- 62.5 °C
Guess first, then reveal
500 is exactly halfway between 100 and 900, so the temperature is halfway between 0 and 100 °C: **50 °C**. The formula gives the same: 100 × (500 − 100) ÷ (900 − 100) = 50.
Discover
Set the ice and boiling readings for your imaginary sensor, then move the new reading. Find the raw reading that means 18 °C. Then drag the new reading below the ice point: what does the readout warn you about?
What the interactive shows (text version)
The calibration diagram plots raw count (0–1023) against temperature. Two green points mark the ice reading at 0 °C and the boiling reading at 100 °C; a straight blue line joins them and extends beyond. Moving the new-reading slider places an orange point on the line and states its temperature, using slope = 100 ÷ (boiling − ice) and T = (reading − ice) × slope. Readings outside the two points are flagged as extrapolation.
Understand
Two known points fix a line
If the sensor is linear, two readings at known values fix its line. Melting ice is close to 0 °C and boiling water about 100 °C at sea level (lower at altitude), which makes them handy references. The slope is the true change divided by the raw change; then any reading converts by T = T₀ + slope × (raw − raw₀).
Interpolate, don't extrapolate
Between the two points (interpolation) the line is usually trustworthy. Beyond them (extrapolation) small curvature in the real sensor grows into big errors. So choose reference points that bracket the range you care about: for a greenhouse, perhaps 5 °C and 35 °C rather than 0 and 100.
Calibration in firmware
Store the two raw readings, measured once per sensor, and convert every reading:
R0, R1 = 118, 870 # measured in ice and boiling water
def temp_c(raw):
return 100 * (raw - R0) / (R1 - R0)Record the date and method in your notebook: a calibration is evidence.
Explain it another way
Intuitive
You know two places on a map exactly. Draw a straight road between them and you can locate anything along it.
Technical
Two-point calibration corrects offset and gain (slope) errors. Nonlinear sensors need multi-point calibration or a lookup table. Reference conditions (pressure for boiling point, purity of ice) set the calibration's own uncertainty.
Mathematical
T = T₀ + (T₁ − T₀)(r − r₀)/(r₁ − r₀). Rearranged into y = mx + c: m = (T₁ − T₀)/(r₁ − r₀), c = T₀ − m·r₀.
Applied
Kitchen scales calibrate with a known mass; pH meters with two buffer solutions; weather stations against a reference thermometer. Each stores numbers like R0 and R1 in memory.
Derivation: The line through two points
Reference points: raw r₀ at true T₀, raw r₁ at true T₁ (here T₀ = 0 °C, T₁ = 100 °C).
Slope: m = (T₁ − T₀) ÷ (r₁ − r₀) degrees per count. For r₀ = 118, r₁ = 870: m = 100 ÷ 752 ≈ 0.1330 °C per count.
Any reading: T = T₀ + m × (r − r₀).
Example: r = 450 → T = 0 + 0.1330 × (450 − 118) = 0.1330 × 332 ≈ 44.1 °C.
Check the ends: r = 118 gives 0 °C and r = 870 gives 100 °C, as they must.
Worked example 1
Ice reads 92 counts, boiling reads 868. A reading of 310: what temperature?
Slope = 100 ÷ (868 − 92) = 100 ÷ 776 ≈ 0.1289 °C per count. T = (310 − 92) × 0.1289 ≈ 28.1 °C.
Common mix-ups
Calibration makes a sensor perfect.
✓ It removes offset and slope errors at the calibration points. Noise, drift and curvature remain.Water always boils at 100 °C.
✓ Only at sea-level air pressure. Up a mountain it boils at a lower temperature, which shifts your calibration.
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Design a calibration procedure for the greenhouse sensor: which two reference temperatures, how you would produce them safely without boiling water (for example a fridge and a warm room measured with a trusted thermometer), how many readings you would average at each, and what you would write in your notebook.
Reflect
What would you check, a month later, to know whether your calibration had drifted?
Write your answer on paper or in your own notes. Lite never stores what you write.