Level 1 Discovering How the World Works · Term 3: Your First Intelligent System
What turns a machine into an intelligent one? This term you learn to think like a robot's programmer: exact instructions, decisions that depend on sensors, loops that repeat, and feedback that keeps correcting. You finish by designing a small intelligent system of your own and testing it the way engineers do.
In this file: 27 lessons across weeks 19–27, with 108 practice questions (questions only, no answers).
Develop engineering curiosity, foundational scientific reasoning and the ability to understand simple systems. Levels describe what you can do, not your age. About About 2–3 hours a week (three short lessons and a lab), with optional extensions. Stop and pick up any time..
Week 19: What makes a machine intelligent?
This week you will
- Tell an automatic machine apart from one that senses and decides.
- Describe the sense–think–act loop with an everyday example.
- Decide which choices a remote robot must make on its own.
Automatic or intelligent?
A music box plays the same tune perfectly every time. A robot vacuum never cleans your room the same way twice. Which one is smarter?
Why it matters
Engineers get asked to make things 'smart' all the time: smart doorbells, smart lights, smart greenhouses. Before you can build one, you need a sharp test for what smart actually means. This term you will build that test, then use it to design your own intelligent system.
Goals
- Tell the difference between a machine that only follows a fixed routine and one that senses and decides.
- Name the sensor and the decision in an everyday intelligent machine.
- Explain why 'intelligent' in engineering means reacting sensibly, not thinking like a person.
Predict
A sorting machine has perfect sensors but nobody has given it any rules yet. Parts roll along the belt. What happens?
- It works out the rules by watching
- Every part goes into the same bin
- It stops the belt and asks for help
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Run the conveyor before it has any rules and watch where the parts go. Then sort six parts by hand using the client's brief. You are doing the 'thinking' the machine is missing.
What the interactive shows, in words
The sorting-machine simulator can be replaced by this description: a belt carries coloured plastic and metal parts past three sensors (colour, size and metal). With no rules, every part falls into the 'Mixed' bin. The learner then decides by hand which bin each of six parts belongs in, using the sensor readings and the client's thresholds.
Understand
Automatic machines repeat
A music box, a toaster with a timer, or a wind-up toy does the same steps in the same order, whatever is happening around it. That is automatic. It can be precise and useful, but if the world changes, it carries on regardless.
Intelligent machines respond
An intelligent machine senses something about the world, decides what to do using rules, and acts. A robot vacuum feels a bump and turns. A night light measures darkness and switches on. Change the world and its behaviour changes too.
Smart is a spectrum
Engineers rarely mean 'thinks like a person'. They mean 'does the right thing in more situations'. A light that turns on at 7 pm is automatic. One that turns on when it gets dark is a little intelligent. One that also learns when you usually come home is more intelligent still.
Explain it another way: intuitive
Imagine two lighthouse keepers. One lights the lamp at exactly 6 pm every day. The other looks out of the window and lights it when it gets dark. On a stormy afternoon, only the second one saves the ships.
Explain it another way: technical
An automatic system runs an open sequence: its outputs depend only on time and its starting state. An intelligent (reactive) system's outputs also depend on its inputs: sensor readings feed rules that choose the action.
Explain it another way: applied
Modern cars are full of both. The windscreen wipers on a timer are automatic; rain-sensing wipers that speed up in a downpour are intelligent. Both use the same motor: the difference is a sensor and a rule.
Try these examples
Example 1
Is a microwave that runs for exactly 2 minutes automatic or intelligent? What would make it intelligent?
The worked solution is in the online lesson.
Common mix-ups
Intelligent machines think like people.
✓ In engineering, an intelligent machine senses, follows rules and acts sensibly in changing situations. It doesn't need feelings or understanding.A better sensor makes a machine smarter.
✓ Sensors only measure. The intelligence is in the rules that turn measurements into actions.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which of these machines is intelligent rather than just automatic?
- A clock that chimes every hour
- A garden sprinkler that runs from 6:00 to 6:20 every morning
- A sprinkler that waters only when a soil sensor reads dry
- A conveyor belt that always runs at the same speed
2. A machine has an excellent camera but no rules. Is it intelligent?
- Yes, because it can see
- No, sensing alone doesn't choose an action
- Yes, if the camera is expensive enough
3. A night light switches on when the room gets dark. What does it sense, and what does it do?
- Senses time, acts by ringing
- Senses light level, acts by switching a lamp
- Senses sound, acts by switching a lamp
4. Put these lights in order from least to most intelligent: (A) on at 7 pm daily, (B) on when it gets dark, (C) on when it's dark AND someone is in the room.
- A, B, C
- C, B, A
- B, A, C
Apply it
Pick three machines at home or school. For each, say whether it is automatic or intelligent, and name the sensor and the rule if it has one. Then choose one automatic machine and invent a sensor and a rule that would make it intelligent.
Reflect
Think of a machine that annoys you because it does the same thing whatever happens. What would it need to sense to behave better?
Sense, think, act
A robot vacuum bumps a chair leg, backs off and turns. In that half second it did three different jobs. What were they?
Why it matters
Sense–think–act is the skeleton of every robot ever built, from a toy line-follower to a Mars rover. Once you can see it, you can understand any intelligent machine by asking three questions: what does it measure, how does it decide, and what can it change?
Goals
- Describe the three stages of the sense–think–act loop.
- Identify each stage in a real machine.
- Explain why the loop must repeat, not run once.
Predict
A robot checks its distance sensor once at the start of a corridor, decides 'all clear', then drives for 10 seconds. Someone steps out in front of it after 3 seconds. What happens?
- It stops, because the sensor sees the person
- It drives into the person
- It slows down a little
Write down your guess and your reason. The reveal is in the online lesson.
Discover
This robot's 'think' step is one rule. Slide the sensor reading towards the wall and watch the decision change. Each time you move the slider, you are doing one more turn of the loop.
What the interactive shows, in words
The rule tester can be replaced by this description: the rule is 'IF distance < 20 cm THEN stop ELSE drive forward'. At 35 cm the condition is false so the robot drives; at 15 cm it is true so it stops; at exactly 20 cm, 20 < 20 is false, so it still drives.
Understand
Sense
Measure something about the world: a distance, a temperature, a colour, whether a button is pressed. A machine can only react to what it can measure.
Think
Compare the measurement with what you want and choose an action. At this level the thinking is usually a rule: if the wall is closer than 20 cm, stop. Rules can be simple and still produce clever-looking behaviour.
Act
Change something in the world: spin a motor, open a valve, sound a buzzer, light an LED. The parts that do this are called actuators.
Then do it again
Acting changes the world, so the next measurement is different. The loop goes round and round, often hundreds of times a second. That repetition is what lets a robot notice surprises and correct itself.
Explain it another way: intuitive
Crossing a road is sense–think–act: you look (sense), judge whether the gap is big enough (think) and walk or wait (act). And you keep looking while you cross.
Explain it another way: technical
A controller runs a cycle: read inputs, compute outputs from the inputs and its rules, write outputs, repeat. The time for one cycle (the loop period) limits how quickly it can react.
Explain it another way: applied
A lift checks its door-edge sensor many times a second while the doors close. If someone's arm breaks the beam, the next cycle's decision is 'reopen', and the motors reverse almost instantly.
Try these examples
Example 1
Split a smart greenhouse fan into sense, think and act.
The worked solution is in the online lesson.
Common mix-ups
A robot senses once, makes a plan and follows it.
✓ Reliable robots sense again and again while they act, so they can react to changes.Only motors count as actuators.
✓ Anything that changes the world on the machine's command counts: valves, heaters, lights, speakers.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot counts how many times its wheel has turned. Which stage is that?
- Sense
- Think
- Act
2. 'If the soil is drier than 30%, open the water valve.' Which stage is this sentence?
- Sense
- Think
- Act
3. Why must the sense–think–act loop keep repeating?
- To use up the battery evenly
- Because acting changes the world, so there is always something new to measure
- Because sensors only work once
4. A robot runs its sense–think–act loop 50 times every second. How many times does it run the loop in 3 seconds?
Answer:
Apply it
Design the sense–think–act loop for an automatic cat-flap that only lets your cat in. Name the sensor, write the rule as an IF sentence, and name the actuator. What should happen if the sensor can't tell?
Reflect
Which part of sense–think–act do you think is hardest to get right in a real robot, and why?
Who decides: the robot or the human?
A radio message to Mars can take over 20 minutes to arrive. If a rover is about to roll off a cliff, who should hit the brakes?
Why it matters
Every intelligent system is a team of human and machine. Engineers decide which decisions to hand to the machine, and which to keep for people. Get it wrong one way and the machine is useless; get it wrong the other and it is dangerous.
Goals
- Explain why some decisions must be made by the machine itself.
- Sort decisions into ones a human can make and ones the machine must make alone.
- Use a simple time calculation to justify autonomy.
Predict
A rover on Mars spots a rock in its path. A message takes 20 minutes each way. If it waits for Earth to say 'stop', how long until it gets the answer?
- 20 minutes
- 40 minutes
- Almost instantly
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Match each rover part to its job, then sort six decisions into 'Earth can decide' and 'the rover must decide alone'. Ask yourself for each one: can it wait 40 minutes?
What the interactive shows, in words
The rover activity can be replaced by this description: the rover's parts are a mast camera (finds landmarks), wheels (move and count distance), solar panel (power by day), battery (stores energy for night), antenna (talks to Earth) and computer (runs the plan). Earth chooses the science target and approves tomorrow's route; the rover itself handles hazard stops, position corrections, battery pauses and steering round rocks.
Understand
Autonomy means deciding alone
A machine is autonomous when it makes a decision without waiting for a person. Automatic doors are autonomous about opening. A Mars rover is autonomous about stopping for hazards. Even the smartest robot usually has some decisions it must hand back to people.
Speed decides who decides
If a decision has to be made faster than a human can respond, the machine must make it. Reflex-speed jobs like braking, balancing and stopping at a cliff edge go to the machine. Slower, bigger choices, such as which rock is scientifically interesting, can stay with people.
Humans keep the big picture
People are still better at goals, judgement and surprises nobody planned for. Good designs combine both: the machine handles the fast, routine decisions; humans set the goals and check the results.
Explain it another way: intuitive
When you touch a hot pan, your hand pulls back before your brain has finished thinking 'ouch'. Your spine made that decision on its own because it was too urgent to wait. Robots need reflexes like that too.
Explain it another way: technical
The human–machine split is a design choice called the level of autonomy. A rule of thumb: if the round-trip delay (sense → human → act) is longer than the time it takes for things to go wrong, the decision must be on board.
Explain it another way: mathematical
Round trip = 2 × one-way delay. At 20 minutes one way, the round trip is 40 minutes. A rover driving at 4 cm/s would cover 4 × 60 × 40 = 9,600 cm, about 96 m, before a reply arrived.
Explain it another way: applied
Self-parking cars decide steering and braking themselves, but the driver chooses the space and can cancel at any time. That split, machine for the fast stuff and human for the goal, is common in real products.
Try these examples
Example 1
A drone is flown by a person over a wifi link with a 0.2 s delay. Should the drone or the person handle staying level in a gust?
The worked solution is in the online lesson.
Common mix-ups
The best robots make every decision themselves.
✓ The best systems split decisions sensibly: machines take fast, routine ones; people keep goals and judgement.Radio is instant, so Earth can steer a rover live.
✓ Radio travels at the speed of light, but Mars is so far away that each message takes several minutes or more.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A rover's camera sees the ground drop away in front of it. Who should decide to stop?
- Mission control on Earth
- The rover, by itself
- Whoever is awake
2. Which decision is fine to leave to scientists on Earth?
- Braking before a rock
- Which crater to explore next week
- Steadying the wheels on a slope
3. A radio message takes 12 minutes to travel from Mars to Earth. What is the shortest time, in minutes, to send a photo to Earth and get a reply back?
Answer: min
4. A slow rover moves 5 cm every second. How many centimetres would it travel during a 60-second wait?
Answer: cm
Apply it
Design a robot lawnmower. List three decisions it must make by itself and two that the owner should make. For each, explain using time: how fast must it be decided?
Reflect
Would you trust a machine to make a decision for you? What would it need to show you first?
Week 20: Introduction to algorithms
This week you will
- Define an algorithm as a finite, exact, ordered list of steps.
- Draw a simple flowchart with a start, steps, a decision and an end.
- Compare two algorithms for the same job by counting their steps.
What is an algorithm?
You could teach a friend to make a sandwich in ten words. Could you teach a robot in ten words?
Why it matters
The 'think' part of every intelligent machine is an algorithm. Sat-navs, washing machines and traffic lights all run them. If you can write a clear algorithm, you can tell any machine what to do; if you can't, the most powerful computer in the world is useless.
Goals
- Define an algorithm as an exact, ordered, finite list of steps.
- Explain why machines need far more precise instructions than people.
- Write a short algorithm that a literal robot can follow.
Predict
You tell a robot: 'Go to the flag.' The robot only understands Forward 1, Turn left and Turn right. What does it do?
- Finds its way to the flag
- Nothing: 'go to the flag' isn't one of its instructions
- Moves forward until it hits something
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Build a program from Forward, Turn left and Turn right that takes the robot to the flag without hitting a red wall. Press Step to watch it run one instruction at a time.
What the interactive shows, in words
The grid robot can be replaced by this description: a 6-by-6 grid, robot at the bottom-left square (0, 0) facing north, flag at (4, 4), walls at (1, 1), (2, 1), (3, 1), (3, 3) and (2, 4). One safe program is: Forward, Forward, Turn right, Forward, Forward, Forward, Forward, Turn left, Forward, Forward (10 instructions).
Understand
An algorithm is a recipe for a machine
An algorithm is a list of steps that solves a problem. To count as one, the steps must be:
- Exact: each step means one thing only.
- Ordered: you know which step comes next.
- Finite: it finishes.
Machines take you literally
A person fills gaps with common sense: 'butter the bread' means use a knife, on one side. A machine has no common sense. If a step is vague, it either can't do it or does something surprising. Writing algorithms is the skill of leaving no gaps.
Big steps are made of small ones
'Go to the flag' is too big for the grid robot. 'Forward 1, Forward 1, Turn right, Forward 1…' uses only steps it knows. Breaking a big job into steps the machine already understands is called decomposition, and it is how all programs are built.
Explain it another way: intuitive
Giving directions to a tourist works because they can ask questions and look around. Writing an algorithm is like writing directions for someone who can't ask, can't look around and follows every word exactly.
Explain it another way: technical
A computer has a fixed set of basic instructions (its instruction set). Every program, however clever, is ultimately a sequence of these. Algorithms describe how to combine them to solve a problem.
Explain it another way: applied
A dishwasher runs an algorithm: fill, heat to 55 °C, spray for 30 minutes, drain, rinse, dry. Engineers test each step precisely because a vague step, like 'heat until hot', can't be built.
Try these examples
Example 1
Write an algorithm for the grid robot to go from (0, 0) facing north to (2, 1).
The worked solution is in the online lesson.
Common mix-ups
An algorithm has to be written in code.
✓ An algorithm is the list of steps. You can write it in plain words, a flowchart or code.There is one correct algorithm for each problem.
✓ Usually there are many. Engineers choose between them.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which of these is NOT a good algorithm for a robot?
- Forward 3, Turn right, Forward 2
- Move a bit, then go round the obstacle
- Repeat 4 times: Forward 1, Turn left
2. 'Step 1: Forward 1. Step 2: go back to step 1.' What is wrong with this as an algorithm?
- Nothing
- It never finishes
- It is not ordered
3. Two learners write different programs that both take the robot to the flag safely. Which is true?
- One must be wrong
- Both can be correct algorithms
- Only the first one written counts
4. A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: turn left, turn left, turn right, forward 1, turn left, forward 1. What is its final x (east–west) coordinate? Use a negative number for west.
Answer:
Apply it
Write an algorithm a robot could follow to tidy three books onto a shelf, using only these steps: move to (place), pick up, put down, turn. Swap with a friend and act it out exactly as written. Where did they have to guess?
Reflect
Where in your day do you follow an algorithm without thinking about it?
Drawing algorithms as flowcharts
A greenhouse heater has no idea what a plant is. How can a simple drawing keep seedlings alive all night?
Why it matters
Before engineers write code, they often draw it. A flowchart lets a whole team, including people who don't program, check an algorithm for mistakes. It is the most widely used design drawing in computing and control.
Goals
- Read a flowchart with start, step, decision and end shapes.
- Draw a flowchart for a short algorithm with one decision.
- Follow a flowchart for given inputs and say what happens.
Predict
A greenhouse controller repeats: measure the temperature, compare it with 18 °C, decide, act. Which step should come first?
- Act
- Decide
- Measure
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Match the greenhouse parts to their jobs, then put one turn of the control loop in order: measure, compare, decide, act. Sketch it as boxes and arrows as you go.
What the interactive shows, in words
The greenhouse activity can be replaced by this description: the parts are a thermometer (measures temperature), a setpoint (the temperature we want, 18 °C), a controller (compares and decides), a heater (adds heat), a vent and glass (lose heat) and the cold night (pulls the temperature down). One turn of the loop is: measure the temperature, compare it with the setpoint, decide whether to heat, act by switching the heater, then measure again.
Understand
Four shapes
Most flowcharts need only four shapes:
- Rounded box: start or end.
- Rectangle: do a step ("turn heater on").
- Diamond: ask a yes/no question ("colder than 18 °C?"), with two arrows out.
- Arrows: show what comes next.
Decisions split the path
A diamond is where an algorithm becomes intelligent: the path depends on the answer. Every diamond must have both a Yes and a No arrow, or the machine doesn't know what to do half the time.
Arrows can loop back
An arrow that points back to an earlier box makes the steps repeat. A thermostat's flowchart loops back to 'measure' for ever. You'll study loops properly in week 23; for now, notice how easy they are to see in a drawing.
Explain it another way: intuitive
A flowchart is like a board game path: you move along the arrows, and at some squares you must answer a question to know which way to go.
Explain it another way: technical
A flowchart is a directed graph: nodes are operations or decisions, edges are control flow. Each decision node has exactly two outgoing edges labelled true and false.
Explain it another way: applied
Hospital staff, pilots and factory workers all use flowcharts for emergencies ('Is the patient breathing? Yes → … No → …') because they are fast to follow under pressure and leave no gaps.
Try these examples
Example 1
Draw a flowchart for: 'If it is raining, take an umbrella. Then leave the house.'
The worked solution is in the online lesson.
Common mix-ups
Flowcharts are just for beginners.
✓ Professional engineers use them to design and check algorithms, especially for safety-critical systems.A decision only needs an arrow for the interesting answer.
✓ Every decision needs a path for both Yes and No.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which flowchart shape asks a yes/no question?
- Rectangle
- Diamond
- Rounded box
2. A flowchart diamond asks 'Door open?' and has only a Yes arrow. What's the problem?
- None, the No case doesn't matter
- The machine won't know what to do when the door is closed
- Diamonds should have three arrows
3. Flowchart: Start → 'Temperature below 18 °C?' Yes → 'Heater on'; No → 'Heater off' → back to Start. The thermometer reads 20 °C. What happens?
- Heater on
- Heater off
- Nothing
4. A flowchart has a start, an end, three action rectangles and two decision diamonds. How many arrows leave the decision diamonds altogether?
Answer:
Apply it
Draw a flowchart for a smart bin that opens its lid when someone's hand is near, waits 5 seconds, then closes. Include at least one diamond and make the chart loop back so it works all day.
Reflect
Was it easier to spot mistakes in the drawing or in written sentences? Why?
Some algorithms are better than others
Two robots count 30 boxes. One counts in ones, the other in twos. Both get 30. Which would you hire?
Why it matters
Once an algorithm works, engineers ask: can it be faster, cheaper, safer? A search engine, a sat-nav and a sorting machine all depend on clever algorithms that do the same job in far fewer steps. Counting steps is the first tool for judging an algorithm.
Goals
- Compare two correct algorithms by counting their steps.
- Explain why fewer steps matters for machines.
- Spot when a faster algorithm stops being correct.
Predict
Counting 30 people one at a time takes 30 counts. How many counts does it take if you count them in pairs (2, 4, 6…)?
- 30
- 15
- 60
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Choose 'Repeat until', start x at 0 and stop at 30. Run it adding 1 each pass, then adding 2, then 3. Write down how many passes each takes.
What the interactive shows, in words
The loop tracer can be replaced by this table for 'repeat until x ≥ 30, starting at 0': adding 1 each pass takes 30 passes; adding 2 takes 15; adding 3 takes 10; adding 4 takes 8 passes (x reaches 32, which overshoots 30).
Understand
Correct first, then fast
An algorithm that gives the wrong answer quickly is worse than useless. So engineers first check that an algorithm is correct for every case, then ask how many steps it takes.
Counting steps
We judge an algorithm by how many steps it needs, especially as the job gets bigger. Counting by ones takes 30 steps for 30 people and 1,000 steps for 1,000. Counting by twos takes half as many either way.
Clever tricks need checking
Faster algorithms often take a shortcut, and shortcuts have edge cases. Counting in twos goes wrong with an odd number of people unless you handle the last one. Always test the awkward cases: zero, one, odd, the biggest.
Explain it another way: intuitive
Looking for a word in a dictionary, you don't start at page 1: you open it in the middle and jump forwards or backwards. Same answer, far fewer pages turned.
Explain it another way: technical
Engineers describe how an algorithm's step count grows with the size of the problem. Counting one at a time grows in step with n; repeatedly halving (like the dictionary trick) grows much more slowly.
Explain it another way: mathematical
Counting n items in groups of g takes ⌈n ÷ g⌉ counts. For n = 30: g = 1 gives 30, g = 2 gives 15, g = 3 gives 10, g = 4 gives ⌈7.5⌉ = 8, because the last group is partly full.
Explain it another way: applied
A warehouse robot that plans its route with a smarter algorithm can pick orders in a fraction of the time. Over millions of orders, that saves enormous amounts of energy and money.
Try these examples
Example 1
A robot must check 20 lockers. Algorithm A checks every locker. Algorithm B checks only even-numbered lockers. Which is better?
The worked solution is in the online lesson.
Common mix-ups
The fastest algorithm is always the best.
✓ The best algorithm is correct first, then as efficient as it needs to be.If it works for one example, it works.
✓ Test the awkward cases too: zero, one, odd numbers and very large inputs.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. How many counts does it take to count 36 people in groups of 3?
Answer:
2. You count 25 people in pairs. How many counts do you need, including the last person on their own?
Answer:
3. Algorithm X takes 5 steps and is wrong for one input in ten. Algorithm Y takes 50 steps and is always right. For a lift's safety check, which should you choose?
- X, because it's faster
- Y, because it's always correct
- Either, it doesn't matter
4. A robot's counter starts at x = 2. The loop is: repeat until x ≥ 24: x = x + 4. How many times does the loop body run?
Answer:
Apply it
Invent two algorithms for finding the tallest person in your class. Count how many comparisons each needs for 10 people. Is one always correct? Is one faster?
Reflect
Can you think of a shortcut you use that sometimes gives the wrong answer?
Week 21: Sequences and instructions
This week you will
- Explain why the order of instructions changes the result.
- Write precise instructions that a literal-minded robot can follow.
- Find and fix a bug in a sequence by tracing it step by step.
Order matters
A lift opens its doors, then moves to floor 7. Every step was correct. Why is everyone screaming?
Why it matters
In real machines the order of steps is often a matter of safety. A lift must close its doors before it moves; a washing machine must drain before it unlocks. Engineers spend a lot of time asking 'what has to be true before this step is allowed?'
Goals
- Explain that the same steps in a different order can give a different result.
- Put the stages of a real machine's routine in a safe order.
- Identify which steps must come before which others.
Predict
A robot runs 'Turn right, then Forward 2' from (0, 0) facing north. A second robot runs 'Forward 2, then Turn right'. Do they end up in the same square?
- Yes, same steps
- No, they end in different squares
- Only if the grid is empty
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Watch a lift trip, then put the seven stages of a trip in order. For each stage, ask: what must already have happened before this is safe?
What the interactive shows, in words
The lift activity can be replaced by this description: a lift has a counterweight (balances the cabin), a door-edge sensor (detects anything in the doorway), a floor position sensor (where the cabin is), a load-weighing sensor (how heavy it is) and a motor with a pulley (turns the ropes). A trip goes: call registered, doors close, accelerate, cruise, slow down, level, doors open.
Understand
A sequence is steps in order
A sequence is the simplest kind of algorithm: do this, then this, then this. Most programs are mostly sequences, with decisions and loops mixed in.
Swapping steps can change everything
Some steps don't care about order: putting on your left sock or right sock first. Others do: socks before shoes. Turning before or after moving sends a robot to a completely different place.
Before-and-after rules
Engineers write down which steps must come before others: 'doors closed before the lift moves', 'drain before unlock'. Any order that breaks one of these rules is unsafe, even if every individual step is fine.
Explain it another way: intuitive
Baking a cake: mix, then bake, then ice. Ice, then bake, then mix gives you a disaster made of exactly the same ingredients.
Explain it another way: technical
Operations that change the system's state usually do not commute: doing A then B gives a different state from B then A. Engineers record ordering constraints as 'A must happen before B'.
Explain it another way: applied
Lift controllers use interlocks: the motor physically cannot be powered until the door-closed sensor confirms the doors are shut. The order is enforced by the design, not just by the program.
Try these examples
Example 1
Put these lift stages in a safe order: accelerate, doors open, call registered, level with the floor, doors close, cruise, slow down.
The worked solution is in the online lesson.
Common mix-ups
If every step is correct, the program is correct.
✓ Correct steps in the wrong order can be wrong, or dangerous.Turning moves the robot.
✓ A turn only changes which way it faces. Its position stays the same.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which pair of steps can safely be done in either order?
- Close the lift doors / start the motor
- Brush your left teeth / brush your right teeth
- Drain the water / unlock the washing-machine door
2. A robot at (0, 0) faces north. It runs: Turn right, Forward 1, Forward 1. Where does it end?
- (0, 2)
- (2, 0)
- (1, 1)
3. What must happen before a washing machine's door is allowed to unlock?
- The drum must be spinning
- The water must have drained and the drum stopped
- The detergent must be added
4. A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: turn left, turn left, turn right, forward 1, turn left, forward 1. What is its final x (east–west) coordinate? Use a negative number for west.
Answer:
Apply it
Write the steps for a robot that makes a cup of squash (fetch cup, add squash, add water, stir, serve). Which steps can swap places, and which must never swap? Write one 'must happen before' rule.
Reflect
Think of a time you did the right things in the wrong order. What happened?
Instructions a robot can't misunderstand
'Walk forward until you reach the door.' Simple for you. Why could it send a robot through a wall?
Why it matters
Most bugs in real machines aren't the machine's fault: they're instructions that meant one thing to the person who wrote them and something else to the machine. Learning to write exact instructions is a superpower for any engineer.
Goals
- Rewrite vague instructions as exact ones a machine can follow.
- Use position and facing direction to predict a robot's path.
- Break a route into short instruction sequences.
Predict
The robot starts at (0, 0) facing north and runs 'Forward 1' four times, then 'Turn right' and 'Forward 1' four times. Walls are at (2, 4) among others. What happens?
- It reaches (4, 4)
- It stops at (1, 4) because the next square is a wall
- It goes round the wall
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Try the four-forwards-then-turn program from the prediction and watch it get stuck. Then find a program that reaches the flag. Count your instructions.
What the interactive shows, in words
The grid robot can be replaced by this description: on a 6-by-6 grid with walls at (1, 1), (2, 1), (3, 1), (3, 3) and (2, 4), the program 'Forward ×4, Turn right, Forward ×4' stops at (1, 4) because (2, 4) is a wall. Going up two, then east four, then north two reaches the flag at (4, 4) in 10 instructions.
Understand
Vague words to avoid
Words like a bit, until it looks right, nearby or carefully mean nothing to a machine. Replace them with things it can count or measure: Forward 3, until the distance sensor reads less than 10 cm, turn 90° right.
Track two things
To predict a grid robot, keep track of where it is (x, y) and which way it faces. Forward changes the position in the facing direction. Turns change only the direction. Writing both down after every step is the most reliable way to follow a program.
Chunk the route
Long programs are easier to write in chunks: 'get to the corridor', 'go along the corridor', 'turn into the room'. Each chunk is a short sequence. This is decomposition, and it makes mistakes much easier to find.
Explain it another way: intuitive
Imagine guiding a blindfolded friend through an obstacle course using only 'step', 'turn left' and 'turn right'. You'd watch every step and count carefully, because they'll do exactly what you say.
Explain it another way: technical
The robot's state is (x, y, heading). Forward maps (x, y) to (x + dx, y + dy) where (dx, dy) depends on heading: north (0, 1), east (1, 0), south (0, −1), west (−1, 0). Turns rotate the heading by 90°.
Explain it another way: applied
Factory robots are programmed with exact coordinates and angles. A pick-and-place robot told to move 'roughly above the box' would be useless; it is told to move to (412.5 mm, 128.0 mm) at a precise speed.
Try these examples
Example 1
Make this exact: 'Go forward a few squares, then turn towards the flag.' The flag is 3 squares north and 2 east of the robot, which faces north.
The worked solution is in the online lesson.
Common mix-ups
The robot will steer round obstacles it can see.
✓ A robot following a fixed sequence doesn't look. It runs each instruction exactly, even into a wall.Turning left then right moves you sideways.
✓ Left then right just puts you back to facing the same way, in the same square.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which instruction is exact enough for a robot?
- Drive forward a bit
- Drive forward 50 cm
- Drive forward until it feels right
2. A robot at (3, 2) facing east does 'Turn left'. Where is it now, and which way does it face?
- (3, 2), facing north
- (3, 3), facing north
- (2, 2), facing west
3. A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: forward 1, forward 1, forward 1, forward 1, forward 1, forward 1. What is its final y (north–south) coordinate? Use a negative number for south.
Answer:
4. A robot faces north (0°). Compass angles go clockwise: east 90°, south 180°, west 270°. It makes these 90° turns: right, right, right, left, right. Which compass angle does it face at the end (0 to 270)?
Answer:
Apply it
Write exact instructions to guide the grid robot from (0, 0) to the flag at (4, 4) in as few instructions as you can, avoiding all the walls. Can you beat 10?
Reflect
Which vague word do you use most when giving directions? What exact version could replace it?
Debugging: find the step that went wrong
Your robot crashes on step 4 of 10. Is the bug in step 4?
Why it matters
Every engineer spends a large part of their time debugging. The best ones don't guess; they trace. Stepping through a program, writing down what happens, and comparing it with what should happen is the single most useful habit you can build.
Goals
- Trace a program one step at a time to locate a bug.
- Explain that the bug may be before the step where things go wrong.
- Fix a bug and re-test the whole program.
Predict
A program says: Forward, Forward, Turn left, Forward… The robot (starting at (0, 0) facing north) crashes on the 4th instruction. Where is the bug most likely to be?
- In instruction 4
- In instruction 3: it should have been Turn right
- In instruction 1
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Press 'Load a buggy program', then use Step to run it one instruction at a time. Find the instruction that caused the crash, fix it with the arrow and delete buttons, and run it again from the start.
What the interactive shows, in words
The grid robot can be replaced by tracing on squared paper: the buggy program Forward, Forward, Turn left, Forward… starts at (0, 0) facing north, reaches (0, 2), turns to face west, then crashes off the left edge on instruction 4. Changing instruction 3 to Turn right (and the later Turn right to Turn left) makes it reach the flag at (4, 4).
Understand
Bug: where it shows vs where it is
A bug is a mistake in a program. Where things visibly go wrong (the crash) is often later than where the mistake was made (a wrong turn earlier). Debugging means working backwards from the symptom to the cause.
Trace, don't guess
Run the program one step at a time. After each step, write down what the robot should be doing and what it is doing. The first step where they disagree is your bug. This is called tracing.
Fix, then test everything
Changing one instruction can break a later one, because every step after it now starts from a different place. After a fix, always run the whole program from the start again, not just the part you changed.
Explain it another way: intuitive
If you get lost walking to a friend's house, the place you notice you're lost isn't where you went wrong. You retrace your steps to find the wrong turn.
Explain it another way: technical
Debugging compares the expected state with the actual state at each step. The bug lies at or before the first step where they differ. Tools called debuggers let programmers step through code exactly like the Step button.
Explain it another way: applied
Spacecraft software is tested by running whole missions in simulation, step by step, before launch. When something goes wrong, engineers replay the log to find the first moment the spacecraft's state disagreed with the plan.
Try these examples
Example 1
The program 'Forward, Forward, Turn left, Forward, Forward, Forward, Forward, Turn right, Forward, Forward' crashes on step 4. Trace it and fix it.
The worked solution is in the online lesson.
Common mix-ups
The bug is always on the line where things go wrong.
✓ It's often earlier. Trace back to the first step where expected and actual differ.Once you've fixed a bug, you're done.
✓ Re-test the whole program; fixes can cause new problems further on.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot crashes into a wall on instruction 6. Which statement is true?
- The bug must be in instruction 6
- The bug is at instruction 6 or earlier
- The bug is after instruction 6
2. You fix instruction 3 of a 10-step program. What should you do next?
- Run just instruction 3 again
- Run the whole program from the start
- Nothing, it's fixed
3. A robot faces north (0°). Compass angles go clockwise: east 90°, south 180°, west 270°. It makes these 90° turns: right, right, right, left. Which compass angle does it face at the end (0 to 270)?
Answer:
4. A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: turn left, turn left, turn right, forward 1, turn left, forward 1. What is its final x (east–west) coordinate? Use a negative number for west.
Answer:
Apply it
Write a 6-instruction program with one deliberate bug for a friend. Swap programs, trace each other's step by step on squared paper, and write down the step number where expected and actual first disagree.
Reflect
What is the difference between guessing at a fix and tracing to find a bug? Which did you do first?
Week 22: Conditional behaviour
This week you will
- Read and write IF–THEN–ELSE rules that depend on a sensor.
- Choose a sensible threshold and test readings at its edge.
- Combine conditions with AND, OR and NOT.
IF this, THEN that, ELSE the other
One sentence beginning with 'if' stops a robot vacuum falling down the stairs. What is that sentence?
Why it matters
Conditions are where a program starts to respond to the world. Every intelligent machine you've met this term is built from rules like 'if the floor disappears, stop'. Learning to write them clearly is learning to give a machine good judgement.
Goals
- Read and write IF–THEN–ELSE rules that use a sensor reading.
- Decide which branch runs for a given reading.
- Explain why every rule needs an ELSE (or a deliberate 'do nothing').
Predict
Rule: IF distance < 20 cm THEN stop ELSE drive. The sensor reads exactly 20 cm. What does the robot do?
- Stop
- Drive
- Nothing, it's confused
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Set a rule, then slide the reading across the threshold. Look at the colour strip: every reading runs exactly one branch. Try switching < to > and see the strip flip.
What the interactive shows, in words
The rule tester can be replaced by this table for the rule IF distance < 20 cm THEN stop ELSE drive: 5 cm → stop; 19 cm → stop; 20 cm → drive; 21 cm → drive; 60 cm → drive; 100 cm → drive.
Understand
A condition is a yes/no question
A condition is something that is either true or false: distance < 20, button pressed, temperature > 28. Comparisons use symbols: < less than, > greater than, = equal to. Remember: 20 < 20 is false.
Two branches
IF the condition is true, THEN do one thing. ELSE (otherwise) do another. Exactly one branch runs every time the rule is checked, never both and never neither.
Choosing the ELSE
The ELSE matters as much as the THEN. 'IF dark THEN light on' with no ELSE means the light never goes off! Sometimes 'do nothing' is right, but it should be a choice you made, not something you forgot.
Explain it another way: intuitive
IF it's raining THEN take a coat ELSE take sunglasses. You check the sky, get one answer, and do one thing.
Explain it another way: technical
A conditional evaluates a Boolean expression and transfers control to one of two blocks. In most programming languages it looks like: if (distance < 20) { stop(); } else { drive(); }
Explain it another way: applied
Robot vacuums have downward-facing 'cliff sensors' that measure the distance to the floor. IF that distance suddenly gets large (stairs) THEN stop and reverse ELSE carry on cleaning.
Try these examples
Example 1
A fan rule is: IF temperature > 26 °C THEN fan on ELSE fan off. What happens at 24, 26 and 30 °C?
The worked solution is in the online lesson.
Common mix-ups
'Less than 20' includes 20.
✓ It doesn't. If you mean 20 or less, write ≤ 20 (less than or equal to).If the THEN part doesn't run, nothing happens.
✓ The ELSE part runs instead. If you leave it out, make sure 'nothing' really is safe.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. IF light level < 30 THEN lamp on ELSE lamp off. The sensor reads 45. What happens?
- Lamp on
- Lamp off
- Both
2. IF speed > 50 THEN beep. The speed is exactly 50. Does it beep?
- Yes
- No
3. A night light's only rule is: IF dark THEN lamp on. What goes wrong?
- The lamp never turns on
- Once on, the lamp never turns off
- Nothing
4. Rule: IF distance < 30 cm THEN stop. The sensor reads 38 cm, 44 cm, 29 cm, 30 cm, 31 cm, 15 cm. For how many of these readings does the THEN branch run?
Answer:
Apply it
Write IF–THEN–ELSE rules for a smart bin: it opens when a hand is within 15 cm and closes otherwise. Test your rule at 10, 15 and 20 cm. Did 15 cm do what you wanted? If not, change < to ≤.
Reflect
When you make a decision with 'if', do you always think about the 'else'?
Choosing a good threshold
A sorting machine calls a part 'large' if it's over 65 mm. A part measures 64.9 mm. Is it large?
Why it matters
A sensor gives a number; a machine needs a decision. The threshold is the bridge. Smoke alarms, spam filters, medical tests and sorting machines all work by picking a threshold, and picking it well is a real engineering decision with real consequences.
Goals
- Explain what a threshold is and how it splits readings into groups.
- Sort items using a given threshold, including at the edge.
- Describe the trade-off when a threshold is moved up or down.
Predict
A smoke alarm sounds when its smoke reading goes above a threshold. If engineers lower the threshold, what happens?
- Fewer false alarms, but slower to warn
- Faster warnings, but more false alarms from toast
- No change
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Use the client's brief and thresholds to sort six parts by hand. Look closely at any part whose reading is near a threshold: which side of the line is it on?
What the interactive shows, in words
The sorting-machine activity can be replaced by this description: a colour sensor says how red each part is, a light gate measures its length and a metal detector senses metal. The client's brief sends metal parts to the Metal bin, large non-metal parts to Reject, small red plastic to Red, and everything else to Mixed. One part measures 58 mm, which is below the 65 mm size limit, so it is not large.
Understand
A threshold draws a line
A threshold is a value that splits readings into two groups: above and below. 'Large' means size > 65 mm. 'Dark' means light level < 30. The rule only cares which side of the line a reading is on, not how far.
Two kinds of mistake
Real readings are a bit noisy. Put the threshold too low and you get false alarms (reacting when you shouldn't). Too high and you get misses (not reacting when you should). Moving the line always trades one for the other.
Picking the value
Engineers choose a threshold by looking at real readings from both groups and putting the line in the gap between them. If there's no clear gap, they think about which mistake is worse. For a smoke alarm, a miss is far worse than a false alarm.
Explain it another way: intuitive
A height bar at a theme park ride is a threshold. Everyone taller than the line can ride; everyone shorter can't. Where the park puts that line is a safety decision.
Explain it another way: technical
Thresholding turns a continuous measurement into a category. With noisy sensors the groups overlap, so any threshold produces some false positives and some false negatives; the threshold sets the balance between them.
Explain it another way: applied
A greenhouse controller might open the vents above 28 °C. Set it at 24 °C and the vents flap open on every sunny spell, wasting heat; set it at 35 °C and the seedlings cook before anything happens.
Try these examples
Example 1
A part sorter calls a part 'large' if its length > 65 mm. Parts measure 58, 65, 66 and 80 mm. Which are large?
The worked solution is in the online lesson.
Common mix-ups
A perfect threshold never makes mistakes.
✓ With real, noisy readings, every threshold makes some mistakes. You choose which kind you'd rather have.A reading on the threshold counts as above it.
✓ That depends on whether the rule says > or ≥. Always check the edge.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Rule: IF temperature > 40 °C THEN switch the fan on. The sensor reads 41 °C, 55 °C, 40 °C, 33 °C, 43 °C, 47 °C. For how many of these readings does the THEN branch run?
Answer:
2. A doorbell camera alerts you when motion is above a threshold. Leaves blowing keep triggering it. What should you do?
- Lower the threshold
- Raise the threshold
- Remove the threshold
3. For a smoke alarm, which mistake is worse?
- A false alarm from toast
- Missing a real fire
4. Small parts measure between 40 and 55 mm. Large parts measure between 75 and 90 mm. A good threshold sits halfway across the gap between the groups. What value is that, in mm?
Answer: mm
Apply it
Design a 'too loud' warning light for a classroom. Choose a threshold for a sound sensor (say, 0–100). Describe one situation that would cause a false alarm and one that would cause a miss. Which would you rather risk?
Reflect
Can you think of a threshold in your own life, like a grade boundary? Who chose it, and what does it trade off?
AND, OR, NOT: combining conditions
A lift should move only if the doors are closed AND someone pressed a button. What happens if an engineer types OR by mistake?
Why it matters
Real decisions rarely depend on one thing. A rover drives only if the path is clear AND the battery is fine. An alarm sounds if the door opens OR a window breaks. These three little words are also the building blocks of every computer chip.
Goals
- Combine two conditions using AND, OR and NOT.
- Fill in a truth table for a combined rule.
- Choose the right combination for a safety rule.
Predict
Rule: drive IF path clear AND battery OK. The path is clear but the battery is low. Does it drive?
- Yes
- No
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Try an AND gate, then an OR gate, then NOT. Flip the inputs through every combination (off-off, off-on, on-off, on-on) and write down when the output is on.
What the interactive shows, in words
The logic lab can be replaced by these truth tables. AND: off+off → off, off+on → off, on+off → off, on+on → on. OR: off+off → off, off+on → on, on+off → on, on+on → on. NOT: off → on, on → off.
Understand
AND: everything must be true
A AND B is true only when A is true and B is true. One false makes it false. Use AND when every condition is required: move IF doors closed AND button pressed.
OR: anything will do
A OR B is true when A is true, or B is true, or both. Only false when both are false. Use OR when any one reason is enough: alarm IF door opens OR window breaks.
NOT: flip it
NOT A is true when A is false. It lets you write rules like drive IF NOT obstacle. Combine them: drive IF path clear AND NOT battery low.
Truth tables
With two conditions there are only four possibilities: both false, first only, second only, both true. A truth table lists all four and the result. Checking all four rows is a quick way to make sure a rule does what you mean.
Explain it another way: intuitive
A theme park ride: you can go on IF you're tall enough AND you have a ticket. You get free entry IF it's your birthday OR you're under 5.
Explain it another way: technical
AND, OR and NOT are Boolean operators. With two inputs, AND is true in 1 of 4 rows, OR in 3 of 4. Every digital circuit, from a calculator to a phone, is built from gates that compute these.
Explain it another way: applied
Factory machines use 'two-hand controls': the press only moves IF the left button AND the right button are both held. That guarantees both of the operator's hands are well away from the blade.
Try these examples
Example 1
Fill in the truth table for 'lift moves IF doors closed AND call pressed'.
The worked solution is in the online lesson.
Common mix-ups
OR means one or the other but not both.
✓ In logic, OR is also true when both are true. 'One but not both' is a different operator called XOR.AND and OR are interchangeable in everyday rules.
✓ They give very different behaviour. For safety, AND usually means 'every condition must be met'.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A burglar alarm should sound if the door opens or a window breaks. Which word joins the two conditions?
- AND
- OR
- NOT
2. A paper shredder should run only when the bin is in place and paper is detected. Which rule is right?
- Run IF bin in place OR paper detected
- Run IF bin in place AND paper detected
- Run IF NOT paper detected
3. In the four-row truth table for A OR B, in how many rows is the result true?
Answer:
4. A rover's rule is 'drive IF NOT obstacle'. The obstacle sensor says true. Does it drive?
- Yes
- No
Apply it
Write a combined rule for a plant-watering helper: water IF the soil is dry AND it is NOT already raining. Draw its four-row truth table. Then add a third condition of your own and say whether it joins with AND or OR.
Reflect
Can you think of a rule at school or home that secretly uses AND or OR?
Week 23: Repetition and loops
This week you will
- Trace a repeat-N-times loop and predict its final value.
- Explain how a repeat-until loop knows when to stop.
- Recognise the forever loop inside every robot controller.
Repeat N times
A robot must draw a square. You could write eight instructions. Could you write it in three?
Why it matters
Machines are brilliant at doing the same thing again and again without getting bored or making a mistake. Loops are how you tell them to. They make programs shorter, easier to read and easier to fix: change one line inside the loop and every repeat changes.
Goals
- Use a 'repeat N times' loop to shorten a program.
- Trace a loop with a trace table and predict its final value.
- Calculate a loop's result with multiplication.
Predict
x starts at 2. A loop runs 'x = x + 3' four times. What is x at the end?
- 5
- 14
- 12
Write down your guess and your reason. The reveal is in the online lesson.
Discover
In 'Repeat N times' mode, set x to start at 2, add 3, repeat 4 times. Press Next pass one at a time and fill in the trace table. Then try adding a negative number.
What the interactive shows, in words
The loop tracer can be replaced by this trace table for x = 2, repeat 4 times x = x + 3: pass 1, 2 → 5; pass 2, 5 → 8; pass 3, 8 → 11; pass 4, 11 → 14. Final x = 14 = 2 + 4 × 3.
Understand
Write it once, run it many times
A square is 'Forward, Turn right' four times. Instead of eight lines, write: repeat 4 times: Forward, Turn right. The instructions inside the loop are called the loop's body.
Variables change each pass
A variable is a named box holding a value, like x = 2. A loop body like x = x + 3 means 'take what's in x, add 3, put it back'. After each pass, x has changed.
Trace tables
To check a loop by hand, draw a table: pass number, value before, value after. Fill one row per pass. This is exactly how professional programmers check tricky loops.
The shortcut
If the body adds the same number every time: final = start + N × step. A trace table and the formula should always agree; if they don't, one of them has a mistake.
Explain it another way: intuitive
'Do 10 star jumps' is a loop. You don't need ten separate instructions; you need one instruction and a count.
Explain it another way: technical
A counted loop runs its body a fixed number of times, usually with a counter variable from 1 to N. In Python it looks like: for i in range(4): x = x + 3
Explain it another way: mathematical
Adding step s, N times, to a start value a gives a + N·s. With a = 2, s = 3, N = 4: 2 + 4 × 3 = 14. If s is negative, x goes down: a = 10, s = −2, N = 3 gives 10 − 6 = 4.
Explain it another way: applied
A 3D printer builds an object as a loop: repeat for every layer: trace this layer, move up 0.2 mm. A 10 cm tall print is 500 passes of the same loop.
Try these examples
Example 1
Write a loop that makes the grid robot walk in a square with sides of 2 squares.
The worked solution is in the online lesson.
Common mix-ups
x = x + 3 is impossible because x can't equal x + 3.
✓ In programs, = means 'store'. It works out the right side and stores it in x.A loop runs its body once and then repeats the last line.
✓ The whole body runs on every pass.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. x starts at 8. A loop runs "x = x + 2" exactly 6 times. What is x when the loop ends?
Answer:
2. x starts at 2. A loop runs "x = x + -1" exactly 4 times. What is x when the loop ends?
Answer:
3. Without a loop, how many instructions does it take to drive a square with 'Forward 1, Turn right' for each side?
Answer:
4. x starts at 7. A loop says 'repeat 0 times: x = x + 5'. What is x afterwards?
- 7
- 12
- 0
Apply it
Write a loop for the grid robot that makes a staircase: three steps up and to the right. Then trace it by hand and write down the robot's position after each pass.
Reflect
What in your life is a 'repeat N times' loop? How do you keep count?
Repeat until: loops that decide when to stop
You don't know how many spoons of sugar a cup of tea needs until you taste it. How does a machine 'taste'?
Why it matters
Most real loops don't know in advance how many times to run. A robot drives forward until it reaches a wall; a kettle heats until it boils; a washing machine fills until the water level sensor says full. Repeat-until joins loops and conditions into one powerful idea.
Goals
- Explain how a repeat-until loop uses a condition to stop.
- Count how many passes a repeat-until loop makes.
- Spot a loop that would never stop.
Predict
x starts at 0. Repeat until x ≥ 10: x = x + 3. How many times does the body run?
- 3
- 4
- 10
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Switch to 'Repeat until'. Start at 0, add 3, stop when x reaches 10. Step through it. Then set the start above the limit and see how many times the body runs.
What the interactive shows, in words
The loop tracer can be replaced by this trace for x = 0, repeat until x ≥ 10, x = x + 3: pass 1, 0 → 3; pass 2, 3 → 6; pass 3, 6 → 9; pass 4, 9 → 12. Stops after 4 passes at 12. If x starts at 25 the condition is already true and the body runs 0 times.
Understand
Check, then repeat
A repeat-until loop checks a condition before each pass. If the condition is true, it stops. If not, it runs the body and checks again. The number of passes depends on what happens, not on a fixed count.
Something must change
The body must change something the condition depends on: x grows, the robot moves closer, the water rises. If nothing changes, the condition never becomes true and the loop runs for ever: an infinite loop, one of the most famous bugs.
Overshoot and zero passes
Two edge cases to test. Overshoot: if x jumps in big steps, it may pass the limit (9 → 12, not 10). Zero passes: if the condition is already true at the start, the body never runs at all.
Explain it another way: intuitive
Filling a glass: pour until it's full. You don't count the seconds; you watch the level and stop when it reaches the top.
Explain it another way: technical
A condition-controlled loop (a while loop in most languages) tests its condition each time round. 'Repeat until done' is the same as 'while not done'. Its body must make progress towards the stopping condition.
Explain it another way: mathematical
Starting at a and adding s until x ≥ L, the number of passes is the smallest whole number n with a + n·s ≥ L. For a = 0, s = 3, L = 10: n = 4, because 3 × 3 = 9 < 10 but 4 × 3 = 12 ≥ 10.
Explain it another way: applied
A lift's levelling routine is a repeat-until loop: creep the cabin until the floor sensor says it's within a few millimetres of the floor. It doesn't know in advance how many tiny moves that takes.
Try these examples
Example 1
A tank holds 2 litres of water. A pump adds 5 litres a minute. Repeat until the water ≥ 20 litres. How many minutes does it run?
The worked solution is in the online lesson.
Common mix-ups
A repeat-until loop always runs at least once.
✓ This kind checks first, so it can run zero times. (Some languages also have a check-after loop that always runs once.)The loop stops exactly at the limit.
✓ It stops at the first value that meets the condition, which may be past the limit.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot's counter starts at x = 4. The loop is: repeat until x ≥ 21: x = x + 2. How many times does the loop body run?
Answer:
2. A robot's counter starts at x = 1. The loop is: repeat until x ≥ 12: x = x + 5. How many times does the loop body run?
Answer:
3. Repeat until distance < 10: beep. The robot isn't moving. What happens?
- It beeps once
- It beeps for ever, unless something else moves
- It stops at once
4. x starts at 25. Repeat until x ≥ 20: x = x + 2. How many times does the body run?
- 0
- 1
- It never stops
Apply it
Write a repeat-until loop for a robot that drives towards a wall, checking its distance sensor each pass and moving 5 cm at a time. Start 37 cm away and stop when closer than 10 cm. How many passes, and where does it stop?
Reflect
What's something you do 'until' something happens? What would make you stop?
The forever loop inside every robot
Infinite loops are a bug, right? So why does every traffic light controller run one on purpose?
Why it matters
A robot that stops checking its sensors is a robot that crashes. Every controller, from a thermostat to a self-driving car, is a loop that never ends: sense, think, act, again. Seeing that loop is the key to understanding how intelligent machines stay intelligent.
Goals
- Explain why control programs run in a forever loop.
- Combine a loop with sense–think–act and a condition.
- Describe a machine's cycle of states that repeats.
Predict
A traffic light runs green → amber → red → green… Where does the program end?
- After one cycle
- After 24 hours
- It doesn't end: it repeats as long as it's switched on
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Judge six moments at the crossroads as safe or a conflict, then say what the lights must show next. Notice how the cycle wraps round from the last state back to the first, for ever.
What the interactive shows, in words
The traffic activity can be replaced by this description: at a crossroads, north–south and east–west roads take turns. A safe cycle is: north–south green, north–south amber, all red, east–west green, east–west amber, all red, walk, flashing don't-walk, all red, then back to the start. It is a conflict if one road shows green or amber while the other shows green, or if walk shows while any road has green.
Understand
Forever on purpose
A control program looks like this:
forever: sense → think → act
It never finishes because the world never stops changing. A forever loop is only a bug when you wanted the loop to stop.
Conditions inside loops
Inside the forever loop sit IF rules: forever: read temperature; IF too cold THEN heater on ELSE heater off. The loop makes sure the rule is checked again and again; the rule decides what to do each time.
Cycles of states
Some machines step through a fixed list of states and wrap round: green, amber, all red, other road green, and so on. The traffic light's forever loop moves from state to state, with rules saying when each change is allowed and what must never be on at the same time.
Explain it another way: intuitive
Your heart is a forever loop: beat, rest, beat, rest, for your whole life. It also adjusts as it goes: faster when you run, slower when you sleep.
Explain it another way: technical
Embedded controllers usually have a 'main loop' that runs until power is removed. Each pass reads inputs, updates the current state and writes outputs. A state machine inside it decides which state comes next.
Explain it another way: applied
A robot vacuum's main loop runs many times a second: read bump, cliff and wheel sensors; update its map; choose a direction; set wheel speeds. It only stops when you switch it off or it docks to charge.
Try these examples
Common mix-ups
All infinite loops are bugs.
✓ Controllers run forever loops on purpose. It's a bug only when a loop that should stop doesn't.A robot checks its rules once when switched on.
✓ It checks them on every pass of its main loop, many times a second.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. When is a loop that never ends the right design?
- Never: it's always a bug
- When the machine must keep watching and reacting for as long as it's on
- Only on very fast computers
2. Where should the IF rule 'IF too hot THEN fan on' go in a thermostat program?
- Before the forever loop, run once
- Inside the forever loop
- After the forever loop
3. A traffic light's cycle is green 30 s, amber 3 s, red 37 s, then repeats. How many full cycles does it complete in 7 minutes (420 s)?
Answer:
4. A robot's main loop runs every 20 milliseconds (0.02 s). How many passes does it make in one second?
Answer:
Apply it
Write a forever loop for a pedestrian crossing: the light stays green for cars until the button is pressed, then goes amber, then red with the walk sign, then back to green. Which rule would you add so that nobody can ever see walk while cars have green?
Reflect
Which machines around you are running a forever loop right now?
Week 24: Sensors and actuators
This week you will
- Sort a machine's parts into sensors, controller and actuators.
- Explain that every sensor reading is imperfect.
- Describe how motors and joints let a machine act.
Sensors: how machines feel the world
Bats find moths in the dark by shouting and listening. Which robot sensor copies them?
Why it matters
A machine is only as clever as what it can sense. Choosing the right sensor is one of the first and most important design decisions an engineer makes. Pick the wrong one and no amount of clever programming will help.
Goals
- Describe what a sensor does: turn something in the world into a reading.
- Match common sensors to what they measure.
- Sort a machine's parts into sensing, thinking and acting.
Predict
An ultrasonic sensor sends a click of sound and listens for the echo. If the echo comes back faster, is the object closer or further away?
- Closer
- Further away
- It can't tell
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Sort each part into Sense, Think or Act. Read the explanation after each choice, especially for any you got wrong.
What the interactive shows, in words
The sorting activity can be replaced by this list. Sense: ultrasonic distance sensor, bump switch, thermometer, wheel encoder. Think: microcontroller. Act: DC motor, buzzer, servo motor, heater.
Understand
A sensor turns the world into a number
A sensor measures something physical and reports it as a reading the controller can use: a distance in cm, a temperature in °C, pressed or not pressed. Without sensors, a machine is blind and deaf.
A sensor zoo
- Distance: ultrasonic (sound echoes) or infrared (light).
- Touch: bump switches, pressure pads.
- Light: light sensors, cameras.
- Temperature: thermometers.
- Movement: wheel encoders count turns; accelerometers feel tilt and shaking.
On/off or a number
Some sensors give just two answers (digital: pressed or not). Others give a whole range (analogue: 0 to 100 cm). A bump switch only tells you that you hit something; a distance sensor tells you how close it is before you hit it.
Explain it another way: intuitive
Your senses are sensors: eyes for light, ears for sound, skin for touch and temperature. A robot just has different ones, and often only a few.
Explain it another way: technical
A sensor converts a physical quantity into an electrical signal, which is turned into a number. Each sensor has a range (what it can measure), a resolution (smallest change it notices) and some noise.
Explain it another way: mathematical
An ultrasonic sensor measures the echo time t. Sound goes there and back, so distance = speed × t ÷ 2. With t = 0.002 s: 343 × 0.002 ÷ 2 ≈ 0.34 m, about 34 cm.
Explain it another way: applied
Cars use ultrasonic sensors in the bumpers for parking beeps, cameras for lane-keeping, and wheel-speed sensors for anti-lock brakes. Each is chosen for the one job it does best.
Try these examples
Example 1
A robot must stop before touching a wall and also know if it has been bumped from behind. Choose sensors.
The worked solution is in the online lesson.
Common mix-ups
A camera is the best sensor for everything.
✓ Cameras are powerful but need lots of processing and struggle in the dark. Often a simple sensor does the job better.An ultrasonic sensor's echo time is the time to reach the object.
✓ It's the time there and back, so halve it.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A greenhouse needs to know when the soil is dry. Which sensor fits?
- Light sensor
- Soil moisture sensor
- Wheel encoder
2. Which sensor gives only two possible answers?
- A bump switch
- A thermometer
- An ultrasonic distance sensor
3. Is a speaker a sensor or an actuator?
- Sensor
- Actuator
4. Sound travels 340 m/s. An echo comes back after 0.01 s. How far away is the object, in metres? (Remember: there and back.)
Answer: m
Apply it
Choose the sensors for a robot that follows a black line on a white floor and stops if someone stands in front of it. Name each sensor, what it measures, and whether its reading is digital or analogue.
Reflect
If you could give a robot one sense that people don't have, what would it be and why?
Sensors aren't perfect
Hold a thermometer still in a still room. Why might it read 20.1, 19.8, 20.3, 19.9?
Why it matters
Beginners trust every reading; engineers know better. Real sensors jitter, drift and occasionally glitch. Good intelligent systems are designed to cope: they average, double-check and leave safety margins. That habit separates machines that work in a demo from machines that work every day.
Goals
- Explain that every sensor reading includes some noise.
- Use averaging to get a steadier estimate.
- Work out how far a robot travels between sensor checks.
Predict
A distance sensor reads 31, 29, 30, 52, 30 cm while the robot stands still. What's the best guess for the real distance?
- 52 cm, the latest big change
- About 30 cm: 52 looks like a glitch
- Average all five: 34.4 cm
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Watch how individual noisy readings scatter around the true value. Compare trusting one reading with the lab's combined estimate. Which stays closer to the truth?
What the interactive shows, in words
The fusion lab can be replaced by this description: a robot's true position moves steadily along a line. Each sensor reading lands a little above or below the truth at random. A single reading can be quite far off; combining many readings, or two different sensors, gives an estimate that stays much closer to the true line.
Understand
Noise
Noise is the small, random wobble in every reading. It comes from electrical jitter, vibration, air currents and more. It can't be removed completely, only reduced.
Averaging calms noise
If the wobble is random, some readings are a bit high and some a bit low. Averaging several cancels much of it out. The cost: you have to wait for more readings, so the machine reacts a little more slowly.
Glitches and margins
Sometimes a reading is wildly wrong: a glitch. Throw out readings that disagree hugely with the rest. And never set a safety threshold right at the danger point: leave a margin for noise.
How often to look
A robot only knows about the world at the moments it checks. Between checks it is driving blind. Distance between checks = speed × time between checks. Faster robots need to check more often.
Explain it another way: intuitive
Guessing how many sweets are in a jar: one person's guess can be way off, but the average of the whole class's guesses is usually surprisingly close.
Explain it another way: technical
A reading = true value + noise. Averaging N readings with independent random noise reduces the typical error, though with diminishing returns. Outliers are removed first because one large error can drag the mean.
Explain it another way: mathematical
Readings 20.1, 19.8, 20.3, 19.9 have mean (20.1 + 19.8 + 20.3 + 19.9) ÷ 4 = 80.1 ÷ 4 ≈ 20.0 °C. Between checks: a robot at 40 cm/s checking 10 times a second travels 40 × 0.1 = 4 cm blind.
Explain it another way: applied
Planetary rovers count wheel turns to estimate distance, but wheels slip in sand, so the estimate drifts. They correct it now and then by photographing landmarks. Combining sensors like this is called sensor fusion.
Try these examples
Example 1
Readings: 48, 51, 50, 49, 12 cm. Estimate the distance.
The worked solution is in the online lesson.
Common mix-ups
A good sensor gives exactly the same reading every time.
✓ Every real sensor has some noise. Good ones just have less.Averaging always gives the right answer.
✓ A big glitch can drag the average. Remove readings that are wildly off first.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A thermometer reads 18, 19, 17 and 18 °C. What is the average, in °C?
Answer: °C
2. A robot drives at 10 cm/s and checks its distance sensor 10 times a second. How far does it travel between one check and the next, in cm?
Answer: cm
3. A robot must never get closer than 10 cm to a wall. Its sensor can be off by up to 2 cm. Which stop rule is safest?
- Stop IF distance < 10 cm
- Stop IF distance < 12 cm
- Stop IF distance < 8 cm
4. Averaging 20 readings instead of 2 makes the estimate steadier. What's the cost?
- None
- The robot reacts more slowly to real changes
- The sensor wears out
Apply it
A rover's distance sensor gives readings every 0.5 s and the rover drives at 10 cm/s. How far does it drive blind between readings? Suggest a stop rule with a margin that keeps it at least 20 cm from rocks.
Reflect
When would you rather react quickly to one reading, and when would you rather wait and average?
Actuators: how machines change the world
A robot hand must hold an egg and a steel bolt. Same motor, same fingers. How can it crush one and drop the other?
Why it matters
Sensing and thinking are useless unless the machine can do something. Actuators are the muscles of a machine: they spin wheels, bend joints, open valves and squeeze grippers. Choosing and controlling them well is what makes a design actually work.
Goals
- Describe what an actuator does and name common ones.
- Match an actuator to a task.
- Explain why an actuator often needs a sensor to do its job well.
Predict
A gripper squeezes everything with the same force. It holds a bolt perfectly. What happens with a raw egg?
- It holds it perfectly too
- It might crush it
- It can't pick up anything round
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Label the six parts of the two-finger gripper, then predict whether each grasp holds, slips or crushes. Notice which part senses and which parts act.
What the interactive shows, in words
The gripper activity can be replaced by this description: a two-finger gripper has a knuckle joint, a first link, a middle joint, a second link, a touch-sensing pad and a joint motor. Too little squeeze lets heavy or slippery objects slip; too much crushes fragile ones like an egg or a paper cup; the pad's grip and the object's weight decide which.
Understand
Actuators make things happen
An actuator is a part that the controller switches or drives to change the world. Common ones:
- DC motor: spins continuously (wheels, fans).
- Servo: turns to a chosen angle (joints, steering).
- Solenoid: pushes or pulls a short distance (locks, valves).
- Heaters, lights, buzzers.
Joints are degrees of freedom
Each motor-driven joint gives a robot one way to move, called a degree of freedom. A gripper finger with a knuckle and a middle joint has two. More joints mean more possible poses, and more motors to control.
Actuators need feedback
A motor alone doesn't know how far it turned or how hard it's pushing. Pair it with a sensor (an encoder for angle, a pad for touch) and the controller can stop at the right place or the right squeeze.
Explain it another way: intuitive
Your muscles are your actuators. But you can carry an egg without crushing it because your fingertips (sensors) tell your brain how hard you're squeezing.
Explain it another way: technical
Electric actuators turn electrical energy into motion. A DC motor's speed rises with voltage; its turning force (torque) rises with current. A servo contains a motor, gears, an angle sensor and a tiny controller in one box.
Explain it another way: applied
Car wipers use a DC motor; electric car windows use a motor that stops when it senses something trapped; a 3D printer uses stepper motors that move in exact small steps. Each choice fits its job.
Try these examples
Example 1
Choose an actuator for: (a) the wheels of a robot car, (b) a robot's elbow joint, (c) an automatic door lock.
The worked solution is in the online lesson.
Common mix-ups
Only motors are actuators.
✓ Heaters, lights, valves, locks and speakers are actuators too: anything the controller uses to change the world.A stronger actuator is always better.
✓ Too much force or speed can damage things. The right actuator, well controlled, beats the biggest.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which actuator is best for pointing a camera at a chosen angle and holding it there?
- DC motor
- Servo
- Buzzer
2. Which addition best helps a gripper hold both an egg and a bolt?
- A bigger motor
- A touch sensor in the finger pad
- Longer fingers
3. A robot arm has a shoulder, an elbow and a wrist, each turned by its own motor. How many degrees of freedom does it have?
Answer:
4. In a greenhouse, which of these is an actuator?
- Thermometer
- Heater
- Setpoint of 18 °C
Apply it
Design a robot that waters a plant. List each actuator you need and what it does, and pair each one with a sensor that tells the controller when to stop.
Reflect
Pick one thing you did today with your hands. Which of your 'sensors' helped your 'actuators' do it well?
Week 25: Feedback intuition
This week you will
- Compare open-loop and closed-loop control.
- Describe how an on/off thermostat behaves and why it wobbles.
- Use proportional correction steps and spot when they overshoot.
Open loop or closed loop?
A robot was told to roll exactly 40 wheel-turns to a door. On a polished floor it stopped a hand's width short. What was it missing?
Why it matters
Feedback is the idea that makes machines dependable in a messy world. Your fridge, a car's cruise control, a drone hovering in the wind: all of them measure the result of what they did and adjust. It's the most important idea in this term.
Goals
- Explain the difference between open-loop and closed-loop control.
- Identify the measured result that is fed back in a closed loop.
- Calculate the gap between where a system is and where it should be.
Predict
Two kettles heat water. Kettle A heats for exactly 3 minutes. Kettle B heats until its sensor reads 100 °C. Someone fills both with very cold water. Which one boils?
- Both
- Only A
- Only B
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Use only the proportional setting (leave any others at zero). Set a target and watch the measured output chase it. Change the plant or add a disturbance if the lab offers one, and watch the loop correct for it.
What the interactive shows, in words
The feedback lab can be replaced by this description: a target value is set, and the system's measured output starts below it. Each moment, the controller pushes in proportion to the gap between target and output, so the output rises quickly at first and then more slowly as the gap shrinks. If something knocks the output down, the gap grows and the controller pushes harder until it recovers.
Understand
Open loop: act from a plan
Open-loop control decides what to do in advance and never checks the result. A toaster on a timer, a robot told 'drive 40 wheel turns'. Simple and cheap, but if the world isn't exactly as expected, the result is wrong and nobody notices.
Closed loop: measure and correct
Closed-loop control measures the result and uses it to decide what to do next. The measurement is fed back, which is why it's called feedback. It's a sense–think–act loop aimed at a target.
The gap drives everything
The thinking step usually starts with one subtraction:
gap = target − measured value
Big gap: push hard. Zero gap: you've arrived. Negative gap: you've gone too far, so push back. The controller doesn't need to know why it's off, just how far.
Explain it another way: intuitive
Walk to a door with your eyes shut, counting steps: open loop. Walk with your eyes open, adjusting as you go: closed loop. Eyes open wins every time someone moves the door.
Explain it another way: technical
In a closed loop the error e = r − y (reference minus measured output) is computed every cycle, and the controller chooses an action from e. Disturbances that change y are automatically corrected because they change e.
Explain it another way: applied
Cruise control measures the car's speed, compares it with the set speed, and opens or closes the throttle. Going uphill slows the car, the gap grows, and the engine automatically works harder, with no hill detector needed.
Try these examples
Example 1
A robot wants to be 200 cm along a corridor. Its encoder says it's at 165 cm. What's the gap, and what should it do?
The worked solution is in the online lesson.
Common mix-ups
Closed loop means the machine is switched off.
✓ It means information goes round in a circle: act, measure, feed back, act again.Feedback needs to know what caused the error.
✓ It only needs the gap. Slip, slope or a push all show up the same way.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which of these is closed-loop?
- A washing machine that always fills for 90 seconds
- A washing machine that fills until a level sensor says full
- A fan that runs for 10 minutes
2. A heater wants the room at 21 °C. The thermometer reads 17.5 °C. What is the gap (target − measured), in °C?
Answer: °C
3. A robot's target is 80 cm. It measures 86 cm. What is the gap, in cm? (It can be negative.)
Answer: cm
4. A closed-loop robot is pushed back 10 cm by a friend. What happens?
- It doesn't notice
- The gap grows, so it drives forward again
- It stops working
Apply it
Find two machines at home: one open-loop and one closed-loop. For the closed-loop one, name what it measures, what its target is, and what it changes to close the gap.
Reflect
When do you use open-loop control in your own life, and when do you rely on feedback?
On/off control: the bang-bang thermostat
Your heating clicks on, then off, then on again all evening. Is it broken, or is that the plan?
Why it matters
The simplest feedback controller is a switch: full on or full off. Thermostats, fridges and ovens have used it for a century because it's cheap and robust. Understanding its wobble is the first step to designing something smoother.
Goals
- Describe how an on/off (bang-bang) controller works.
- Explain why its temperature wobbles around the target.
- Describe the trade-off set by the gap between switch-on and switch-off.
Predict
A heater switches ON when the room is below 17.9 °C and OFF above 18.1 °C. Compared with switching at 17.5 and 18.5 °C, what happens?
- The temperature is steadier but the heater clicks much more often
- The temperature is steadier and the heater clicks less
- No difference
Write down your guess and your reason. The reveal is in the online lesson.
Discover
With 'On/off', try a gap of 0.2 °C, then 1 °C, then 4 °C. For each, note how much the temperature swings and how many times the heater switched.
What the interactive shows, in words
The thermostat plot can be replaced by these results from the same simulated room, target 18 °C. On/off with a 0.2 °C gap: swings about 0.5 °C, about 37 switches in 2 hours. 1 °C gap: swings about 1.2 °C, about 13 switches. 2 °C gap: swings about 2.4 °C, about 7 switches. In every case it takes about 34 minutes to warm up from 10 °C.
Understand
Full on or full off
A bang-bang controller has only two actions. Below the target: heater fully on. Above it: heater fully off. It's a single IF–THEN–ELSE rule inside a forever loop.
Why it wobbles
The heater can't be 'a bit on', so the temperature overshoots while it's on and drops while it's off. It never settles exactly on the target; it oscillates in a band around it.
The gap (hysteresis)
Switching at exactly one temperature makes the heater chatter on and off. So thermostats use two thresholds, a switch-on and a higher switch-off. The space between is called hysteresis. A small gap gives steadier temperature but more switching; a big gap gives fewer switches but bigger swings.
Explain it another way: intuitive
Steering a bike by only ever turning the handlebars fully left or fully right. You'd still go roughly straight, but you'd zig-zag the whole way.
Explain it another way: technical
Bang-bang control with hysteresis: u = 1 if y < r − h/2, u = 0 if y > r + h/2, otherwise keep the previous u. The output oscillates; the band width and switching rate depend on h and how fast the system heats and cools.
Explain it another way: applied
Fridges switch their compressor on and off with a few degrees of hysteresis. A fridge that switched every few seconds would wear out its compressor in months.
Try these examples
Example 1
A thermostat is set to 20 °C with a 2 °C gap. When does the heater switch on, and when off?
The worked solution is in the online lesson.
Common mix-ups
A thermostat that clicks on and off a lot is broken.
✓ Switching on and off is how bang-bang control works. Only very rapid switching suggests the gap is too small.On/off control is too crude to be useful.
✓ It's cheap, robust and good enough for fridges, ovens and heating everywhere.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Why does a bang-bang thermostat never hold the temperature exactly on target?
- The thermometer is broken
- The heater can only be fully on or fully off, so it overshoots and undershoots
- The target is set wrong
2. A thermostat targets 22 °C with a 3 °C gap split evenly. Below what temperature does the heater switch on, in °C?
Answer: °C
3. An engineer shrinks the gap from 2 °C to 0.2 °C. What happens?
- Smaller swings, more switching
- Bigger swings, less switching
- Smaller swings, less switching
4. Gap set: on below 17 °C, off above 19 °C. The heater is ON and the room reaches 18 °C. What does it do?
- Switches off
- Stays on
- Switches on
Apply it
Design an on/off controller for a fish tank heater that keeps the water between 24 and 26 °C. Write the two thresholds and the rule. What would happen if a fish tank heater switched too often?
Reflect
Where else do you see a system that zig-zags around what it wants instead of holding steady?
Correct in proportion
When you park a bike next to a friend, you slow down as you get close. What rule is your brain using?
Why it matters
Instead of 'full on or off', a proportional controller pushes harder when it's far away and gently when it's close. It's smoother and faster than bang-bang, and it's the first part of the PID controllers inside drones, robot arms and lifts.
Goals
- Use proportional correction steps: move a fraction of the gap each time.
- Predict when correction steps glide in, overshoot or go unstable.
- Explain why a proportional heater settles a little short of its target.
Predict
A robot at 0 cm wants to reach 60 cm. Each step it moves half the remaining gap. Where is it after 2 steps?
- 60 cm
- 45 cm
- 30 cm
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Step through with k = 0.5. Then try k = 1, k = 1.5, k = 2 and k = 2.2. Describe what each one does in a few words.
What the interactive shows, in words
The gap-closer can be replaced by this table, starting at 0 cm with target 60 cm. k = 0.5: 30, 45, 52.5, 56.3 cm (glides in). k = 1: 60 (straight there). k = 1.5: 90, 45, 67.5, 56.3 (overshoots, settles). k = 2: 120, 0, 120, 0 (bounces for ever). k = 2.2: 132, −26.4, 163.7 (grows: unstable).
Understand
Push in proportion to the gap
A proportional controller makes its correction a fixed fraction of the gap:
correction = k × gap
Far away, big gap, big push. Close by, small gap, gentle push. The number k is called the gain.
Too little, just right, too much
With k below 1, each step closes part of the gap: a smooth glide in. k = 1 jumps straight there (in a perfect world). k between 1 and 2 overshoots and wobbles, then settles. k = 2 bounces for ever. k above 2 wobbles bigger and bigger: unstable.
Settling a little short
A proportional heater only heats when the room is too cold. Near the target the gap is small, so the heat is small, and it can only balance the heat leaking out if the room stays a little below target. Higher gain shrinks this offset; later levels add a trick (integral action) to remove it.
Explain it another way: intuitive
Pouring a drink: you pour fast when the glass is empty and slow right down near the top. That's proportional control.
Explain it another way: technical
u = Kp · e. In the simple step model, the new gap is (1 − k) × the old gap. If |1 − k| < 1 (0 < k < 2) the gap shrinks to zero; otherwise it doesn't. Real systems add delay and inertia, which make overshoot appear at much lower gains.
Explain it another way: mathematical
Gap after n steps = (1 − k)ⁿ × starting gap. With a 60 cm gap and k = 0.5: 30, 15, 7.5 cm. With k = 1.5: −30, +15, −7.5 (overshoot, flipping sides). With k = 2.2: −72, +86.4 (growing).
Explain it another way: applied
A lift slows smoothly as it approaches a floor because its controller pushes in proportion to the distance left. Engineers tune the gain so passengers don't feel a jolt or bounce at the end.
Try these examples
Example 1
A robot is at 20 cm, target 100 cm, k = 0.25. Where is it after one step? After two?
The worked solution is in the online lesson.
Common mix-ups
A bigger gain is always better: it gets there faster.
✓ Too much gain overshoots, wobbles or goes unstable.Proportional control always reaches the exact target.
✓ When something keeps pulling it away (like heat leaking out), it settles a little short.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot is at 0 cm and wants to stop at 80 cm. Each step it moves 0.5 of the remaining gap. Where is it after one step, in cm?
Answer: cm
2. A robot is at 20 cm and wants to stop at 40 cm. Each step it moves 0.25 of the remaining gap. Where is it after one step, in cm?
Answer: cm
3. Which value of k makes the robot overshoot the target and then settle?
- 0.3
- 1.5
- 2.5
4. A proportional heater targets 18 °C but the room settles at 16.6 °C. Why?
- The heater is broken
- Near the target the gap is small, so the heat is small: it only balances the losses below target
- The thermometer reads 1.4 °C too low
5. A robot at 0 cm targets 80 cm with k = 0.5. Where is it after three steps, in cm?
Answer: cm
Apply it
Open the thermostat diagram, switch to Proportional and try Kp from 10% to 300% per °C. Record where the room settles for three values. Then explain in two sentences why it never quite reaches 18 °C, and what happens to the offset as Kp rises.
Reflect
In which everyday task do you correct a lot when you're far off and a little when you're close?
Week 26: Introduction to robotic movement
This week you will
- Explain how a two-wheeled robot drives straight, curves and spins.
- Describe how two joints place a robot hand.
- Plan a safe route when you cannot steer in real time.
Steering without a steering wheel
Robot vacuums, rovers and wheelchairs often have no steering wheel at all. So how do they turn?
Why it matters
Two motors, two wheels and a caster are the most common robot body in the world: cheap, simple and able to spin on the spot. Knowing how wheel speeds turn into motion lets you predict, plan and program a robot's path.
Goals
- Explain how two independently driven wheels make a robot go straight, curve or spin.
- Calculate a two-wheeled robot's forward speed from its wheel speeds.
- Choose wheel speeds for a given manoeuvre.
Predict
A robot's left wheel turns forwards at 5 cm/s and its right wheel backwards at 5 cm/s. What does the robot do?
- Drives forwards slowly
- Spins on the spot
- Stays completely still
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Make the robot go straight, then curve left, then curve right, then spin on the spot. Write down the wheel speeds for each.
What the interactive shows, in words
The wheel-drive diagram can be replaced by this description, with wheels 10 cm apart, over 4 seconds. Both 6 cm/s: straight, 24 cm forwards. Left 2, right 6: forward speed 4 cm/s, curves left about 92°. Left 6, right 2: curves right about 92°. Left −5, right 5: forward speed 0, spins left on the spot about 229°.
Understand
Same speeds: straight
If both wheels turn forwards at the same speed, the robot drives straight. Its forward speed is the average of the two wheels: (left + right) ÷ 2.
Different speeds: curve
If one wheel is faster, the robot curves away from it, towards the slower wheel. Right wheel faster: it curves left. The bigger the difference, the tighter the turn. This is called differential drive.
Opposite speeds: spin
Equal and opposite speeds make the average zero, so the robot doesn't go anywhere. It just rotates on the spot. Being able to turn without moving is very handy in tight spaces.
Explain it another way: intuitive
Rowing a boat: pull both oars equally and you go straight. Pull only the right oar and you swing left. Pull one forwards and one backwards and you spin.
Explain it another way: technical
For wheels a distance W apart, forward speed v = (vL + vR) / 2 and turning rate ω = (vR − vL) / W (radians per second, positive = turning left). The robot has two driven wheels, giving two independent controls.
Explain it another way: mathematical
With W = 10 cm, vL = 2 cm/s and vR = 6 cm/s: v = (2 + 6) ÷ 2 = 4 cm/s and ω = (6 − 2) ÷ 10 = 0.4 rad/s. In 4 s it turns 1.6 rad, about 92°: roughly a quarter turn to the left.
Explain it another way: applied
Tanks and diggers use the same idea with tracks: speed up one track and slow the other to turn. That's why they're called skid-steer vehicles.
Try these examples
Example 1
A robot's wheels go 8 cm/s (left) and 4 cm/s (right). What's its forward speed, and which way does it curve?
The worked solution is in the online lesson.
Common mix-ups
A robot turns towards its faster wheel.
✓ It turns away from the faster wheel, towards the slower one.Robots need a steering wheel or steerable wheels to turn.
✓ Driving two fixed wheels at different speeds is enough.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Left wheel 10 cm/s, right wheel 6 cm/s. What is the robot's forward speed, in cm/s?
Answer: cm/s
2. Left wheel 3 cm/s, right wheel 7 cm/s. Which way does the robot curve?
- Left
- Right
- Straight
3. Which wheel speeds make the robot spin on the spot to the left?
- Left +5, right +5
- Left −5, right +5
- Left +5, right −5
4. A robot faces north (0°). Compass angles go clockwise: east 90°, south 180°, west 270°. It makes these 90° turns: right, right, right, left, right. Which compass angle does it face at the end (0 to 270)?
Answer:
Apply it
Using the wheel-drive diagram, find wheel speeds that make the robot turn about a quarter turn (90°) left in 4 seconds while still moving forwards. Then write a short program for a robot to drive a square using only 'set left speed', 'set right speed' and 'wait'.
Reflect
What would go wrong if one of a robot's wheels slipped on a wet floor?
Joints and arms: placing a robot hand
A robot arm with two joints can touch a point 6 units away in two completely different ways. How?
Why it matters
Robot arms build cars, sort parcels and perform surgery. Each one has to answer the same question thousands of times a day: what angles put the hand exactly here? Starting with two joints shows you the whole idea.
Goals
- Describe how two joint angles set where a two-link arm's hand ends up.
- Find the furthest and closest an arm can reach.
- Explain why some points can be reached with more than one pose.
Predict
An arm has an upper arm 5 units long and a forearm 3 units long. What's the furthest the hand can be from the shoulder?
- 5 units
- 8 units
- 15 units
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Use the shoulder and elbow sliders to touch the star. Then press New target and try again. For one target, find a second, different pair of angles that also reaches it, if you can.
What the interactive shows, in words
The arm diagram can be replaced by this description: an upper arm of 5 units and a forearm of 3 units, with the shoulder on a table. Shoulder 0°, elbow 0°: hand at (8, 0). Shoulder 90°, elbow −90°: hand at (3, 5). Shoulder 30°, elbow 60°: hand at about (4.3, 5.5). The hand can reach anywhere between 2 and 8 units from the shoulder.
Understand
Two joints, two numbers
The shoulder angle points the upper arm; the elbow angle bends the forearm relative to it. Give both numbers and the hand's position is fixed exactly. Each joint is one degree of freedom.
The reach ring
Straight arm: furthest reach, upper + forearm. Folded arm: closest reach, upper − forearm. Any point between these distances (and above the table, for our arm) can be reached; anything outside can't, no matter what the controller tries.
Elbow up or elbow down
Many points can be reached two ways: elbow bent one way or the other, like reaching a cup with your elbow up or tucked down. Robots must choose, often the pose that avoids hitting things or needs the least movement.
Explain it another way: intuitive
Touch your nose, then a table, keeping your wrist stiff. Your shoulder and elbow do all the work, and you can usually reach the same spot with your elbow higher or lower.
Explain it another way: technical
Forward kinematics: given the joint angles, find the hand position. For our arm, x = 5·cos θ1 + 3·cos(θ1 + θ2) and y = 5·sin θ1 + 3·sin(θ1 + θ2). Finding angles from a target (the reverse) is called inverse kinematics.
Explain it another way: mathematical
With the shoulder at 90° (straight up) and the elbow at −90° (bent right): the elbow is at (0, 5), and the forearm points along +x, so the hand is at (3, 5). Straight out sideways (0°, 0°): hand at (5 + 3, 0) = (8, 0).
Explain it another way: applied
Factory arms have six joints, enough to put the hand anywhere nearby at any angle. Their controllers solve these equations hundreds of times a second as the arm moves.
Try these examples
Example 1
Our arm (5 and 3 units) has the shoulder at 0° and the elbow at 90°. Where is the hand?
The worked solution is in the online lesson.
Common mix-ups
A longer arm can reach everywhere closer too.
✓ There's also a closest reach (upper − forearm). Points too near the shoulder can be unreachable.Each target has exactly one set of joint angles.
✓ Often there are two (elbow up and elbow down), and sometimes none.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot arm has an upper arm 9 cm long and a forearm 2 cm long. What is the closest distance from the shoulder that the hand can reach, in cm?
Answer: cm
2. Our arm has links of 5 and 3 units. Which point can its hand NOT reach?
- A point 4 units from the shoulder
- A point 7 units from the shoulder
- A point 9 units from the shoulder
3. A robot arm has a waist that rotates, a shoulder, an elbow and a wrist that bends, each with its own motor. How many degrees of freedom is that?
Answer:
4. Why can a two-joint arm often reach the same point in two ways?
- Because it has a spare motor
- The elbow can bend either way (elbow up or elbow down)
- It can't: there's only ever one way
Apply it
Design a two-joint arm to move books from a desk to a shelf 60 cm away and 40 cm higher. Choose the two link lengths so the shelf is in reach and the desk right next to the robot is too. Explain your choice using the reach ring.
Reflect
How many degrees of freedom do you think your own arm and hand have? Which joints are they?
Planning a route before you move
Rover drivers on Earth plan a whole day of driving in one go, then hit send. How do they make sure it doesn't end in a crater?
Why it matters
Planning is how intelligent machines look ahead. Delivery robots, warehouse vehicles and rovers all plan routes before moving, then use sensors to check the plan is still working. It's sequences, decisions and feedback all working together.
Goals
- Plan a complete route on a grid that avoids obstacles.
- Compare routes by length and safety.
- Explain why a planned route still needs sensors and checks along the way.
Predict
You plan a 10-step route for a rover and send it. Halfway along, a wheel slips and the rover is one square off. What happens if it just keeps following the plan?
- It reaches the goal anyway
- It ends one square off, or hits something
- It notices and re-plans
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Plan the entire route to the flag before you press anything, writing it on paper. Then enter it and press Run all. Did it work first time? Find the shortest safe route you can.
What the interactive shows, in words
The grid robot can be replaced by squared paper: draw a 6-by-6 grid with walls at (1, 1), (2, 1), (3, 1), (3, 3) and (2, 4), start at (0, 0) facing north and the flag at (4, 4). The shortest safe route goes up 2, east 4, up 2: Forward, Forward, Turn right, Forward ×4, Turn left, Forward, Forward.
Understand
A plan is a sequence
A route plan is a list of moves from start to goal that avoids every obstacle on the map. Writing it is like writing an algorithm, except the 'bugs' are walls and craters.
Comparing routes
Several routes may work. Engineers compare them: shorter (fewer moves, less energy), safer (further from hazards), or easier to check (passing landmarks the robot can see). The shortest route isn't always the best.
Plans need checkpoints
Real wheels slip and maps are imperfect, so a plan alone is open-loop. Robots add checkpoints: stop, measure where you really are, correct, continue. Planning ahead plus checking along the way combines the best of both.
Explain it another way: intuitive
Planning a walk to a friend's house: you choose the route at home, but you still look at street signs as you go, in case you took a wrong turn.
Explain it another way: technical
Path planning searches a map for a sequence of moves from start to goal. On a grid, the shortest path length (in moves, ignoring turns) is at least the number of rows plus columns between start and goal; walls can make it longer.
Explain it another way: mathematical
From (0, 0) to (4, 4) on an open grid you need at least 4 moves east and 4 moves north: 8 Forward moves, plus the turns to change direction. Walls can force detours that add moves.
Explain it another way: applied
Mars rover drivers plan each day's route on 3D maps from the rover's photos, then the rover drives itself, checking for hazards and stopping if something doesn't match. On Earth, warehouse robots replan in a fraction of a second when someone steps into an aisle.
Try these examples
Example 1
On the grid robot, compare route A (up 2, east 4, up 2) with route B (east 1 first). Which is valid?
The worked solution is in the online lesson.
Common mix-ups
A good plan doesn't need sensors.
✓ Plans are open-loop. Sensors and checkpoints catch slips and surprises.The shortest route is always best.
✓ Safety, energy and how easy it is to check position matter too.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A robot starts at (0, 0) facing north on an open grid (east is +x, north is +y). It runs: forward 1, forward 1, turn right, turn right, forward 1, turn left, turn left. What is its final x (east–west) coordinate? Use a negative number for west.
Answer:
2. On an open grid with no walls, what's the fewest Forward moves to get from (0, 0) to (3, 5)?
Answer:
3. Why do rovers stop at checkpoints along a planned route?
- To rest their motors
- To measure where they really are and correct any drift
- Because the plan says so for no reason
4. Route A is 10 moves and passes right beside a crater. Route B is 12 moves and stays well clear. Which would a careful engineer pick?
- A, it's shorter
- B, it's safer
- Neither
Apply it
Draw a 6×6 map of your classroom or bedroom with furniture as walls. Plan a robot route from the door to a chosen spot, then choose two checkpoints where it should confirm its position. Explain why you picked them.
Reflect
Do you plan your route before you move, or work it out as you go? When is each better?
Week 27: Intelligent system design challenge
This week you will
- Turn an everyday problem into clear requirements.
- Design the sensing, rules and loop for a small intelligent system.
- Test the design with edge cases and improve it.
Design challenge 1: define the problem
Engineers say a problem well defined is half solved. What makes a problem 'well defined'?
Why it matters
This week you design your own intelligent system. The most common reason real projects fail isn't bad code or weak motors: it's solving the wrong problem, or not knowing when you've solved it. Clear requirements prevent both.
Goals
- Write a clear problem statement for an intelligent system.
- Turn wishes into specific, testable requirements.
- Identify constraints and one trade-off in a design.
Predict
Which requirement could you actually test?
- The plant waterer should be smart
- The plant waterer must water when the soil moisture reads below 30%, and never more than twice a day
- The plant waterer should keep plants happy
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Weight the criteria differently (say, cost very important, then performance very important) and watch which design comes out top. Notice there's rarely one design that's best at everything.
What the interactive shows, in words
The trade-off lab can be replaced by this description: six possible designs are scored on cost, mass and performance. When cost matters most, a cheap, modest design wins; when performance matters most, an expensive, heavier design wins. No design is best at everything, so the weights you choose decide the winner.
Understand
Problem statement
Start with one or two sentences: who has the problem, what goes wrong now, and what a good solution would do. 'Plants on our classroom windowsill dry out over weekends. We need a system that waters them only when they need it.'
Testable requirements
Turn wishes into requirements you can check:
- What it must do, with numbers (water when moisture < 30%).
- What it must never do (never water more than twice a day).
- Anything about speed, size or power.
If you can't imagine a test for it, rewrite it.
Constraints and trade-offs
Constraints are limits you can't break: budget, size, a battery that must last a week. Within them you'll face trade-offs: a more sensitive sensor costs more; checking more often uses more battery. Write down the trade-off you choose and why.
Explain it another way: intuitive
Asking a friend to 'get some food' could mean anything. Asking for 'two apples and a loaf of bread, under £3' means you'll know exactly whether they got it right.
Explain it another way: technical
Requirements should be specific, measurable and verifiable. A design is evaluated against them; trade-off tools weight competing criteria (cost, mass, performance) to compare options.
Explain it another way: applied
Before a Mars rover is built, engineers write thousands of requirements: how far it must drive, how cold it must survive, how much it may weigh. Every test the rover goes through checks one of them.
Try these examples
Example 1
Rewrite as testable requirements: 'The night light should come on when it's dark and not waste energy.'
The worked solution is in the online lesson.
Common mix-ups
Requirements are just a wish list.
✓ Good requirements are specific and testable, so you know when you've succeeded.The best design wins on every criterion.
✓ Usually designs trade one criterion against another. You choose the balance and explain why.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Which requirement is testable?
- The robot should be fast
- The robot must reach the door in under 30 seconds
- The robot should feel friendly
2. Why include something the system must NEVER do?
- It makes the list longer
- Safety and sense: it rules out dangerous or silly behaviour
- Engineers like negative sentences
3. Checking a sensor 100 times a second instead of once a second makes a robot react faster. What's the likely trade-off?
- None
- It uses more battery and computing power
- It makes the sensor less accurate
Apply it
Start your term project: choose an everyday problem, write a two-sentence problem statement, and list at least three testable requirements, including one 'must never'. Name one constraint and one trade-off you expect.
Reflect
Which of your requirements was hardest to make testable? How did you fix it?
Design challenge 2: design the brain
A sorting machine's whole brain fits on one small table. How can eight rows of yes and no sort thousands of parts?
Why it matters
Now you put the whole term together: sensors to measure, rules and loops to decide, actuators to act, and feedback to correct. Designing the brain on paper first, before any building or coding, is exactly what professional engineers do.
Goals
- Design the sense–think–act structure of an intelligent system.
- Write its rules using IF–THEN–ELSE, AND/OR and a loop.
- Cover every possible combination of sensor readings.
Predict
A sorter has three yes/no sensors: red?, large?, metal?. How many different combinations of readings are possible?
- 3
- 6
- 8
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Turn the client's four-line brief into an 8-row rule table, choosing a bin for every combination of red, large and metal. Then watch the slow belt run your table.
What the interactive shows, in words
The sorting-machine level can be replaced by this rule table for red (R), large (L) and metal (M): any row with M = yes goes to Metal; M = no and L = yes goes to Reject; M = no, L = no and R = yes goes to Red plastic; M = no, L = no and R = no goes to Mixed plastic. That covers all 8 combinations.
Understand
Start with the loop
Sketch the structure first:
forever: read every sensor → apply the rules → drive the actuators
Name each sensor and actuator. If the system aims at a target (a temperature, a position), mark where the gap is measured and fed back.
Cover every case
List every combination of sensor readings. Two yes/no sensors give 4 rows, three give 8. A rule table with an action for each row guarantees there's no situation your system hasn't thought about.
Priority rules
Some rules must win over others. Any metal part goes to Metal, whatever its colour or size. Put safety and top-priority rules first, so they're checked before anything else. 'IF metal THEN Metal ELSE IF large THEN Reject ELSE …' makes the order clear.
Explain it another way: intuitive
A rule table is like a choose-your-own-adventure book where every page has a next step. No reader ever gets stuck on a page with nothing to do.
Explain it another way: technical
With n binary inputs there are 2ⁿ input combinations. A complete decision table maps each to an output. Nested IF–ELSE IF chains express priority: earlier conditions take precedence.
Explain it another way: applied
The client's sorting brief becomes four rules: metal first, then large, then red, then everything else. That one ordering fills all 8 rows of the table with no gaps and no contradictions.
Try these examples
Example 1
Brief: metal parts → Metal bin. Large non-metal → Reject. Small red plastic → Red. Everything else → Mixed. Write it as a priority chain.
The worked solution is in the online lesson.
Common mix-ups
You only need rules for the situations you expect.
✓ List every combination; the unexpected ones are where machines go wrong.Rule order doesn't matter.
✓ In an IF–ELSE IF chain, the first true rule wins. Put the most important rules first.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. A smart greenhouse has four yes/no sensors (too hot?, too cold?, soil dry?, daytime?). How many rows does its complete rule table need?
Answer:
2. Using the chain IF metal THEN Metal ELSE IF large THEN Reject ELSE IF red THEN Red ELSE Mixed, where does a small, red, metal part go?
- Red
- Metal
- Reject
3. A rule table for two sensors has only three rows filled in. What's the risk?
- None
- In the missing situation, the machine has no instruction
- It will run faster
4. In your design, where do the sensor readings and rules go?
- Before the forever loop
- Inside the forever loop
- After the forever loop
Apply it
For your term project, draw the sense–think–act diagram and write the rules as an IF–ELSE IF chain inside a forever loop. If you have yes/no sensors, fill in the complete rule table. Mark the one rule that must always win.
Reflect
Which part of your design's brain was hardest to decide, and why?
Design challenge 3: test it and make it better
Your design works on your first try. Is it finished?
Why it matters
Engineers test because confidence without evidence is just hope. A good test plan finds problems on paper or in simulation, where they're cheap, rather than in a real classroom, greenhouse or Mars crater, where they're not. Then the design cycle goes round again.
Goals
- Write test cases with expected results, including edge cases.
- Run tests and record pass or fail honestly.
- Make one evidence-based improvement and re-test.
Predict
Your rule is 'IF distance < 20 cm THEN stop'. You test it at 50 cm and 5 cm and both pass. Which extra test is most likely to find a problem?
- 40 cm
- Exactly 20 cm
- 60 cm
Write down your guess and your reason. The reveal is in the online lesson.
Discover
Set up the rule for your own design (or the stop rule). Look at the test-case table: 5, 19, 20, 21, 60 and 100 cm. Does every row do what you'd want? If not, change the rule and check again.
What the interactive shows, in words
The rule tester can be replaced by this test table for IF distance < 20 cm THEN stop ELSE drive: 5 cm → stop (pass); 19 cm → stop (pass); 20 cm → drive (a designer who wanted the robot to stop at 20 cm would record this as a fail and change < to ≤); 21 cm → drive; 60 cm → drive; 100 cm → drive.
Understand
Test cases
A test case is an input plus the result you expect, written down before you run it. Then you run it and record the actual result. Pass if they match, fail if they don't. Writing the expectation first stops you fooling yourself.
Pick tests that bite
Cover normal cases, edge cases (exactly on a threshold, zero, the maximum) and odd cases (a glitchy reading, two sensors at once). A test that can't fail teaches you nothing.
Improve, then re-test
When a test fails, find out why, change one thing, and run all the tests again. Then record what changed and what the evidence showed. That loop of design, test, improve is the design cycle, and it's how every real product gets good.
Explain it another way: intuitive
Before a bridge opens, engineers drive heavy lorries over it. They don't test with a bicycle: they test with something that might actually break it.
Explain it another way: technical
Boundary-value testing checks inputs at, just below and just above every threshold, because off-by-one mistakes (using < instead of ≤) cluster there. Regression testing re-runs all earlier tests after every change.
Explain it another way: applied
Car makers test emergency braking with dummies stepping out at exactly the worst moment, in rain, at night. Each failed test leads to a change, then the whole test suite runs again.
Try these examples
Example 1
Write four test cases for a fan rule 'IF temperature > 26 °C THEN fan on ELSE fan off'.
The worked solution is in the online lesson.
Common mix-ups
If it works once, it's finished.
✓ One success proves very little. Test the edges and the odd cases too.A failed test means the design is bad.
✓ A failed test is useful evidence. Finding it now is much cheaper than finding it later.
Practice questions
Questions only. Check your answers in the Lite lesson; they are graded on our server and nothing is saved.
1. Rule: IF temperature > 40 °C THEN switch the fan on. The sensor reads 41 °C, 55 °C, 40 °C, 33 °C, 43 °C, 47 °C. For how many of these readings does the THEN branch run?
Answer:
2. Why write the expected result before running a test?
- It saves paper
- So you can't convince yourself afterwards that whatever happened was right
- Because tests run faster
3. You change your rule from < to ≤ to fix one failed test. What should you do next?
- Run only the test that failed
- Run all the tests again
- Nothing
4. Good practice tests each threshold at just below, exactly on, and just above it. A design has 3 thresholds. How many boundary tests is that?
Answer:
Apply it
Finish your term project: write at least five test cases (including one exactly on a threshold), run them by hand or in a Tactiverge simulator, and record expected vs actual. Make one improvement, re-run every test, and write two sentences on what changed and what the evidence showed.
Reflect
What did testing teach you about your design that you didn't know when you designed it?