Calibration

Learn calibration: adjusting a sensor's values to a threshold that matches the real world.

LESSON COMPASS

What will you use this page for?

Core idea

Calibration means tying the raw number a sensor gives you to a real-world meaning, and finding the right decision thresholds by measuring them in your own environment.

Evidence to produce

Complete the page task with your own input, test conditions and reasoning.

Control trap

Setting the threshold by guessing Weak: “100 is probably a good number.” Better: Measure the dark and bright values and take their average. Using a single threshold and being surprised by flicker With one threshold, the output can switch on and off when the light is near the boundary. A low and a high threshold (a…

Next connection

Project: Automatic Night Light — Using the light sensor you calibrated, you will build a real night-light circuit that turns itself on when it gets dark.

Module sources: Python Tutorial · Arduino Learn

LevelBeginner
Age10–16
Duration30–45 min
PrerequisiteFiltering Sensor Data
ContentStandard lesson · 1,487 words
Last updated

One-sentence summary

Calibration means tying the raw number a sensor gives you to a real-world meaning, and finding the right decision thresholds by measuring them in your own environment.

Why it matters

A light sensor never says “bright” or “dark.” It only gives you a number, for example a value between 0 and 255. That number means nothing on its own. Is 120 bright or dark? The answer depends on the room, the time of day and the type of sensor.

A program written without calibration works incorrectly in a different room. A night light that behaves nicely at home might stay on all the time at school. Every space has its own light, and the numbers the sensor sees are different too.

Think of a thermometer. The sensor inside it actually measures an electrical value. The manufacturer has adjusted that value so it means “degrees.” That adjustment is calibration. We are going to learn to make a similar adjustment for our own sensors.

Short definition: Calibration is the process of matching a raw sensor value to a real-world value or to a correct threshold.

Raw value versus real meaning

What is a raw value?

While a sensor is connected to the board, it keeps producing a number. We call this the raw value. A raw value is a measurement that has not been processed, converted or interpreted.

For a light sensor, the raw value usually behaves like this:

But this behaviour is not the same on every sensor. On some sensors the number grows in the dark. That is why you should measure instead of memorise.

Why is using a number directly not enough?

Suppose you wrote “if the raw value is below 100, turn on the lamp.” Where did that 100 come from? A guess. In another room the dark value might be 40 and the bright value 90. Then your lamp would never turn on.

Everyday example: If you tell a friend “set the volume to 100,” the 100 on their phone may not be as loud as the 100 on yours. Same number, different meaning. Calibration closes that gap.

Measuring min–max and setting a threshold

Step 1: Measure the lowest and highest value

The heart of calibration is simple: you try the sensor in two extreme situations and note the smallest and largest number you see.

For a light sensor:

  1. Cover the sensor with your hand (dark). Read the number and write it down.
  2. Hold the sensor toward a lamp or window (bright). Read the number and write it down.

Say your measurements come out like this:

Dark reading   = 30
Bright reading = 210

Step 2: Calculate the threshold

A threshold is the boundary number where a decision flips. Below it we do one thing, above it another. The simplest threshold is the middle of the lowest and highest value.

threshold = (dark + bright) / 2
threshold = (30 + 210) / 2
threshold = 120

Now the number 120 carries a real meaning for your room: below 120 counts as dark, above it counts as bright.

The whole logic as pseudocode:

Start
dark   = value read while covered
bright = value read while lit
threshold = (dark + bright) / 2

Repeat forever
  light = read the sensor
  If light < threshold
    "Dark" state
  Otherwise
    "Bright" state

Step 3: Add a margin (hysteresis)

If the threshold is a single sharp line, the number can flicker between 119 and 121 when the light sits right at the edge, and the lamp switches on and off rapidly. To prevent this we use two thresholds: a little below and a little above.

low_threshold  = threshold - 15
high_threshold = threshold + 15

If light < low_threshold
  turn the lamp on
If light > high_threshold
  turn the lamp off

Everyday example: An automatic door works the same way. To avoid opening and closing endlessly when you stand right at the edge, it keeps its opening and closing limits slightly apart.

Recalibrating when the environment changes

Calibration is not something you do once and forget. When the environment changes, the values change too:

That is why good projects leave a path for recalibration. For example, the device has a button; pressing it makes the device measure for a few seconds and store new min–max values.

If the calibration button is pressed
  read the sensor for 3 seconds
  store the smallest and largest value
  recalculate the threshold

Everyday example: A phone’s automatic screen brightness. When you walk into a dark room, the phone readjusts itself. It keeps measuring and adapts to the environment.

Mini practice

Imagine a light sensor and a micro:bit or Arduino-style board. Your task: correctly calibrate a circuit that lights an LED when it gets dark.

  1. Read the sensor in the dark, write the value on paper.
  2. Read the sensor in bright light, write the value on paper.
  3. Take the average of the two values; that is your threshold.
  4. Calculate 15 below and 15 above the threshold.
  5. Fill in the pseudocode below with your own numbers.
dark   = ____
bright = ____
threshold = (dark + bright) / 2
low  = threshold - 15
high = threshold + 15

Repeat forever
  light = read the sensor
  If light < low
    turn the LED on
  If light > high
    turn the LED off

Then test the sensor under different light. Are the values what you expected? If not, repeat the min–max measurement. It is normal not to get it right on the first try; measuring and correcting is part of the work.

Common mistakes

Setting the threshold by guessing

Weak: “100 is probably a good number.” Better: Measure the dark and bright values and take their average.

Using a single threshold and being surprised by flicker

With one threshold, the output can switch on and off when the light is near the boundary. A low and a high threshold (a margin) prevent this flicker.

Calibrating once and forgetting

When the room, the season or the dust on the sensor changes, the old threshold becomes wrong. Leave a recalibration path in the device.

Confusing the sensor’s direction

On some sensors the number grows in the dark, on others it shrinks. Do not memorise; measure and see for yourself which way it works.

Safety note

Review questions

  1. What does calibration compare a sensor reading against?
  2. Why is one calibration point often insufficient?
  3. How do offset and scale errors differ?
  4. What environmental changes can invalidate a previous calibration?
  5. Why should calibration data be kept separate from raw measurements?
  6. What record makes a calibration repeatable?

Answers

  1. It compares the device output with a reference value or known condition.
  2. A sensor can behave differently across its range, so several points reveal non-linearity and scale error.
  3. An offset shifts all readings by a similar amount; a scale error changes how strongly readings respond across the range.
  4. Temperature, supply voltage, sensor placement, ageing, moisture and mechanical movement can change behaviour.
  5. Raw data preserves evidence; calibrated values are a transformation that should be reproducible and reversible.
  6. Record the reference, equipment, environment, points measured, formula, date, uncertainty and person performing the procedure.

Lesson summary

Check your understanding

  1. Explain briefly what calibration means.
  2. Why is a raw value not enough information on its own?
  3. If the dark reading is 40 and the bright reading is 200, what is the simplest threshold?
  4. What is the purpose of using a low and a high threshold instead of a single one?
  5. Why might moving a device to a new room require recalibration?

Answers

  1. Calibration is the process of matching the raw number a sensor gives to a real meaning or a correct threshold. We measure the sensor in its own environment and adjust.
  2. Because the same number means different things in a different room, at a different time and on a different sensor. The meaning only appears through measurement.
  3. threshold = (40 + 200) / 2 = 120.
  4. Leaving a gap between two thresholds (a margin/hysteresis) stops the output from switching on and off rapidly, that is flickering, when the light is near the boundary.
  5. The new room has different light; the old min–max values no longer apply, so the threshold can make wrong decisions and you need to measure again.

Source and verification note

For “Calibration”, verification focuses on whether the relationship between Raw value versus real meaning and Why is using a number directly not enough? remains consistent across examples. Sensor readings can change with the model, supply voltage and environment. Thresholds in the lessons are therefore examples; a real project should use a measurement table and calibration.

Next lesson

Project: Automatic Night Light — Using the light sensor you calibrated, you will build a real night-light circuit that turns itself on when it gets dark.

Start QuizBack to Sensors and Actuators
QUESTION POOL

Reinforce this lesson with 10 questions

This lesson has a pool of 20 questions. Each attempt selects 10 and reshuffles the choices.