← IGCSE Computer Science Paper 1

Comparing a sensor reading with a stored value

A pre-set value, such as a target temperature, kept in the microprocessor. It compares each digital sensor reading with it to decide if the reading is too high, too low or on target.

Understanding Comparing a sensor reading with a stored value in IGCSE Computer Science Paper 1

What it does: The stored value is set by the designer. Here it is held in a variable called targetTemp and the program compares each reading with it. 18 is lower than the target of 22, so the reading is too low. The microprocessor would switch the heater on. The microprocessor runs a stored program of instructions. The actuator only carries out the action it is told to do. The readings are compared continuously, so the system can respond whenever the reading drifts away from the target.

Common mistakes: The stored value is pre-set by the designer, so it must be a fixed number such as 22. It must not be copied from the sensor reading. The line should be target ← 22. The reading 25 is higher than the stored value 22, so the room is too hot. The microprocessor should switch the cooler on, not the heater. The line should be OUTPUT "Cooler on".

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 553–577) and word search (Modules 553–607).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
What does the microprocessor compare each digital sensor reading with?
A stored (pre-set) value, such as a target temperatureThe reading from the previous day
Matches
IF 18 > 22 THEN heater ON
↓
18 is not greater than 22. The reading is too low, so the comparison should use < to match the heater being turned on.
Applying
Meanings
Term
stored value
Meaning
A pre-set value, such as a target temperature, kept in the microprocessor. It compares each digital sensor reading with it to decide if the reading is too high, too low or on target.
Practice
storedValue ← 22
Testing
Gaps
IF reading target THEN heateron
Check Answer
Spots
1target ← reading
2reading ← 18

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Snowy Owl' badge — List Slicer, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. What does the microprocessor compare each digital sensor reading with?
A. A stored (pre-set) value, such as a target temperature ✓
B. The reading from the previous day
The microprocessor compares each digital reading with a stored value (the target) to decide what to do next.
2. Who normally chooses the stored value, such as the target temperature of 22 °C?
A. The sensor works it out by itself
B. The designer of the system sets it in advance ✓
The stored value is set by the designer or user beforehand. A sensor only measures; it does not decide the target.
3. A heating system has a stored value of 22 and the sensor reading is 18. What is the result of the comparison?
A. The reading is too low ✓
B. The reading is too high
18 is lower than the target of 22, so the reading is too low. The microprocessor would switch the heater on.
4. A cooling system has a stored value of 22 and the sensor reading is 27. What does the microprocessor find?
A. The reading is too high, so it turns the cooling on ✓
B. The reading is on target, so it does nothing
27 is higher than 22, so the reading is too high. The microprocessor sends a signal to switch the cooling on.
5. The stored value is 22 and the sensor reading is 22. What does the microprocessor do?
A. It switches the heater on because the readings match
B. Nothing changes because the reading is on target ✓
When the reading equals the stored value, it is on target, so no change is needed.

Match the Pairs

IF reading < 22 THEN heater ON → The microprocessor sees the reading is below the stored value, so it switches the heater on
IF reading > 22 THEN heater OFF → The microprocessor sees the reading is above the stored value, so it switches the heater off
The designer sets the target temperature once. The microprocessor keeps it as a stored value. → targetTemp <- 22
Worked example: a reading of 18 is compared with a stored value of 22. It is too low, so the heater turns on. → IF 18 < 22 THEN heater ON
IF 18 > 22 THEN heater ON → 18 is not greater than 22. The reading is too low, so the comparison should use < to match the heater being turned on.
IF reading = 22 THEN heater ON → A reading equal to the stored value is on target, so the heater should not be switched on. The heater should come on when the reading is too low (< 22).

Key Term

stored value
A pre-set value, such as a target temperature, kept in the microprocessor. It compares each digital sensor reading with it to decide if the reading is too high, too low or on target.

Fill in the Blanks

1. target ← 22 reading ← 18 IF reading < target THEN heater_on
Hint: Type the comparison operator that checks whether the reading is too low.
2. target ← 22 reading ← 25 IF reading > target THEN cooler_on
Hint: Type the comparison operator that checks whether the reading is too high.
3. IF reading = target THEN OUTPUT "On target"
Hint: Type the operator that checks whether the reading is exactly equal to the stored value.
4. target ← 22 IF reading < target THEN heater ← ON
Hint: Type the variable name that holds the stored value the reading is compared with.
5. // Designer sets target to 22 target ← 22 IF reading < target THEN heater_on
Hint: Type the number for the stored target value that the comment says the designer chose.

Spot the Error

Question 1
A target ← reading
B reading ← 18
C IF reading < target THEN
D OUTPUT "Heater on"
E ENDIF
Line A — The stored value is pre-set by the designer, so it must be a fixed number such as 22. It must not be copied from the sensor reading. The line should be target ← 22.
Question 2
A target ← 22
B reading ← 25
C IF reading > target THEN
D OUTPUT "Heater on"
E ENDIF
Line D — The reading 25 is higher than the stored value 22, so the room is too hot. The microprocessor should switch the cooler on, not the heater. The line should be OUTPUT "Cooler on".
Question 3
A target ← 22
B reading ← target
C IF reading = target THEN
D OUTPUT "On target"
E ENDIF
Line B — The reading must come from the sensor. Copying the stored value into reading means the comparison is always 'on target'. The line should be reading ← READ sensor.
Question 4
A IF reading < target
B OUTPUT "Heater on"
C ELSE
D OUTPUT "Heater off"
E ENDIF
Line A — The IF statement is missing the keyword THEN. The line should be IF reading < target THEN.
Question 5
A REPEAT
B READ sensor ← reading
C IF reading < target THEN
D OUTPUT "Heater on"
E ENDIF
F UNTIL system off
Line B — The assignment arrow is the wrong way round. The value from the sensor must be stored in the variable reading. The line should be reading ← READ sensor.

Student with a class code? Join your class →