GRADE 7 · COMPUTING · UNIT 2 · LESSON 2.6
Decomposing problems: Creating a smart solution
Using sensors in programming
Read a little. Try the workbook. Check your answers. Choose one section below to get started.
LET’S TRACE, REASON AND TEST
Using sensors in programming
Sensors provide readings that a program can test. A light level is numeric, while a touch or gesture predicate can return True or False. A loop can obtain a fresh reading on each pass, choose a branch and repeat. A classroom alarm model is not a certified security system.
- Identify sensor inputs and explain how a condition selects an output.
- Predict both branches of the light-level flowchart for the supplied inputs.

Explore the clues
Tap one card to find out more.
Understand the idea
Sensors provide readings that a program can test. A light level is numeric, while a touch or gesture predicate can return True or False. A loop can obtain a fresh reading on each pass, choose a branch and repeat. A classroom alarm model is not a certified security system.
Concept to practise: Using sensors in programming.
Work through an example
For level < 100, a reading of 67 takes the true branch and 130 takes the false branch. The value 100 also takes the false branch because it is not less than 100. Output depends on the exact comparison.
Try before your workbook
A loop checks level < 100 and shows an image only on the true branch. What happens at 99 and at 100? Why must the sensor be read again?
Check my readiness thinking
99 selects the true branch; 100 selects the false branch. Re-reading allows the next loop to respond to changed conditions instead of repeatedly testing an old stored reading.
Your original programs and learning models
These original PaxaKids program and data models support your workbook. Some examples deliberately contain faults to investigate. Follow their headings and preserve exact code case, punctuation and order. Traces and supplied records are not claims of physical testing.
Let a sensor supply the input
A sensor measures a physical condition. A program tests a condition using that input and chooses an output. Our model is a classroom demonstration, not a complete security system.
Know which result the API returns
| Input / feature | Example MicroPython API | Result here |
|---|---|---|
| Light via LED display | display.read_light_level() | integer, 0–255 |
| Processor temperature | temperature() | integer degrees C |
| V2 logo touch | pin_logo.is_touched() | Boolean |
| Movement gesture | accelerometer.was_gesture("shake") | Boolean |
| V2 microphone | microphone.sound_level() | integer, 0–255 |
Read the intended light-response loop
Decision: level < 100?
True branch
- Show CHESSBOARD
- Play BA_DING
False branch
- Clear display
Trace readings on both sides
| Reading | Test to evaluate |
|---|---|
| 67 | 67 < 100 |
| 130 | 130 < 100 |
| 100 | 100 < 100 |
Find the mismatch in a runnable starter
ORIGINAL FAULTY LIGHT PROGRAM
from microbit import *
import music
while True:
level = display.read_light_level()
if level > 100:
display.show(Image.CHESSBOARD)
music.play(music.BA_DING)
else:
display.clear()
sleep(100)Compare a touch plan with its code
FAULTY TOUCH FRAGMENT: V2 ONLY
from microbit import *
import music
if pin_logo.is_touched:
display.show(Image.SURPRISED)
music.play(music.BADDY)
Try one step with Paxa!
Use the API for the chosen editor. Label paper traces, simulator runs and physical tests accurately; ask a grown-up before connecting equipment. Save personal responses before leaving.
Our Unit 2 learning path
- Lesson 2.1: All about software
- Lesson 2.2: Introducing the micro:bit
- Lesson 2.3: Using Python with the micro:bit
- Lesson 2.4: The micro:bit Python environment
- Lesson 2.5: Correcting errors using a flowchart
- Lesson 2.6: Using sensors in programming
- Lesson 2.7: Flowcharts for algorithm planning
- Lesson 2.8: Algorithmic solutions and data types
- Lesson 2.9: Planning a smart solution
- Lesson 2.10: Effective testing
- Lesson 2.11: Evaluating a program
- Lesson 2.12: Testing accelerometer gestures
- Lesson 2.13: Protecting a museum crown
- Lesson 2.14: Final project
- Lesson 2.15: Evaluation
- Lesson 2.16: What can you do?
For grown-ups: using this lesson
Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.
Read one explanation, discuss the model and try the readiness check before the workbook. Choose “Mark lesson finished” when ready. Optional account progress saves lesson position and completion across devices; save personal responses before leaving.
2. Fill in your workbook
Read the teaching and the complete workbook instructions. Choose, write or draw; Answer list offers larger controls. Trace code precisely and distinguish predictions from actual tests. Review designs, explanations and drawings with a grown-up.
Opening your PDF…
Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.
You’ve completed the checked activities.
TAKE YOUR PRACTICE OFFLINE
3. Download the student worksheet
All 8 original A4 student pages, ready for pencil-and-paper practice. Choose Review Answers to check your work on this webpage.
Student worksheet only · PDF · 8.3 MiB · No answer key included
TRY FIRST, THEN CHECK TOGETHER
Download the student worksheet →4. Answers & guidance
Finished your try? Open the guide and compare one worksheet at a time. Your own words may be different and still explain the right idea.
Shown on this webpage only. There is no answer-key download, and this guide is left out when printing the page.
Show answers for all 8 worksheets
Worksheet 1
- Question 1: Which is a sensor input? a measured light level
- Question 2: Which part chooses between two paths? a condition
Worksheet 2
- Question 3: Which statement is accurate? a touch predicate returns a Boolean
Worksheet 3
This page introduces the activity. There are no marked responses on this sheet.
Worksheet 4
- Question 4: What happens for 67? show CHESSBOARD and play BA_DING
- Question 5: What happens for 130? clear the display; no new tune
- Question 6: What happens at exactly 100? the False branch clears the display
Worksheet 5
- Question 7: Which replacement makes the test match the flowchart? if level < 100:
Worksheet 6
- Question 8: Which line calls the touch predicate correctly? if pin_logo.is_touched():
- Question 9: Which extra output is present in this code? a SURPRISED image
Worksheet 7
- Question 10: Repair the light program and explain its wrong comparison. Trace 67, 130 and 100. For the touch example, explain the missing call brackets and the additional image output. Describe the flowchart change that would represent the image, then give a corrected repeated touch algorithm for the stated music-only plan. Light comparison becomes level < 100. At 67 show CHESSBOARD and play BA_DING; at 130 and 100 clear screen and start no tune. Read a new level each loop, indent under while True, preserve imports and pause. Touch pin_logo.is_touched() is a Boolean call; without parentheses the method object is tested rather than its result. Intended True path plays BADDY and False bypasses output; repeat. To match displayed extra code, insert SURPRISED image output before music, but to implement the stated music-only plan remove that image. import music needed; use V2 logo. No claim every sensor result is integer. Accept correct chart or exact indented code plus explanation. No numeric scoring. Grown-up review; personal evidence is required.
Worksheet 8
- Question 11: Record the source revision, board version and transfer method. For covered and uncovered conditions, record the measured light level, expected branch, observed image/clear display and sound, pass/fail, and any repair/retest. Demonstrate both active and inactive outputs on the board. Explain any condition that did not cross the threshold. Label simulator preparation separately. Require identified corrected .py revision, completed editor Send/HEX transfer, physical tests on both sides of 100, measured or editor-observed readings, expected and actual image/clear plus tune/no-new-tune, pass/fail and retest. Covering alone is not proof the reading was below 100; adjust ordinary classroom lighting as needed. Active branch may repeat its completed tune while reading remains low; inactive clears image and starts no new tune. V2 uses built-in speaker; V1 needs a teacher-provided appropriate audio output arrangement for sound, otherwise sound test pending. No hardware/transfer: mark demonstration pending, simulator preparation separate. Never fabricate measured values or successful device observations. Source and API-stub checks do not demonstrate physical light sensing. No numeric scoring. Grown-up review; personal evidence is required.
Curriculum & workbook reference
- Cambridge Lower Secondary Computing 7 Student’s Book — pages 62–65
- PaxaKids Grade 7 Computing Lesson 2.6: Using sensors in programming — pages 1–8
Computing for your homeschool day
Explore Using sensors in programming with this free Grade 7 Computing lesson. Read one idea together, try the fillable workbook and return to review at your own pace. Download the same student worksheet PDF for pencil-and-paper practice.
Fit learning around your family’s day. There is no timer and no sign-up is needed to use the lesson. An optional account saves your lesson position and completion across devices. Workbook responses and drawings stay in this tab; save a copy of your responses before leaving.
Understand your results
Your answers are checked in your browser. Open responses need grown-up review and are shown separately from the automatic score. Check your work, then use “Retry answers to practise” to revisit mistakes while keeping correct responses.
Choose Review Answers after trying the activity. The guide stays on the webpage; the worksheet download contains only the student pages.
For programme background, visit the Cambridge Lower Secondary Computing overview. PaxaKids provides independent original companion practice.
The book pages identify the related teaching topic. The explanations, characters, programs and exercises here are original PaxaKids companion practice. Practical tasks require the appropriate editor and, where applicable, suitable equipment. A design or paper trace is not a verified hardware result. Only completed, reviewed lessons are listed.
Explore the Cambridge Lower Secondary Computing curriculum for programme background. PaxaKids is an independent learning resource.
