Challenge 1
Make a dance with a beat you can clap along to. Make it eight bars long. A bar is one short group of beats. Beep on the first beat of every bar. Change the move partway through each bar. If a person can clap along, it has a rhythm.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 23
Level 2 · Lesson 23 · EV3-L02-2360 minutes · Ages 8+ · Model: EV3 Dancing Robot
The Dancing Robot: two Large Motors move the legs. A Medium Motor swings the arms. The Brick calls out the moves.
Lessons 6 and 8 each made one choice. The swing ride sped up and stayed fast. The pterosaur started gliding and kept gliding. Once the answer changed, it never changed back.
A dance is not like that. A dance is a choice made over and over. This move, now that one, now back to the first. Today you build a check that can give a different answer every few seconds.
Think of street dancers at a festival. A line of dancers moves together. They change moves on a count that everyone keeps in their head. Nobody calls out what to do. They all know the pattern. They all know where they are in it.

Dance is built on counts. Eight beats of one move, eight of the next, and back again. The count lets forty people change at the same moment, with no shouting. On every beat, each dancer asks the same question: where am I in the eight?
And the big thing is, the count resets. It goes from one to eight, then starts again. That is what makes a dance repeat, instead of wandering off.
What if the count only went up? The dance would change once. Then it would do the same thing for ever. That is a machine, not a dance. Everything with a beat needs something that comes back round to the start. Think of music, walking, breathing, or a heartbeat.
A question worth asking again and again is one whose answer can change back.
The swing ride and the pterosaur both checked a motor’s degree count. A degree count only goes up. That is why those machines changed just once.
(timer) :: sensors reset timer :: sensors
The timer goes up like anything else. But you can reset it whenever you like. That makes it different. A number you can send back to zero can make a check say yes, then no, then yes, over and over.
repeat (8)
reset timer :: sensors
repeat until <(timer) > (2)>
if <(timer) < (1)> then
write [LEFT ] at line (3) :: display
else
write [RIGHT] at line (3) :: display
end
end
endFollow the timer, not the blocks. It is reset to 0. It goes past 1, so the answer flips from the top branch to the bottom. Then it goes past 2. That ends the inner loop and sends it back to the reset. Going round like this is called a cycle. A cycle is what a rhythm is.
| Number | Goes up | Comes back down | So a check on it… |
|---|---|---|---|
| degrees counted | Yes | Only if you reset it, or run the motor backwards. | Flips once and stays. Good for one part of a job. |
| timer | Yes | Yes, whenever you reset it. | Can flip back and forth for ever. Good for a rhythm. |
A wait pauses for a length of time. The timer is different: it runs in the background and can be read at any moment, so the robot can know how long something has taken while it is still happening.
| Block | What it does |
|---|---|
(timer) | Reports the seconds since the timer was last reset. |
reset timer | Sets it back to zero, so the next reading counts from here. |
The most valuable use of a timer is escaping a wait that might never end. A robot told to drive until it sees a wall will drive for ever if the wall is not there. Combined with a timer, it can give up:
Repeat until the wall is close or five seconds have passed. That one change turns a program that can hang into one that always finishes. Both robots below are looking for a wall that is not there.
no way out
with a timeout
The sensor is not faulty and the program is not wrong. There is simply no wall, and only one of these two programs has a way of noticing that.
The left-hand robot is not broken, and neither is its sensor. Its condition is simply one that will never come true, so the program sits on that block for ever — with nothing on the Brick to say so. The right-hand program asks the same question with an escape route bolted on, and finishes every time.
Real systems time themselves out constantly — a lift that cannot close its doors eventually gives up and beeps rather than trying for ever. A robot with no timeout simply stops responding, and there is nothing on screen to say why.
To make a machine keep changing its mind, give it something that keeps changing.
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.
Say this back before you move on: “Reset the timer and the answer can change back.”
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | Keeps the count and calls the moves. The timer it reads is inside the Brick, not in a motor. |
| Large Motor ×2 — the legs | Ports B and C, run as a pair. The same speeds make it step in place. Opposite speeds make it spin. Both are dance moves. |
| Medium Motor — the arms | Runs on its own, at its own speed. It uses the start that does not wait, from Lesson 15. The arms keep going while the legs change moves. |
| The Brick screen and speaker | Call the move and keep the beat. Then people watching can hear the count the robot dances to. |
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 |
|---|---|---|
| Left leg (Large) | B | B is left. The Movement blocks expect it. |
| Right leg (Large) | C | C is right. |
| Arms (Medium) | A | Not part of the movement pair. So the arms can run at their own speed while the legs move as a pair. |
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.
Use Bluetooth. This robot spins on the spot again and again. A cable would wrap round its legs within about two bars.
Change one number at a time. Clap along with the beeps. If you can clap to it, it has a rhythm.
reset timer above the repeat (8). Run it. Watch the dance stop after one bar. Then say why, in one sentence.Step 3 is the whole lesson in one change. Move the reset out of the loop, and the number stops coming back down. Then the Switch gives the same answer for ever. You are back to the pterosaur, in Lesson 8.
The reset is not tidying up. The reset is what makes it a rhythm.

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.
Eight bars of a dance with two moves. Step left, step right, with the arms going the whole time.
when program starts :: events hat
set movement motors to [B v] and [C v] :: movement
clear display :: display
write [DANCING] at line (1) :: display
[A v] start motor at (60) % speed :: motors
repeat (8)
reset timer :: sensors
play beep (70) for (0.1) seconds :: sound
repeat until <(timer) > (2)>
if <(timer) < (1)> then
write [LEFT ] at line (3) :: display
start moving at (30) (-30) % speed :: movement
else
write [RIGHT] at line (3) :: display
start moving at (-30) (30) % speed :: movement
end
end
end
stop moving :: movement
[A v] stop motor :: motors
write [END] at line (5) :: displayWhat success looks like: a beep every two seconds. Between beeps, the robot turns one way, then the other. The arms swing all the time. The screen shows LEFT, then RIGHT, in time with the moves.
Does it only ever go one way? Then the timer is not being reset. Check that
reset timeris inside the outerrepeat (8), not above it. If it resets only once, the timer stays past 2 for ever after the first bar.
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 dance with a beat you can clap along to. Make it eight bars long. A bar is one short group of beats. Beep on the first beat of every bar. Change the move partway through each bar. If a person can clap along, it has a rhythm.
Make an uneven rhythm. One move lasts clearly longer than the other, over and over. Then say which number you changed. What would a dancer call that?
Give the arms a rhythm of their own that does not match the legs. Arms and legs must run at different speeds. They must change at different moments. Then the robot is doing two rhythms at once. Say how you kept them apart.
Make up a dance and teach it to someone else. Write your dance down the way real dances are written down. Make a list of bars. For each bar, write what the legs do and what the arms do. Write what the Brick says or plays. Decide the tempo before you write any blocks. The tempo is how fast the beat goes. Build just what you wrote. The robot might do something your sheet does not say. Then fix the robot or fix the sheet. They must agree at the end. Then give your written dance, and only that, to another group. Ask them to build it on their robot. Do not help. When you show it, answer two questions. What did the other group get wrong? Was it their mistake, or a gap in how you wrote it? And your dance is just the same every time. Two shows should be clearly the same dance, but not exactly the same. What would you add?