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.

8 fillable worksheet pagesRead at your own pace

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.

Today’s two goals
  • Identify sensor inputs and explain how a condition selects an output.
  • Predict both branches of the light-level flowchart for the supplied inputs.
Original PaxaKids illustration for Using sensors in programming. Precise program text and data are supplied in the workbook models.
An original PaxaKids workbook scene. Use the supplied programs and data for precise workbook facts.

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

Our goal: identify sensor inputs, predict both branches of a light-level rule, then repair and test a MicroPython program.

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

Know which result the API returns — original model
Input / featureExample MicroPython APIResult here
Light via LED displaydisplay.read_light_level()integer, 0–255
Processor temperaturetemperature()integer degrees C
V2 logo touchpin_logo.is_touched()Boolean
Movement gestureaccelerometer.was_gesture("shake")Boolean
V2 microphonemicrophone.sound_level()integer, 0–255

Read the intended light-response loop

    Decision: level < 100?

    True branch
    1. Show CHESSBOARD
    2. Play BA_DING
    False branch
    1. Clear display

    Trace readings on both sides

    Trace readings on both sides — original model
    ReadingTest to evaluate
    6767 < 100
    130130 < 100
    100100 < 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)
    Paxa the Fox

    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
    1. Lesson 2.1: All about software
    2. Lesson 2.2: Introducing the micro:bit
    3. Lesson 2.3: Using Python with the micro:bit
    4. Lesson 2.4: The micro:bit Python environment
    5. Lesson 2.5: Correcting errors using a flowchart
    6. Lesson 2.6: Using sensors in programming
    7. Lesson 2.7: Flowcharts for algorithm planning
    8. Lesson 2.8: Algorithmic solutions and data types
    9. Lesson 2.9: Planning a smart solution
    10. Lesson 2.10: Effective testing
    11. Lesson 2.11: Evaluating a program
    12. Lesson 2.12: Testing accelerometer gestures
    13. Lesson 2.13: Protecting a museum crown
    14. Lesson 2.14: Final project
    15. Lesson 2.15: Evaluation
    16. 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.

    Using sensors in programming8 student pages · original artwork

    Opening your PDF…

    Swipe sideways across the worksheet on a small screen, or use “Answer list” for larger controls.

    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

    Download worksheet PDF ↓

    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

    1. Question 1: Which is a sensor input? a measured light level
    2. Question 2: Which part chooses between two paths? a condition

    Worksheet 2

    1. 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

    1. Question 4: What happens for 67? show CHESSBOARD and play BA_DING
    2. Question 5: What happens for 130? clear the display; no new tune
    3. Question 6: What happens at exactly 100? the False branch clears the display

    Worksheet 5

    1. Question 7: Which replacement makes the test match the flowchart? if level < 100:

    Worksheet 6

    1. Question 8: Which line calls the touch predicate correctly? if pin_logo.is_touched():
    2. Question 9: Which extra output is present in this code? a SURPRISED image

    Worksheet 7

    1. 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

    1. 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.
    Back to my workbook ↑

    Curriculum & workbook reference

    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.