- Learn
- Computer Science & IT
- Computing and Coding for Ages 7 to 11
- Physical Computing
Programming Things That Sense and Move
Grade 5Lesson 8 of 10 in Computing and Coding for Ages 7 to 11 Course
What you will learn
- Find the small computers hidden inside everyday machines, and explain how every one of them takes in input, processes it and gives out output.
- Spot the computers hidden in machinesLearn what physical computing and microcontrollers are, and find the computers that control machines all around you.
- Follow input, process and output in a systemSplit a device into its inputs, processing and outputs, and explain how its parts and the people who use it work together.
- Spot the computers hidden in machines
- Write programs that switch outputs on and off, change them over time and combine them, so your device can signal and move.
- Light up LEDs and displaysSwitch lights on and off, make them blink with pauses, and show pictures, numbers and words on a display.
- Make sounds and tunesPlay tones and short tunes, choose sounds that send a clear message, and control when a sound starts and stops.
- Make things move with motorsProgram motors to start, stop, change direction and change speed, and use a servo to turn something to an exact position.
- Light up LEDs and displays
- Use buttons, switches and sensors as inputs, find out what numbers your sensors give, and keep readings and counts in variables.
- Use buttons and switches as inputsMake a device react to presses, choose between an event block and a check inside a loop, and turn everyday objects into touch inputs.
- Measure the world with sensorsChoose the right sensor for a job, explore the numbers it gives in different situations, and pick sensible threshold values from real readings.
- Keep readings and counts in variablesUse variables to count events, remember readings, make a device adjustable and log data over time.
- Use buttons and switches as inputs
- Use loops, pauses and if-then-else with real readings so your device keeps checking the world and reacts in the right way.
- Keep checking with loops and timingSet things up once at the start, then use forever and repeat loops with pauses so the device keeps reading inputs and updating outputs.
- Choose actions with if, then and elseTurn sensor readings into decisions with comparisons and thresholds, and make sure the device does the right thing in both cases.
- Handle several conditions and rangesUse else-if chains, "and" and "or" so a device can tell apart more than two situations, and test every branch.
- Keep checking with loops and timing
- Plan a smart device for a real need, connect and program it safely, then test it where it will be used and improve it until it works.
- Plan a device for a real problemDescribe the problem and the people it is for, write criteria you can check, choose inputs and outputs, and plan the algorithm before you code.
- Connect, download and run on the real deviceConnect parts to the right pins, follow safety rules, and send your program from the editor to the board.
- Test in the real world and fix faultsPlan and record tests, find whether a fault is in the hardware or the program, fix one thing at a time, and judge the finished device against its criteria.
- Plan a device for a real problem
Physical Computing study guide
1Discover computers that sense and control things
A computer can work inside a door, a washing machine, or a toy. You will follow how its parts work together and what its program controls. You will also sort the information going in, the actions coming out, and the choices people make about the device.
1.1 Find the computer inside a machine
A washing machine can follow a program without a keyboard. Its computer is hidden inside the machine. You can program a small board to control things too.
A program reaches the real world
Physical computing means programming a device that senses and acts. It might notice movement, light an LED, or turn a wheel. An embedded computer is built into a larger machine. Traffic lights, microwave ovens, and robot vacuums have embedded computers.
A microcontroller is a tiny computer on one chip. It stores a program and runs its instructions. A microcontroller board holds that chip and places to connect parts. Classroom boards often have buttons, lights, and sensors already attached. A micro:bit is one example.
Two kinds of parts work together
| Kind | What it means | Examples |
|---|---|---|
| Hardware | Physical parts you can touch | Board, wires, button, motor |
| Software | Instructions the computer runs | A program that opens a gate |
Changing software can change what the same hardware does. One board might blink a heart today and count shakes tomorrow. The board still needs the right connected parts. Instructions to move a gate cannot move it without a motor.
Follow an automatic door
Imagine walking toward a store's automatic door.
- A sensor notices that someone is near.
- The computer follows its program and chooses to open.
- A motor slides the door open.
- When nobody is near, the program waits, then closes it.
The sensor does not slide the door itself. Each part has its own job. A person chose the rules and wrote the program. The computer follows those instructions, including any mistakes in them.
When a machine acts like a robot
A robot can sense, decide, and act by following a program. A car that detects a wall and steers away does this. A toy car driven only by your remote follows your choices. Its movement alone does not show that it senses its surroundings.
Look for the job a machine does, not a screen. A washing machine's hidden computer still runs instructions, even when its only display is a few lights.
Key Takeaways
- An embedded computer controls a larger machine.
- A microcontroller board runs a stored program.
- Hardware and software work together.
- A robot uses a program to sense, decide, and act.
1.2 Trace information through a device
A device works because its parts share a job. You can follow the information through it in three stages: input, process, output.
What goes in, what happens, what comes out
An input gives the computer information. A button press or a light reading can be an input. An input device collects that information.
Processing happens when the computer follows the program. It might compare a reading with a number and choose an action. An output is the action it controls, such as a beep. A speaker, display, or motor is an output device.
| Part of a night light | Job |
|---|---|
| Light sensor | Input: measure the brightness |
| Computer running a program | Process: check whether the reading is below 40 |
| LEDs | Output: shine when the answer is yes |
For a reading of 12, the check is true. The program switches the LEDs on. For a reading of 95, the check is false. The program switches them off. The reading supplies information; the program gives that information a meaning.
Remember information
Storage lets the computer keep its program and values. A step counter keeps a count between movements. Without remembering the earlier count, it could not add the next step to it.
Some memory holds values only while a program runs. A board can also keep its downloaded program for the next start. Saving a program and keeping a running count are different jobs for storage.
People stay involved
At a crosswalk, your button press is an input. The program waits and changes signals in order. The signal lights and beeps are outputs. People also choose timings, write the program, and turn systems on or off. A useful device gives people clear controls, such as a stop button.
A part's role depends on what it does in that system. Light leaves an LED as output. That light can reach a sensor as input to another system.
Follow information, not power
A battery supplies power; it does not measure the world. Wires connect parts and carry power or signals. In a wired button, the button collects the input. Its wire carries that signal to the board. Ask, "Which part tells the computer something?" to find the input device.
Key Takeaways
- Input gives information; processing follows the program; output acts.
- Storage keeps programs and values.
- People choose rules, settings, and controls.
- A wire can carry a signal from an input device.
- The same light can be output from an LED and input to a sensor.
2Control lights, sounds and motors
Lights, sounds, and movement let a board send messages into the world. You will build patterns with pauses and choose an output that fits the job. Following each instruction in order will help you predict when a light changes, a sound ends, or a model stops moving.
2.1 Build a light pattern you can see
A light can show a message without making a sound. Your program controls when it shines and how long the message stays visible.
Show a picture or a number
An LED, or light-emitting diode, is a small light. Some boards have a grid of LEDs as a display. The micro:bit has 25 LEDs arranged in five rows of five. The display can show icons, numbers, or scrolling words.
A shown heart stays until another instruction changes or clears it. Turning an LED on does not make it turn off later. Put an off instruction in the program when you want darkness.
Give your eyes time
A computer can change a light too quickly to see clearly. A pause makes the program wait. Many pause blocks use milliseconds, written ms. There are 1,000 ms in one second. A pause of 500 ms lasts half a second.
Build a blink in this order:
- Turn the LED on.
- Pause for 500 ms.
- Turn the LED off.
- Pause for 500 ms.
The first pause holds the light on. The second holds it off. Put all four blocks inside a loop to keep blinking. If you only pause after turning it off, the on part may be too short to notice.
Make a model traffic light
Use separate green, yellow, and red LEDs. Start with all three off. Repeat these steps:
- Green on; pause 5,000 ms; green off.
- Yellow on; pause 2,000 ms; yellow off.
- Red on; pause 5,000 ms; red off.
One cycle takes 12 seconds: five, then two, then five. Switching off each light keeps the next stage clear. A pattern placed only in "on start" runs once. Put it in "forever" when it must keep cycling.
Choose colors
Some colored LEDs mix red, green, and blue light. Red and green at full brightness make yellow. All three at full brightness make white. A plain single-color LED cannot change its color just because you choose a new color block. Choose an output that can show the message you need.
Key Takeaways
- Pause after both the on and off steps to make a clear blink.
- 1,000 ms is one second.
- A display keeps its picture until an instruction changes it.
- Use a loop for a repeating light pattern.
2.2 Give a sound the right message
A beep can confirm a button press. A tune can celebrate a win. A speaker or buzzer turns your program's sound instructions into an output.
Change pitch and length
Pitch is how high or low a sound seems. You choose a tone's frequency in hertz, written Hz. A higher frequency produces a higher-pitched tone. Middle C is about 262 Hz. The A above it is 440 Hz.
Duration means how long a sound lasts. A program can set duration in beats or milliseconds. A tune is a sequence of notes, with a pitch and duration for each. A higher pitch does not mean a longer note. Change the duration to change its length.
Program a doorbell
Put these instructions in "on button A pressed":
- Play 523 Hz for one beat.
- Play 392 Hz for one beat.
The first sound is higher. The second is lower, giving a "ding-dong" pattern. Each press plays the sequence once. Some boards have a speaker built in. Others use a connected speaker or buzzer.
Choose when the next block runs
| Sound block | What the next block does |
|---|---|
| Play until done | Waits for the sound to finish |
| Play in background | Starts while the sound can still be playing |
Suppose a two-second sound comes before "show star". With "play until done", the star appears after the sound. With "play in background", the star can appear during it. Read the block's name when matching a light to a sound.
Keep signals useful
Use a short, soft sound for "OK". Use a repeating warning only while the warning is needed. A sound in an unconditional forever loop starts again every round. Give the alarm a condition or a control that silences it.
Start with low volume and short sounds when you test. Nearby classmates need to hear their own work too.
Key Takeaways
- Frequency changes pitch; duration changes length.
- A tune plays notes in a chosen order.
- A waiting sound block delays the next instruction.
- A warning sound needs a clear way to stop.
2.3 Choose movement and a stopping point
A wheel needs to keep spinning. A model gate needs to move to a chosen position. These jobs need different kinds of motor control.
Spin or turn to a position
A motor makes movement. An output that moves something is an actuator. With a spinning motor, you can choose direction and speed. Many kits use a percentage for speed: 100% is full speed, 50% is about half speed, and 0% is stopped.
A servo turns to a position and holds it. Many classroom servos accept angles from 0 to 180 degrees. The angle tells the servo where to point, not how long to spin.
| Job | Useful motor |
|---|---|
| Turn a fan or a wheel | Spinning motor |
| Raise a flag to a chosen angle | Servo |
| Move a model gate between two positions | Servo |
Open and close a model gate
Suppose the gate is closed at 0 degrees and open at 90 degrees. Set it to 0 in "on start". In "on button A pressed", place:
- Set servo to 90 degrees.
- Pause for 5,000 ms.
- Set servo to 0 degrees.
The gate stays open for five seconds, then closes. Removing the last instruction leaves the servo holding the open position. A pause by itself does not close the gate.
Steer a buggy
A buggy can have one motor on each side. Both sides forward at matching speeds drive it straight. Both backward make it reverse. If the right wheel stops while the left moves forward, it turns right. It turns toward the slower side.
Test which direction moves your model forward. A motor's mounting can change the result. If it turns the wrong way, change the direction in the program.
Plan the whole movement
Include a stop instruction for a spinning motor. Starting it and then waiting leaves it running throughout the wait. For a three-second journey, start, pause 3,000 ms, then stop.
Follow the kit's motor connections and power setup. Motors may need an extra motor board. Keep fingers, hair, and loose clothes away from spinning parts. Support a buggy during a table test so it cannot drive over the edge.
Key Takeaways
- A spinning motor controls speed and direction.
- A servo moves to an angle and holds it.
- A buggy turns toward its slower side.
- Waiting does not stop a motor.
- Use the kit’s motor board and power setup.
3Read buttons and sensors
Buttons tell a board what someone chooses. Sensors tell it about the world around it. You will find out how presses and readings reach your program, then save useful information in variables. A count or a saved reading helps your device remember what happened earlier.
3.1 Make a press do the right thing
A button tells your program whether it is pressed. Choosing how to read it changes what your device does when someone holds it down.
Two states, different switches
A button has two states: pressed and not pressed. A push-to-make switch, like a doorbell button, connects only while pressed. A toggle switch stays where you put it until you flip it again.
Buttons let people control a device. One button could choose a game mode. Another could clear a display or silence a sound.
Once per press or while held?
| What you want | Program choice |
|---|---|
| One action for each press | A button event |
| An action while the button is held | A button check inside a loop |
An event block responds when something happens. In a quiz buzzer, "on button A pressed" can show a happy face and play one beep. Button B can clear the screen. Holding A does not turn its event into a repeating loop.
A condition asks about the button's state at that moment. To run a fan while A is held, use a forever loop:
forever:
if button A is pressed:
motor on
else:
motor off
The loop keeps asking. When you release A, the next check takes the else path. Without "motor off", the fan can keep spinning after release.
Count presses carefully
If "change score by 1" sits in a button event, one press adds one. If it sits inside a fast loop's held-button check, one long hold can add many points. Every round finds the button still pressed and adds again.
A check in "on start" has a different problem. It checks only when the board starts. A press several seconds later arrives after that check has finished.
Touch can be input too
Some boards can detect buttons A and B together. Others also offer a touch-sensitive logo or pins. With a suitable kit, foil or fruit connected by clips can become touch pads. A touch pad gives the program input; the display or sound is the output that responds.
Key Takeaways
- Use an event for one action per press.
- Use a repeated check for an action while held.
- A push-to-make switch releases; a toggle switch keeps its position.
- Touch pads can provide input.
3.2 Find out what your sensor measures
A sensor turns something in the world into a reading. Before choosing what your device should do, find out what those numbers mean in its real location.
Match the sensor to the job
| What you need to notice | Useful sensor |
|---|---|
| Brightness | Light sensor |
| Temperature | Temperature sensor |
| Noise level | Microphone or sound sensor |
| Wetness of soil | Moisture sensor |
| How far away an object is | Distance sensor |
| Shaking or tilting | Accelerometer |
| Direction the board faces | Compass |
An accelerometer measures acceleration, including the effect of gravity. A board uses this information to detect movement and tilt. Blocks such as "on shake" use that sensor's readings.
Read numbers before choosing a rule
On a micro:bit, light readings run from 0 for dark to 255 for bright. The sensor supplies a number, not the word "dark". A program compares that number with a threshold to choose an action.
Try this for a night light:
- Show the light reading while the room is bright: about 140.
- Cover the sensor and read again: about 15.
- Choose a threshold between them, such as 50.
- Use "light level < 50" to decide when to shine.
The reading 15 is below 50. The reading 140 is above it. A threshold of 5 would miss both situations, so the light would never come on during these tests.
Expect small changes
Readings might wobble from 140 to 142 to 139. Small changes are normal. A threshold right beside those values can make an output switch back and forth. Choose a value with space between the usual readings for your two situations.
The same threshold may fail somewhere else. Sunlight near a window can reach a partly covered sensor. Check it where the finished device will sit.
Temperature needs a little care
Classroom boards commonly report temperature in degrees Celsius, or °C. Water freezes at about 0 °C; a classroom might be near 20 °C. Some boards measure inside their computer chip. That chip can warm up while running, so its reading can be warmer than the surrounding air. A reading tells you what that sensor measured, in that place.
Key Takeaways
- Choose the sensor for the thing you need to measure.
- A sensor reading is a number your program can compare.
- Choose thresholds using real readings.
- Small reading changes are normal.
- Test the sensor in the device’s real location.
3.3 Remember a count or a reading
A board can remember information while your program runs. A variable is a named place in memory that holds a value you can change.
Build a step counter
Name a variable "steps". Put "set steps to 0" in "on start". Add these events:
- On shake: change steps by 1.
- On button A pressed: show the value of steps.
- On button B pressed: set steps to 0.
After three shakes, steps holds 3. Button A shows 3. Button B clears the count. The word "steps" is the name; 3 is the value. "Show text steps" displays the name, not the count.
Keep the starting instruction out of forever. Resetting steps every round erases the count again and again. Test by walking exactly 20 steps. A display of 26 means extra movements were counted; 14 means some steps were missed. Try changing where you wear it or how strong a shake must be.
Save a moment
"Set temp to temperature" saves the reading now. If temp becomes 21, it stays 21 until another instruction changes it. It does not follow the sensor by itself.
To keep the highest reading, begin with the first reading. For each new value, use:
if reading > highest:
set highest to reading
With readings 21, 23, and 22, highest starts at 21. It changes to 23 because 23 is larger. It stays at 23 when 22 arrives.
Make a setting adjustable
A variable can hold a threshold too. Start threshold at 50. Button A adds 10; button B subtracts 10. Compare light with the variable threshold. Someone can tune the night light without changing its blocks.
If the comparison still contains a fixed 50, changing the variable will do nothing.
Save readings over time
A data logger collects and saves readings at regular times. Taking a reading every five seconds for one minute gives 12 readings, when the first is at five seconds. A table or graph can show how they changed.
Choose the gap to match the change. Moving a board happens quickly, so readings need to be close together. A room cooling overnight changes slowly, so a gap of several minutes can work.
Key Takeaways
- Set a starting count once, then change it when events happen.
- A saved reading stays until you update it.
- Keep a highest value by replacing it only with a larger reading.
- Use a variable in the comparison to make a setting adjustable.
- A data logger saves readings at regular times.
- Choose the reading gap to suit how fast things change.
4Write control programs that decide
Your device needs to notice changes after it starts. You will place checks inside loops, turn readings into true-or-false choices, and handle several conditions. Testing a value exactly at a boundary helps you see whether your program does the job you intended.
4.1 Keep your device checking
A room can become darker after a board starts. Your program needs to check again to notice the change. The place you put each instruction matters.
Set up once, then keep watching
Use "on start" for setup. It can set a count to zero, display a welcome picture, or close a model gate. It runs when the board starts or resets.
Use "forever" to keep reading inputs and setting outputs. A typical round reads a sensor, makes a decision, and changes an output. Event blocks can also respond whenever their event happens.
A plant alarm might repeat these steps:
- Read the moisture sensor.
- If the soil is dry, show a sad face and beep.
- Else, show a happy face.
- Pause for 1,000 ms.
It checks about once each second. The reading belongs inside the loop too. Reading once at startup and comparing that old number forever would miss new conditions.
Repeat a set number of times
A "repeat" loop finishes after its chosen number of rounds. To flash a warning three times, repeat: LED on, pause 200 ms, LED off, pause 200 ms.
Each round waits 400 ms. Three rounds wait 1,200 ms, or 1.2 seconds. After the third round, the program moves to the block below the loop. A forever loop would keep flashing.
Waiting affects checking
A pause holds up the instructions in that loop. During a ten-second pause, that loop does not check its sensor or button again. A short press can happen and finish between checks. Other event blocks can still run in editors that handle events separately.
A "repeat until" loop checks its condition between rounds. It leaves the loop when a check finds the condition true. If it checks whether A is held, A must be held at the time of a check.
Give an output one clear rule
Two forever loops can fight over the same light. One turns it on; the other turns it off. The light can flicker as their instructions take turns. Put the choices in one place, with a condition that selects the intended state.
Key Takeaways
- Put setup in "on start" and repeated reading inside a loop.
- A repeat loop finishes; a forever loop keeps running.
- A paused loop does not check its inputs.
- A repeat-until loop checks between rounds.
- Control an output from one clear set of choices.
4.2 Tell your device what to do in both cases
A sensor gives a number. A condition turns a comparison into true or false. Your program uses that answer to choose an action.
Read the comparison aloud
| Sign | Read it as |
|---|---|
| < | Less than |
| > | Greater than |
| = | Equal to |
| ≤ | Less than or equal to |
| ≥ | Greater than or equal to |
The threshold is the number where the behavior changes. Use real sensor readings to choose it.
Make a night light respond both ways
Use this decision inside forever:
if light level < 50:
turn LEDs on
else:
turn LEDs off
At 15, the condition is true, so the LEDs turn on. At 140, it is false, so they turn off. This choice is called selection.
Now follow a change: first the room is dark, then bright. The first check turns the LEDs on. The next bright check reaches else and switches them off. If you leave out else, no instruction turns them off. The earlier on state remains.
Test the exact threshold
At a reading of 50, "less than 50" is false. The LEDs turn off. To include 50 in the on case, use "less than or equal to 50". Decide which behavior you need before choosing the sign.
A useful set of tests is 49, 50, and 51. These readings check just below, exactly at, and just above the boundary. A very dark and a very bright test alone can miss an incorrect equals sign.
Check the direction
A too-hot warning can use "temperature > 30". At 31 °C it shows "HOT" and plays a tone. At exactly 30 °C it shows "OK". Greater than does not include equality.
For a night light, "light > 50" would reverse the job. It would shine in the bright case. Say the whole rule aloud: "If the light reading is less than 50, turn on." This helps you connect the sign to the action.
Buttons can supply conditions too. "If A is pressed, motor on; else, motor off" chooses a state on every check, using the button's two states.
Key Takeaways
- A condition has a true or false answer.
- If and else give actions for both answers.
- Strict < and > comparisons leave out equality.
- Test the exact threshold and values beside it.
4.3 Choose between more than two actions
Some devices need three choices or two clues at once. You can join conditions and order decisions so the output matches each situation.
Follow an else-if chain
An else-if chain checks from the top. The first true branch runs. The later branches are skipped.
if temperature < 18:
show "COLD"
else if temperature > 25:
show "HOT"
else:
show "OK"
A reading of 17 reaches "COLD". At 18, the first check is false. The second check is false too, so it shows "OK". A reading of 25 also shows "OK"; 26 shows "HOT". The middle range includes both 18 and 25.
Put a stricter check first
Consider "if temperature > 10, show WARM; else if temperature > 25, show HOT". At 30, the first check is already true. The program shows "WARM" and skips "HOT".
Check "greater than 25" first, then "greater than 10". A high reading can now reach "HOT". Separate if blocks behave differently: both can run and change the same display. Use one chain when only one choice should happen.
Join clues with and or or
And needs both conditions to be true. A garden light might require darkness and someone nearby. Use "light < 50 and distance < 100 cm".
| Light and distance | Shine? |
|---|---|
| Dark and near | Yes |
| Dark and far | No |
| Bright and near | No |
| Bright and far | No |
Or needs at least one condition to be true. A model alarm can beep if a door opens or a window opens. It beeps when either opens, and also when both open.
Check a range
To ask whether temperature is from 18 to 25, use "temperature ≥ 18 and temperature ≤ 25". A reading of 20 passes both checks. At 27, the upper check fails.
Using or here would accept every reading: even 40 is at least 18. Test both ends and a value outside each end. For the three-message thermometer, test 17, 18, 25, and 26 to reach all branches and check both boundaries.
Key Takeaways
- An else-if chain runs its first true branch.
- Check a stricter overlapping condition first.
- And needs both conditions; or needs at least one.
- Use and to keep a value between two limits.
- Test every branch and both sides of each boundary.
5Design, build and test a device that solves a problem
A useful device has a clear job for a real person. You will turn that job into a plan, connect and program the parts, and test the finished model. A written test result helps you find a fault and choose one change that makes the device work better.
5.1 Plan a useful device
A smart device starts with someone's need. Before you choose blocks or parts, decide who will use it and what problem it should solve.
Write things you can check
Design criteria say what a successful device must do. "Make a good light" is hard to test. "The light turns on within two seconds of darkness" gives you a clear check. Ask where the device will sit and how people will control it.
Start with a simple version. Add extra features after its main job works. A device with many unfinished features may never solve the original problem.
Plan a plant reminder
The class plant keeps drying out. You want a reminder that tells someone to water it.
| Stage | Plan |
|---|---|
| Input | Moisture sensor in the soil |
| Process | Check every ten minutes; compare with the dry threshold |
| Output | Sad face and short beep when dry; happy face otherwise |
| Human control | A button silences the beep until watering |
First explore the sensor in wet and dry soil. Use those readings to choose the threshold. A number that works for one moisture sensor may mean something different on another.
The silence button needs a remembered setting. Once pressed, the program keeps the beep silent while the soil stays dry. When watering is detected, it clears that setting for next time. Otherwise, a single press could silence every future warning.
Draw or write the algorithm
An algorithm is the steps your program follows. Write numbered steps or draw a flowchart. In a flowchart, an oval marks the start. A rectangle shows an action. A diamond asks a yes-or-no question. Labeled arrows show which path to follow, and an arrow back shows repetition.
For a model gate, the plan might be: check for an animal nearby; open the gate; wait ten seconds; close; return to the check. A servo supplies the two positions. Try the plan with a toy animal before building the model.
Think about difficult moments
What happens if both buttons are pressed? What if a reading equals the threshold? Can the user stop the device? Add tests for these cases to your plan. A greenhouse logger, a door alarm, and a buggy that stops near walls all need different inputs and different checks.
Key Takeaways
- Begin with the user, place, and problem.
- Write criteria you can test.
- Match inputs and outputs to the job.
- Plan decisions and repeats before coding.
- Build the main feature before adding extras.
5.2 Send your program to the real board
The simulator can help you try your blocks. The real device also needs matching connections, power, and the newest copy of your program.
Connect with care
Switch off or unplug power before changing connections. Keep electronics dry and use the battery pack supplied with your kit. Tell an adult if anything gets hot, smells strange, or has a damaged battery.
Follow your kit's connection pictures. Match the labeled pins or sockets to the program. Some boards use numbers such as 0, 1, and 2; others use letters. Power and ground have their own labels. Ground is often marked "GND" or "−".
Some parts, including many LEDs, work only one way around. Match the kit's + and − markings. Fasten clips firmly and keep their metal ends apart. Touching clips can connect places that should stay separate.
Match the pin in the program
An LED is connected to pin 1. The program says "turn pin 0 on". The program can run without reporting an error, but the LED stays dark.
- Find the LED's connection in the kit plan.
- Read its pin label: 1.
- Change the output block to pin 1.
- Send the changed program to the board.
The hardware connection and software instruction now point to the same place.
Download and try it
To download a program means to send it to the board. Many boards use a USB cable; some also support Bluetooth. A saved change in your editor does not update the board until you send it again.
Try a tiny program first, such as showing a heart. Check that the real board runs it. Then send your device program. Most classroom boards keep their program after unplugging and run it again when powered.
Build around the parts
Keep a light sensor uncovered. Place moisture-sensor prongs in the soil. Fix a motor firmly and leave enough wire for moving parts. A sensor hidden by your model's roof cannot measure the light you intended.
A simulator is an on-screen model. It helps check program logic, but its readings and movement can differ from the real device. A heavier gate may move slowly. A bright window may change the sensor readings. Test the model where people will use it.
Key Takeaways
- Follow the kit’s connection plan and match pin labels.
- Send the program again after editing it.
- Try a tiny program to check the real board.
- Place parts so they can sense and move freely.
5.3 Test, find the fault, and improve
A device working once is a useful start. Testing checks whether it does its job in different situations, including the awkward ones.
Compare expected and actual results
The expected result is what should happen. The actual result is what did happen. Write both so you can explain a pass or failure.
For a night light using "light < 50", a test table might look like this:
| Test | Expected result |
|---|---|
| Cover sensor; reading about 15 | LEDs on |
| Uncover sensor; reading about 140 | LEDs off |
| Give a reading of exactly 50 | LEDs off |
| Cover, then uncover | On, then off |
Add an actual-result column when you run the tests. The last test checks a change over time. It can reveal a missing else that two separate startup tests miss.
Test every input and every branch. Include values at boundaries and actions such as holding a button or pressing both buttons. Use the real location as well as the simulator.
Find one cause at a time
A fault, or bug, makes the actual result differ from the expected one. It can be hardware or software.
- Hardware: loose clip, wrong pin, low battery, backward part, covered sensor.
- Software: wrong comparison, missing else, old program, poor threshold, check outside a loop.
Use a clear search order:
- Describe exactly what fails and when.
- Check power and whether the latest program was sent.
- Match each connection to the plan.
- Test one part with a tiny program.
- Display sensor readings and check the decision rule.
- Change one thing, then repeat the failed test.
Use readings to explain a failure
A night light never turns on. Its covered reading is 70, and uncovered is 160. The program uses "light < 50". Both readings fail that condition.
Try a threshold of 110. Now 70 passes and 160 fails. Test both situations again. Changing the threshold explains this fault; replacing several parts at once would hide which change helped.
Judge the finished device
To evaluate, compare the device with each design criterion. Ask its users to try it. A bright warning might work well for one person but be hidden from another's seat. Use their feedback and your results to choose the next improvement.
Key Takeaways
- Record what should happen and what actually happened.
- Test changes over time, boundaries, and every branch.
- Faults can be in hardware or software.
- Use tiny programs and visible readings to narrow down a fault.
- Change one thing and test again.
- Evaluate against the criteria and ask users to try the device.
Physical Computing examples
1Follow a machine’s hidden computer
9 steps
- 1IntroductionA machine notices you
An automatic door opens as you approach. You do not turn a handle, but several parts work together. A hidden embedded computer controls it.
Follow the information from the approaching person (input), through the program (processing), to the moving door (output). Then use the same ideas to explain another device.
- 2ExplanationLook inside the machine
An embedded computer is built into a machine to control it. A washing machine and a robot vacuum both have one. Your classroom board also runs a program. Its microcontroller is a tiny computer on one chip, with connections for other parts on the board.
- 3ExampleFind the moving part
At the store, a sensor notices you nearby. The computer follows its opening rule. A motor slides the door open. The computer did not invent that rule: someone wrote it. A mistake in the program can make the machine behave wrongly.
- 4ChallengeChange the door’s wait
The same automatic door should wait longer before closing. Its motor and sensor work. Should you change its hardware or software, and why?
---reveal---
Change the software: the program controls the wait. The working motor and sensor are hardware and can carry out the changed instructions.
- 5ExplanationGive each part a job
Input gives information to the computer. Processing follows the program and chooses an action. Output carries it out. For the door, sensing a nearby person supplies input, the program processes it, and the motor provides movement as output.
- 6AnalogyKeep a note for later
Think of storage like keeping a note you can use later. A board stores its program and useful values. A counter remembers the earlier number before adding another event. The name of the store helps the program find that value again.
- 7ChallengeSort a toy’s parts
A toy hears a clap and shows a smile. It has a microphone, a computer running a rule, a display, and a battery. Which supplies input, and which supplies power?
---reveal---
The microphone supplies input about sound. The battery supplies power. The display gives output after the computer processes the clap information.
- 8ChallengeAdd a person’s choice
The clap toy should let you choose how loud a clap must be. What human control could you add, and which part of the system would use the setting?
---reveal---
Buttons could raise or lower the chosen limit. The program would use that setting during processing, when it compares the microphone reading. The display could stay as the output.
- 9RecapTrace before you build
To explain a device, name what it notices, what its program decides, and what acts. Include values it remembers and choices people control. A machine does not need a screen to have a computer; look at the work its parts do together.
2Build signals with light, sound, and movement
13 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionMake your board send a message
- 2ExplanationHold a light state
- 3ExampleBuild one beacon cycle
- 4ChallengeFix the disappearing flash
- 5ExplanationChoose pitch and duration
- 6ExampleTime a greeting with a picture
- 7ChallengeMake a different note
- 8ExplanationMove to a flag position
- 9ExampleRaise the flag
- 10ExampleFinish the movement
- 11ChallengeChoose a wheel’s finish
- 12ChallengeFollow the station signal
- 13RecapCheck what keeps going
3Make a badge notice and remember
15 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionGive a badge useful inputs
- 2ExplanationRead a press once
- 3ExampleKeep checking a held button
- 4ChallengeChoose a foil-pad action
- 5ExplanationMatch a reading to its meaning
- 6ExampleCollect two groups of readings
- 7ExampleChoose a useful boundary
- 8ChallengeChoose a sensor for a new job
- 9AnalogyGive a value a name
- 10ExampleStart a movement count
- 11ExampleSave one reading
- 12ChallengeFollow the remembered maximum
- 13ConnectionMake a record over time
- 14ChallengeGive the badge a tuning button
- 15RecapKeep the right information
4Make a changing-room indicator
14 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionNotice when a room changes
- 2ExplanationUse startup for setup
- 3ExampleChoose the gap between checks
- 4ChallengeFind the stale reading
- 5ExplanationChoose true or false
- 6ExampleFollow a changing input
- 7ChallengeTest the exact limit
- 8ExampleAdd a cold message
- 9Key InsightKeep equality in the middle
- 10ChallengeRepair the order
- 11ExplanationJoin two clues
- 12ChallengeCheck a middle range
- 13ChallengeFollow the complete indicator
- 14RecapTry the paths that meet at a boundary
5Plan and test a shelf reminder
12 steps
Save this lesson to follow every Walkthrough step by step.
- 1IntroductionBuild for a real place
- 2ExplanationChoose a clear success test
- 3ExamplePlan the information path
- 4ChallengeImprove a vague requirement
- 5ExampleMatch the connection plan
- 6TipSend each edited version
- 7ChallengeLet the sensor do its job
- 8ExampleWrite down both results
- 9ExampleUse evidence to find a fault
- 10ChallengeChoose a useful retest
- 11ChallengeChoose the next improvement
- 12RecapLet test results guide the next change
Physical Computing practice questions
Set 1: Follow signals and simple programs10 Practice Questions
Question 1 of 10
Show answerHide answer
Question 2 of 10
Show answerHide answer
Question 3 of 10
Show answerHide answer
Question 4 of 10
Show answerHide answer
Question 5 of 10
Show answerHide answer
Question 6 of 10
Show answerHide answer
Question 7 of 10
Show answerHide answer
Question 8 of 10
Show answerHide answer
Question 9 of 10
Show answerHide answer
Question 10 of 10
Show answerHide answer
Set 2: Choose parts and trace changing values10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 3: Predict responses and find missing steps10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 4: Trace a whole device from start to finish10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Set 5: Solve problems in new device designs10 Practice Questions
Save this lesson to see every answer and practice every set.
Question 1 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 2 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 3 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 4 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 5 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 6 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 7 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 8 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 9 of 10
Show answerHide answer
Save this lesson to see this answer.
Question 10 of 10
Show answerHide answer
Save this lesson to see this answer.
Stuck on your own question? Homework Help
Key Terms
A
Accelerometer
Actual result
Actuator
Algorithm
And
B
Button state
Buzzer
C
Condition
Control program
Counter
D
Data logger
Design criteria
Display
Distance sensor
Download
Duration
E
Else branch
Else-if chain
Embedded computer
Evaluation
Event
Expected result
F
Fault
Flowchart
Forever loop
Frequency
G
Ground
H
Hardware
I
Input
L
LED
Light sensor
M
Microcontroller
Millisecond
Moisture sensor
Motor
Motor speed
O
On start
Or
Output
P
Pause
Physical computing
Pin
Pitch
Processing
Push-to-make switch
R
Range check
Reading
Repeat loop
Reverse
Robot
S
Saved reading
Selection
Sensor
Servo
Simulator
Software
Storage
System
T
Temperature sensor
Threshold
Toggle switch
Tune
V
Variable
About this lesson
Make your own Study Materials
Turn your notes, slides and documents into Study Guides, Practice Questions, Flashcards and 6 more tools.