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:
- When the surroundings are bright, the number grows.
- When the surroundings are dark, the number shrinks.
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:
- Cover the sensor with your hand (dark). Read the number and write it down.
- 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:
- The season shifts and daylight fades.
- Dust settles on the sensor, so it sees less light.
- You move the device to another room.
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.
- Read the sensor in the dark, write the value on paper.
- Read the sensor in bright light, write the value on paper.
- Take the average of the two values; that is your threshold.
- Calculate 15 below and 15 above the threshold.
- 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
- This lesson uses only low-voltage educational sources: a battery, USB, micro:bit or Arduino. No activity uses mains (wall socket) electricity.
- When holding the light sensor toward a lamp, do not touch hot bulbs; LED lamps are safer.
- Do not point the sensor straight at the sun for a long time or dazzle your eyes; a short moment is enough for a reading.
- Cut the board’s power before changing any connections. Do not yank the cables; plug them in properly.
- Do all circuit work together with an adult.
Review questions
- What does calibration compare a sensor reading against?
- Why is one calibration point often insufficient?
- How do offset and scale errors differ?
- What environmental changes can invalidate a previous calibration?
- Why should calibration data be kept separate from raw measurements?
- What record makes a calibration repeatable?
Answers
- It compares the device output with a reference value or known condition.
- A sensor can behave differently across its range, so several points reveal non-linearity and scale error.
- An offset shifts all readings by a similar amount; a scale error changes how strongly readings respond across the range.
- Temperature, supply voltage, sensor placement, ageing, moisture and mechanical movement can change behaviour.
- Raw data preserves evidence; calibrated values are a transformation that should be reproducible and reversible.
- Record the reference, equipment, environment, points measured, formula, date, uncertainty and person performing the procedure.
Lesson summary
- Calibration matches a raw sensor value to a real-world meaning or to a correct threshold.
- A raw value carries no meaning on its own; the same number means different things in different environments.
- The threshold is set by taking the average of the lowest and highest measurement.
- A margin (two thresholds) stops the output from flickering at the boundary.
- Old calibration breaks when the environment changes; good projects leave a path for recalibration.
Check your understanding
- Explain briefly what calibration means.
- Why is a raw value not enough information on its own?
- If the dark reading is 40 and the bright reading is 200, what is the simplest threshold?
- What is the purpose of using a low and a high threshold instead of a single one?
- Why might moving a device to a new room require recalibration?
Answers
- 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.
- 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.
- threshold = (40 + 200) / 2 = 120.
- 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.
- 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.