Challenge 1
Make a walk you can hear. Take a burst of steps, then a pause, and repeat. A friend with their eyes shut should be able to tell you two things. How many bursts were there? How many steps were in each one?
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 1
Level 2 · Lesson 1 · EV3-L02-0160 minutes · Ages 8+ · Model: Spider
The Spider: eight legs and one Large Motor. The legs take turns, just like a real spider’s legs.
A spider does not walk at a steady speed. It runs a few quick steps. Then it stops dead and waits. Then it runs again. That stop and start is what makes it look like a spider. It matters more than the eight legs.
That is a pattern made of patterns. A few steps make a dash. A few dashes make a trip. To write that, you put one loop inside another.
Jumping spiders are the ones that look back at you. They are small. You can find them in lots of places, all over Southeast Asia. They move in short bursts. A quick run, then they keep very still, then another run.

A spider always keeps some legs on the ground. The other legs swing forward. So it never falls over, even when it stands still. With eight legs, there are always three or more down to hold it up, like a stool. Your model does the same. It has one motor, some rods that link the legs, and legs that take turns.
The stopping matters too. A jumping spider cannot see well while it moves. So it stops to look. It is not being shy. It cannot walk and see at the same time, so it takes turns: walk, then look.
Think of a spider that walked at one speed all the time. It would be easy to spot and easy to follow. It would never get a clear look at anything. The stop and start helps it hide, and it helps it see.
When a robot stops, it has not gone wrong. Often the stop is the whole point.
There is no new block today. There is a new shape. One repeat block sits inside another repeat block.
repeat (4)
repeat (3)
[A v] run for (360) [degrees v] at (40) % speed :: motors
end
wait (1) seconds
endRead it from the inside out. That is the order it happens in.
| Where a block sits | How often it runs |
|---|---|
| Inside the inner loop | 12 times. That is 3 × 4. The counts multiply. |
| Inside the outer loop, outside the inner | 4 times. Once for each dash. |
| Outside both | Once. |
The counts multiply. That catches everybody out. Say you want twelve steps, so you write repeat (12) in both loops. You get a hundred and forty-four! First decide what one trip round each loop means. Then pick the numbers.
Ask what it is part of. The stepping is part of the dash, so it goes inside. The pause comes between dashes. So it goes in the outer loop, after the inner one. What about a beep for each new dash? It goes at the top of the outer loop, before the inner one.
Move a block from one loop to the other, and it is not a small change. You have changed how many times it happens. Often by a lot.
Machines repeat. A wiper sweeps, a conveyor runs, a ride goes round — and none of that should mean copying the same blocks over and over. A loop says “do this again” once.
| Block | What it does |
|---|---|
repeat (10) end | Runs the blocks inside a set number of times, then carries on below. |
forever end | Runs the blocks inside over and over, and never carries on below. |
repeat until <> end | Repeats until a condition becomes true — a loop with a sensor as its exit. |
Anything placed after a forever loop will never run. Not “runs late” — never. Both programs below end with the same block: set the status light green.
repeat (3)
forever
↑ this block never runs
Both programs contain the same green-light block. Let it run as long as you like — the right-hand ring will never turn green.
The repeat loop counts its three passes, stops, and moves on to the block underneath, so its light turns green. The forever loop reaches the bottom of its own blocks and jumps straight back to the top, so the block underneath is never reached — however long you leave it. If a program seems to stop half way through, look for a forever loop above the blocks that are not happening.
A program is a list, and the Brick works down it once. Every block runs, in order, and when the last one is done the program is over. That is fine for a list of instructions — drive, turn, beep, stop — because each is a thing you do once.
A sensor is not a thing you do once. Asking is 1 pressed? gives you an answer about this instant, and an instant later it may be wrong. Checking a sensor once tells you what the world was like at the moment the program started — which is almost never what you wanted to know.
So a program that has to react must ask again, and again, for as long as it is running. That is the whole job of the loop: not to repeat an action, but to keep the question being asked.
Wrap a sensor check and the motor it controls in a forever loop and you have built a closed-loop control system — the pattern behind every line follower, thermostat and cruise control:
It is called closed because the output feeds back round to the input: the motors move the robot, moving the robot changes what the sensor sees, and what the sensor sees changes the motors. Break the circle at any point and the robot stops responding.
when program starts :: events hat
forever
if <[1 v] is pressed? :: sensors> then
[A v] start motor [clockwise v] :: motors
else
[A v] stop motor :: motors
end
endRead it as a sentence and it is almost too simple to need explaining: for ever, if the button is pressed run the motor, otherwise stop it. The motor now follows the button for as long as the program is running.
This is the mistake nearly everybody makes first, and it is a hard one to spot because nothing about it looks wrong:
when program starts :: events hat if <[1 v] is pressed? :: sensors> then [A v] start motor [clockwise v] :: motors else [A v] stop motor :: motors end
The logic is perfect. The ports are right. Nothing is misspelled. And the robot will ignore the button completely — because the Brick reaches that if/else a few milliseconds after you press Run, finds the button not pressed, takes the else branch, stops the motor, runs out of blocks and ends. By the time a finger arrives, there is no program left to notice it.
with forever — a closed loop
without it — the common mistake
↑ running — for the only time
Both programs contain exactly the same if/else. The only difference is the forever block around one of them.
Both programs contain exactly the same if/else. The counter is what gives it away: one keeps checking for as long as it runs, the other is stuck on the single check it made before anybody touched anything. A student who has seen this once stops writing it.
The tell on a real robot is a program that ends the instant you start it — the Brick returns to its menu almost immediately. If a sensor program finishes rather than waits, the loop is what is missing.
The inner loop is one burst. The outer loop is how many bursts. Do not mix them up.
Everything so far has been relative: move 90 degrees from wherever you are now. Sometimes what you actually want is absolute: go to the 90-degree position, whatever position you happen to be in at the moment.
Both pointers below do the same job over and over: swing out a quarter turn, then come home. The only difference is the block that brings them back. Watch one trip and they look identical — so let it run for several.
relative — by an amount
absolute — to a place
Let it loop. Nothing about the left program is wrong — it is just that every trip starts from wherever the last one finished, so a small error is never corrected, only added to.
A pointer moved relatively slowly wanders: each movement starts from wherever the last one finished, so any small error is carried forward and added to. Each orange dash is a trip that called a slightly different place “home”. Nothing about that program is wrong — it is simply that a relative move has no idea where it is supposed to end up.
An absolute movement has no memory of the error. Told to go to position 0, it goes to position 0 — the same place every time, however wrong it was beforehand. That makes it the right tool for a home position: the known place a mechanism returns to before it starts work.
This is possible because an EV3 motor counts its own turning all the time. Its position can be read back, and can be reset to zero — which is how you tell the motor that here is what you mean by zero, usually at the start of a program with the mechanism held at its resting place.
A clock hand returns to twelve; a car’s steering returns to centre; a 3D printer homes its head before every print. All of them go to a position rather than moving by an amount.
Say this back before moving on: “Inside the inner loop, the counts multiply.”
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | The body. It is also most of the weight. On a walking model, the weight decides which legs really grip. |
| Large Motor, the walk | Moves all eight legs through one set of linked rods. One full turn is one whole step. That is why 360 degrees means “one step”. |
| The leg linkage (not electronic) | The rods that join the legs. They keep the legs out of step, so some are always down. Turn it slowly and look. Half the legs lift while the other half push. |
| The Brick screen and speaker | Count the dashes and the steps. Then you can hear the loops working, not just hope they are. |
Sensors go in ports 1, 2, 3, 4. Motors go in ports A, B, C, D. You cannot swap them. If you do, nothing warns you. The robot just will not work.
| Part | Port | Why this one |
|---|---|---|
| Walking motor (Large) | A | One motor moves all eight legs. So there is just one thing to plug in. |
| Sensors | none | The spider walks blind. It stops because the program says so. It has not seen anything. A real spider is the other way round! |
Check your own build now:
Two routes, and either is fine. USB is the reliable one and the one to fall back on when a room’s Bluetooth is busy; Bluetooth leaves the robot free to move, which some models need.
Do these in order. Naming the Brick after you go looking for it in the list is how groups end up driving each other’s robots.
EV3 until somebody changes it.EV3.The two failures, every class, every time. The Brick has gone to sleep while you were building — press the centre button to wake it. Or you have paired with the group at the next table, which is why the name matters.
The long version, including Port View and how to read the port tiles, is in the Brick & Bluetooth guide.
Bluetooth. This one walks. A cable dragging behind it gets caught in its own back legs almost straight away.
Before every run, guess the total number of steps. Say it out loud. Then count the low beeps to check. A good guess is the skill you are learning.
wait (1) seconds inside the inner loop. Run it. Now the spider stops after every step. Same blocks, different loop, and a very different animal.Steps 3 and 4 are the lesson. Nothing was added. Nothing was taken away. One block moved to the other loop. The spider stopped looking like a spider. All that changed was how many times that block runs.
Which loop a block sits in is not about being tidy. It decides how often the block runs.

Build the model before you read any further. Everything after this is about making it do something, and none of it will make much sense with nothing on the table in front of you.
One page at a time — use Next and Previous, or the ← → keys. Fullscreen makes it big enough to build from.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
Four dashes of three steps each, with a pause between. The Brick beeps for both.
when program starts :: events hat
clear display :: display
write [SPIDER] at line (1) :: display
repeat (4)
write [Run ] at line (3) :: display
play beep (75) for (0.1) seconds :: sound
repeat (3)
[A v] run for (360) [degrees v] at (45) % speed :: motors
play beep (60) for (0.05) seconds :: sound
end
write [Still] at line (3) :: display
wait (1) seconds
end
write [END] at line (5) :: displayWhat success looks like: listen, do not just watch. You should hear high, low-low-low, silence, four times. Is there a pause after every single step? Then the wait has got inside the inner loop.
Count the low beeps. There should be twelve. Do you hear a different number? Then your two loop counts are not what you think. Counting beeps finds this much faster than watching the legs.
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Make a walk you can hear. Take a burst of steps, then a pause, and repeat. A friend with their eyes shut should be able to tell you two things. How many bursts were there? How many steps were in each one?
Get exactly twenty steps out of the spider. Use two loops, with more than one burst. More than one pair of numbers will work. Find two of them. Say which pair makes the better-looking spider.
Move one block from one loop to the other, on purpose. Start with a walk that works. Move one block from the inner loop to the outer loop. Before you run it, guess what will change. Then run it. Were you right?
Give the spider a trip with a shape to it. A spider crossing a room does not do the same thing all the way. It might dash three times to reach a hiding place. Then it waits longer than usual. Then it dashes twice more. Your job is to build a trip with at least three different parts. The shape of your program must match the shape of the trip. Plan it on paper first. Draw the loops. Draw the outer loop as a box. Draw the inner loop as a box inside it. Next to each box, write how many times it goes round. Write what one trip round it means, too. Then work out the total number of steps from your drawing. Do this before you build anything. Then build it. Count the steps as it runs. The number you worked out and the number you hear must be the same. When you show it, answer two questions. Where was your count different from the real one, and which loop caused it? And your spider stops because the program says so. A real spider stops so it can look. What would you add so that your spider stopped for a reason?