KeyStage

Key Stage 2 computing · Algorithms and programming

KS2 computing: controlling and simulating physical systems

Key Stage 2 computing includes writing programs that control or simulate physical systems. In practice that means programs that switch on lights, move a motor or react to a sensor, or that imitate something from the real world, such as traffic lights or a lift, on a screen. Children use sequence, selection and repetition, and think about what goes into a system and what comes out.

Controlling and simulating physical systems, explained

The programme of study asks Key Stage 2 pupils to design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems. A physical system is anything in the real world that behaves in a predictable, rule-based way: a set of traffic lights, a pedestrian crossing, an automatic door, a lift, a greenhouse with a fan. Schools choose how to teach it, so what your child does depends on the equipment the school has.

To control a physical system, a program sends instructions to a device that does something in the real world. Many schools use small programmable boards or kits with lights, buzzers, switches and motors, or floor robots that follow a route. The program might make a light blink, make a buzzer sound when a button is pressed or make a motor turn for two seconds. Where a school has no equipment, children simulate a system on screen. They build a virtual traffic light or a model of day and night that behaves like the real thing, and this teaches the same ideas without the hardware.

Two words that help unpick these programs are input and output. An input is information that goes into the system, for example a button being pressed, a light sensor reading or a temperature. An output is something the system does as a result, such as a light turning on, a sound playing or a motor moving. Children are taught to map their system first: “What are the inputs? What are the outputs? What should happen, and when?” This design work is the first stage of writing any program with a specific goal.

These projects pull together all the other programming skills. A sequence decides the order of events (red, then amber, then green), selection decides what happens in different conditions (if the button is pressed, then the crossing light changes) and repetition keeps the system running (repeat forever). Children also use variables, for example to keep count of cars or store a temperature, and they decompose the system into parts that can be built and tested one at a time. Debugging is hands-on and sometimes very visible, because a light that stays on at the wrong time is easy to spot.

Whatever kit the school has, parents do not need to buy anything for their children to get this thinking. Everyday systems around the house work in the same way, and talking about how they behave, and what would have to be in a program to make them work, is excellent preparation.

Words your child will hear

Physical system
A real-world arrangement that follows rules, such as traffic lights, an automatic door or a lift.
Simulation
A program that imitates how something in the real world behaves, usually on a screen.
Input
Information going into a system, such as a button press or a sensor reading.
Output
What the system does, such as turning on a light, making a sound or moving a motor.
Sensor
A part that detects something about the world, such as light, sound, temperature or touch.
Control
To make a device do something by giving it instructions from a program.
Repeat
To run a set of instructions again and again, either a set number of times or forever.

What the National Curriculum says

In Key Stage 2, pupils should be taught to:

  • Design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts
  • Use sequence, selection, and repetition in programs; work with variables and various forms of input and output

Objectives from the National Curriculum in England, © Crown copyright, used under the Open Government Licence v3.0.

Try it: programming a model traffic light

A school has a model set of traffic lights with red, amber and green lights. Write a program for the usual sequence in the UK, then debug it when the amber stays on during green.

  1. Identify the outputs and the goal. The outputs are three lights. The UK sequence is: red, red and amber together, green, amber, then back to red. There is no input yet, so the lights simply cycle.
  2. Decompose the problem. First get one light working. Then write the complete sequence for one cycle, then add the waiting times, then repeat it forever. Test after each part.
  3. Write the first version, listing which lights are on at each stage, with a wait after each.
    repeat forever
      red ON, amber OFF, green OFF
      wait 4 seconds
      red ON, amber ON, green OFF
      wait 1 second
      red OFF, amber OFF, green ON
      wait 4 seconds
      red OFF, amber ON, green OFF
      wait 1 second
  4. Test and find the bug. Suppose a child had written “amber ON” in the green step by mistake. The model would show amber and green together, which does not happen on a real road. Tracing the program one line at a time shows that the amber was never switched off.
  5. Extend the goal with selection. Add an input: a pedestrian button. In the red stage, replace the fixed 4-second wait with a check: if the button has been pressed, wait 8 seconds, else wait 4 seconds. Test with and without a press. Real crossings are more complicated than this, but the model shows how an input and an if/else change what the system does.

The program repeats red, red and amber, green, then amber, with a wait after each stage. The debug fix is to set each light ON or OFF in every step, and the button extension uses an if/else to choose how long red stays on.

Common mistakes and how to help

Thinking a program only works on a screen

Children mostly meet coding in a window on a computer, so it can be a surprise that the same ideas run lights and motors.

What helps: Point out the programmed devices around you: a washing machine, a microwave, a lift, a pedestrian crossing. Each has inputs, a program and outputs.

Forgetting to turn things off

Children think of an instruction as “turn the green light on” and forget that the red light will stay on unless it is switched off.

What helps: Make a small table of what each light should be doing at each stage, and check the program against it. It helps to spell out the state of every light every time.

Mixing up inputs and outputs

Both appear as blocks in the program, and a device such as a button or a buzzer is easy to put in the wrong group.

What helps: Ask, “Is this telling the program something (input), or is the program telling it to do something (output)?” Sort everyday devices into the two groups.

Assuming the simulation is the same as the real thing

A simulation is a model with simplifications. A virtual traffic light has no wires to loosen and no bulb to blow, so it can seem to work flawlessly.

What helps: Talk about what the simulation leaves out and what it is useful for. It lets us test ideas quickly and safely before building the real thing.

How to help at home

  • Spot the systems. On a walk or at home, find things that have inputs and outputs: automatic doors, a pedestrian crossing, a bedside lamp with a sensor. Ask, “What sets it off? What does it do?”
  • Be the traffic light. One person is the programmed traffic light who holds up red, red and amber, green and amber cards in order while the others walk or stop. Then add a button press that changes the timing.
  • Write the rules in plain English. Choose a system, such as a lift that stops at three floors, and write its rules as if/then sentences. This is the design stage of a program, and no technology is needed.
  • Use a simple circuit kit if you have one. A battery-powered torch or buzzer kit shows input and output clearly: a switch is the input and the light is the output. Stay nearby, keep to ordinary low-voltage batteries (keeping small button batteries away from younger brothers and sisters) and never experiment with mains electricity.
  • Ask about school projects. Ask your child to explain what their device or simulation does and how they tested it. Explaining is excellent practice for logical reasoning.

Leads on to

Everything in Key Stage 2 computing

Updated .