Challenge 1
Make the dinosaur take ten steps, not six. Make it thud twice on each step, not once. You should change one number and add one block. Are you copying blocks out ten times? Then stop and look at the loop again.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 1 · Beginner›Lesson 22
Level 1 · Lesson 22 · EV3-L01-2260 minutes · Ages 7+ · Model: Stegosaurus
The Stegosaurus: a dinosaur with four legs. It has a row of plates down its back. It has spikes on its tail. One motor moves all four legs.
Your Hexapod took five steps because you told it five rotations. That worked, but it is not quite what you meant. You meant “take five steps, and make a noise on each one”. There is a block for saying just that.
By the end, this dinosaur will walk the steps you choose. It will thud once on every step. To change the number of steps, you change just one number.
Stegosaurus lived about 150 million years ago. It is one of the easiest dinosaurs to spot. Look for the two rows of tall, bony plates on its back.

Nobody knows for sure what the plates were for. Even dinosaur scientists still argue about it! Maybe they kept it safe. Maybe they were for showing off. Maybe they helped it cool down. The tail spikes are less of a mystery. Scientists have found Allosaurus bones with holes the shape of Stegosaurus spikes.
We do know how it walked. A heavy animal with four legs moves them the same way, over and over. Each time round the pattern is one step.
What if an animal had to think about every leg, one by one? It would be far too slow to stay alive. Walking is not a long list of different instructions. It is one short pattern, repeated.
That is just what a loop is for. It is why programs for things that repeat can be short.
You have met loops before, on the Wipers in Lesson 2. A forever loop never stops. That is right for a machine that runs all day. It is wrong for almost everything else.
repeat (6) runs the blocks inside it six times. Then it carries on to the next block. forever never carries on, because there is no next.
The demo runs both, side by side. Watch the block below each loop. One of them lights up in the end. The other one never will.
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.
There is one more reason to use a loop. It matters a lot. You could write the step blocks out six times. But what if you want seven steps? Now there are six places to change. You may miss one. With a loop, there is just one number.
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 Brick has a small speaker. It can play one of the built-in sound files, or beep a note you choose. Sound is what makes a machine feel finished — and it is also a way for the robot to tell you something without you having to look at it.
| Block | What it does |
|---|---|
play sound [Communication / Hello v] until done :: sound | Plays the sound and waits for it to finish before the next block runs. |
start sound [Communication / Hello v] :: sound | Starts the sound and moves straight on to the next block, so the sound plays while the robot keeps working. |
play beep (60) for (0.5) seconds :: sound | Plays a single note for a set time — useful for short alerts. The number is a note, not a volume: bigger means higher. |
set volume to (100) % :: sound | Sets how loud everything after it will be. Worth putting at the top of a program — the Brick remembers the last volume it was given, even from somebody else’s program. |
stop all sounds :: sound | Cuts off anything that is still playing, including a long sound started earlier. |
These two blocks play the very same file. The difference is what the rest of the program does while it plays — so it cannot be heard on its own, only seen. Here are both, each lifting a barrier.
play sound until done
start sound
Watch the barriers, not the clock. On the left the warning finishes before anything moves; on the right it sounds while the barrier lifts.
The bars underneath are when the speaker was on and when the motor was turning. On the left they never overlap: the program is stuck at the sound block until the file has finished, and only then does the barrier lift. On the right they overlap almost completely, and the whole job is done in half the time.
Real machines warn before they move, not after: a lift chimes before the doors close, a reversing lorry beeps while it rolls back, a level crossing sounds before the barrier drops. Getting the order right is the difference between a warning and an apology.
Say this back before you move on: “A repeat block does the same thing again and again. One number says how many times.”
One motor again. This time, the Brick is not part of the dinosaur at all. It sits next to it on the table. The cable runs across.
Look at the motor’s axle. The part on it is not a normal gear. It is a worm: a screw lying on its side. It fits into the teeth of a 24-tooth gear.
One full turn of a worm moves its gear by exactly one tooth. So a 24-tooth gear needs 24 turns of the motor to go round once. Just two parts slow the motor down 24 times!
That is far slower than the Ferris Wheel’s gears in Lesson 12. It turns a fast, weak motor into a slow, heavy dinosaur.
Now try it backwards. Turn the motor axle by hand, and the legs move. Now hold a leg and try to turn it by hand. The worm will not move at all! A worm only works one way round. Big machines use worms when a heavy load must never slip back.
You need one number before you can program this well. Turn the motor axle slowly by hand. Count how many motor turns make one whole step. That is one full up, forward, down and back of a front leg. Write it down. Every program below uses your number.
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 |
|---|---|---|
| Large Motor (drives the worm) | A | A motor on its own usually goes in A. Every program on this page says A. |
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.
The dinosaur walks, but the Brick stays still. So the motor cable has two jobs. It carries power, and it ties the model to the Brick. Leave the cable nice and loose before you press play.
Does the number stay still when the axle turns? Then stop here. The cable is in the wrong port. Or it is not pushed all the way in.
Try it the other way too. Hold the model still and push a leg. The number should not move at all. A leg cannot turn the worm. It is good to see this now. Later, a stuck dinosaur may show no change. You will know why.
Make one change at a time. Guess what will happen before each run.
end. Guess how many thuds you will hear. Then run it and count. Inside the loop means once on every step. Outside means once, at the end.Remember Step 2. Is a block inside or outside a loop? That changes how many times it happens. A block in the wrong place is not broken. It is just in the wrong place.
Does the dinosaur shuffle without going anywhere? Check that all its feet touch the table. Check it is not sitting on its tail. A worm has lots of force. So if the model will not move, it is almost always standing wrong. The motor is strong enough.

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.
The same build on Google Drive — sometimes a video, sometimes a scan:
Fullscreen it while you build — you can pause and scrub with the player's own controls.
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.
Six steps, and a thud on each one. Replace 24 with the number you counted in section 5. Does your dinosaur take one step every 24 motor turns? Then leave it as it is.
when program starts :: events hat [A v] set speed to (40) % :: motors repeat (6) [A v] run [clockwise v] for (24) [rotations v] :: motors play beep (50) for (0.2) seconds :: sound end
Walk it in the order the Brick runs it:
end happens until all six are done.What success looks like: six thuds, one on each step. Then it goes quiet. The program has finished, and the dinosaur stops where it is. Count the thuds out loud. Do you hear five, or seven? Then your step number is wrong, not your loop.
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 the dinosaur take ten steps, not six. Make it thud twice on each step, not once. You should change one number and add one block. Are you copying blocks out ten times? Then stop and look at the loop again.
Make it walk, pause, and walk again. Do six steps, then a clear two-second rest, then six more. At the very end, play a sound that is different from the step sound. A person listening with shut eyes should tell the rest from the finish.
Make the dinosaur walk a set distance, not a set number of steps. Choose a target, say 30 cm. Measure how far one step really takes it. Work out how many steps that needs. Put that number in the loop. It must stop within a hand-span of the target on two runs out of three.
A museum wants your Stegosaurus for a display. It must act like a real exhibit, not a toy. Build a program that walks the dinosaur forward along its display case. At the end, it pauses as if it is eating grass. Then it walks back to just where it started. It must end on the same spot it began. Then it is ready to run again for the next visitor. Plan on paper first. Getting back to the start is the hard part. What must be true about the way back, compared with the way out? How will you check that it really got home, and not just nearly? You will be asked two questions when you show it. What did you have to measure before you could write the program? And after five runs in a row, does it still start from the same place? If not, why does the error grow?