Challenge 1
Play five rounds. The Brick must name the winner each time. It plays a beep only for the start signal.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 47
Level 2 · Lesson 47 · EV3-L02-4760 minutes · Ages 8+ · Model: Hand Speed Competition
The Hand Speed Competition: a game for two players. It tests who is quicker. There is a button on each side and a turntable in the middle. The Brick decides who was faster.
This model is made to be played, not just watched. Two people sit facing each other. Something happens. The first one to hit their button wins the round.
By the end of the lesson, the Brick will name the winner. And you will use the block that makes a fair race possible.
Every quiz show on TV has a row of buzzers. The players slam them at almost the same moment, and one light comes on. Nobody argues. The machine decided in a tiny part of a second.

A buzzer machine is not really waiting for one press. It waits for any press, from anyone. Then it asks a second question: which one was it? Those are two different jobs. Mix them up, and a home-made quiz game ends in an argument.
People take about a fifth of a second to react. Two players often press less than a hundredth of a second apart. So the machine must block everyone else the moment the first press comes in. If not, every light comes on.
Say you check player one, and then check player two. Player one wins every close round, just because they were asked first. The game is unfair, and nobody can see why. That is worse than a game that is plainly broken.
Waiting for “either one” is not the same as waiting for “this one”, then “that one”.
or, and the question it leaves behind 6 minIn Lesson 14, the Forklift needed and. Both things had to be true, or nothing happened. Today you need its twin. You met it on the Jazz Drum in Lesson 30. or is true when either side is true.
wait until <<[1 v] is pressed? :: sensors> or <[2 v] is pressed? :: sensors>>
| Button 1 | Button 2 | and (Lesson 14) | or (Lesson 30) |
|---|---|---|---|
| up | up | false | false |
| down | up | false | true |
| up | down | false | true |
| down | down | true | true |
and is fussy. It says true in one row out of four. or is easy-going. It says true in three rows out of four. Both ask about the same two buttons. They just want different answers.
or tells you that something happened. It never tells you what. When the wait ends, the program knows a button went down. It knows nothing else. To name the winner, it has to ask a second question.
wait until <<[1 v] is pressed? :: sensors> or <[2 v] is pressed? :: sensors>> if <[1 v] is pressed? :: sensors> then write [PLAYER 1] at line (2) :: display else write [PLAYER 2] at line (2) :: display end
or stops the clock. The if reads the score. Two jobs, two blocks.And see why this is fair. One block watched both buttons at the same moment. So no player was asked first. The if only runs after somebody has already won.
A sensor that reports a number cannot be used to make a decision on its own — 23 is neither true nor false. An operator turns that number into an answer by comparing it with something.
| Block | What it does |
|---|---|
<(x) > (50)> | True when the left value is bigger than the right. |
<(x) < (50)> | True when it is smaller. |
<<> and <>> | True only when both conditions are true. |
<<> or <>> | True when at least one of them is. |
Forget the symbols for a moment. A comparison is a question about position on a number line: is x to the left of the other number, or to the right? Left is smaller, right is bigger — and that is the whole of it.
Drag the orange x and the black marker, and change the comparison. The green stretch is every position of x that would make the answer true — so you can see where the answer flips before you get there. Turn not on and watch the green jump to the other side.
Drag either marker, or use the arrow keys.
is x to the LEFT of it?
The lab above asks one question at a time: is this x true? A robot never has just one x, though — a sensor reading slides up and down all the time, so what really matters is which stretch of the line makes the condition true. This one draws the whole answer at once.
Drag the circle to move the number you are comparing against, and change the comparison. Everything shaded green is a value of x that would make it true.
Drag the circle, or use the arrow keys. It moves in steps of 0.2.
Every number to the left of 0.2 — but not 0.2 itself, so the circle is hollow.
Watch the circle, because it carries the part everyone gets wrong:
Now turn not on with x > 2 selected and watch two things happen together. The shading jumps to the other side, and the circle fills in — because “not greater than 2” means 2 or less, and 2 has to be part of it. That pairing is the whole reason a hollow circle is worth drawing.
Why a robot cares. Two conditions that look almost identical — light < 30 and not (light > 30) — differ by exactly one value, the reading of precisely 30. A robot sitting right on its threshold behaves differently under the two, and that is the sort of bug that only shows up occasionally and looks like a broken sensor.
These three join answers together rather than numbers. The trap is that English is looser than a program: “stop if it is close and the bumper is pressed” sounds like it covers both situations, when it covers neither on its own.
Flip the two conditions and watch the table. There are only four possible situations in total, and and and or differ on exactly two of them.
| close | bumper | and | or |
|---|---|---|---|
| true | true | true | true |
| true | false | false | true |
| false | true | false | true |
| false | false | false | false |
and is fussy: it wants both. Three of the four rows are false.
Two sensors are running below: an Ultrasonic reporting a number, and a Touch Sensor reporting true or false. Watch the comparison turn the number into an answer, and watch and and or disagree.
and was true in one row out of four. or was true in three. That is the whole difference, and it is why one of them makes a robot look broken.
The comparison is doing one job: it takes a reading that is neither true nor false and, by holding it against a number you chose, produces something a decision can use. The moment the blue fill crosses the black marker is the moment the answer changes.
The number you compare against is a design decision, not a fact. “Close” for a parking sensor might be 15 cm; for a robot arm it might be 3. Pick it by measuring what the sensor actually reads in the situation you care about, then leave a margin.
and narrows: both must hold, so the robot acts less often but more certainly — stop only if something is close and the bumper is pressed. or widens: either will do, so the robot acts more readily — stop if something is close or the bumper is pressed.
In the four situations above, and was true in one of them and or in three. That is the practical difference: swapping one for the other does not adjust a robot slightly, it changes how often it reacts at all.
The Touch Sensor is the simplest input the EV3 has: a button that is either pressed or not. That sounds trivial, but it is how a robot knows it has hit a wall, reached the end of a track, or been told to start by a person.
| Block | What it does |
|---|---|
wait until <[1 v] is pressed? :: sensors> | Holds the program here until somebody presses the sensor. |
<[1 v] is pressed? :: sensors> | Reports true or false. Drop it into a condition to make a decision rather than a wait. |
[1 v] when [bumped v] :: events hat | Starts a whole stack of its own. The dropdown chooses the moment: pressed, released or bumped. |
A button is not only “pressed”. One press is three things: the moment it goes down, the time it stays down, and the moment it comes back up. Watch what a single press does to three programs at once.
versus two hat blocks
The middle counter is the one that surprises people. Nothing is wrong with it — a loop really does check that fast, and every check really is a separate answer.
Nothing there is broken. A loop really does get round hundreds of times a second, and each time it asks is pressed? the honest answer is still yes — so if that loop plays a sound or counts something, it does it hundreds of times from one finger. The two hat blocks each fire once, and they fire at different moments: pressed the instant the button goes down, bumped only when it comes back up.
The three options, and what each is for:
when program starts :: events hat set movement motors to [B v] and [C v] :: movement start moving [straight: 0] :: movement wait until <[1 v] is pressed? :: sensors> stop moving :: movement
The robot drives until something presses the sensor. Note that the movement is started unmeasured on purpose — the sensor decides when to stop, not a distance.
Touch sensors are everywhere in machines you cannot see into: a lift knows the doors are shut, a printer knows the lid is closed, a washing machine will not spin until it is latched. They are safety devices as much as inputs.
Use or to know that it happened. Then use an if to know which.
Up to now a robot has been able to wait for a sensor. Deciding is different: the robot checks the sensor and does one thing or another depending on the answer — and then carries on either way.
| Block | What it does |
|---|---|
if <> then end | Runs the blocks inside only when the condition is true. Otherwise skips them. |
if <> then else end | Runs one set of blocks when true and a different set when false. |
A decision made once, at the start, is almost never what you want. Here are two robots with the identical if-else, testing the identical sensor against the identical number — one inside a loop and one not.
decision inside a loop
the same decision, once
A decision is only worth as much as the last time it was made. Inside a loop, that is a few milliseconds ago.
Nothing is wrong with the right-hand program’s decision. It asked the question, got a truthful answer, and acted on it correctly. It simply never asked again, and the world moved on. Decisions belong inside a loop, so the robot keeps re-deciding as things change.
when program starts :: events hat
forever
if <([4 v] distance in [cm v] :: sensors) < (15)> then
stop moving :: movement
else
start moving [straight: 0] :: movement
end
endOnce there is more than one question, decisions can be arranged in four ways. They look nearly identical stacked up in the editor, which is exactly why they get muddled — the thing that differs is not what the blocks say, it is which routes through them exist.
One question sorts them almost completely:
| Are the questions… | Use | How many bodies can run |
|---|---|---|
| independent — any combination can be true | separate ifs | none, some, or all |
| one question, two answers | if / else | exactly one |
| the second only matters when the first is true | nested if | one, and only via the outer |
| mutually exclusive cases — exactly one should win | chained if / else | exactly one, the first that matches |
Each if is asked no matter what the others answered, so any number of them can fire on the same pass. That is the right shape when the conditions genuinely have nothing to do with each other.
forever
if <[3 v] is ambient light intensity [< v] (20) %? :: sensors> then
[A v] start motor [clockwise v] :: motors
end
if <[4 v] is distance [< v] (15) [cm v]? :: sensors> then
[D v] start motor [clockwise v] :: motors
end
endExactly one branch runs, every time. Reach for this whenever the robot must do something either way — and in preference to two ifs testing opposite conditions, which is the same idea written twice and can drift apart.
Putting one if inside another means the inner question is only ever asked when the outer one is true. Use it when the second question is meaningless otherwise: there is no point asking which side an obstacle is on when there is no obstacle.
if <[4 v] is distance [< v] (15) [cm v]? :: sensors> then
if <([2 v] angle :: sensors) < (0)> then
start moving [right: 50] :: movement
end
endWhen not to nest. If you only want “both true” and nothing happens at the outer level, an and says it in one block and reads better:
if <<[4 v] is distance [< v] (15) [cm v]? :: sensors> and <([2 v] angle :: sensors) < (0)>> then start moving [right: 50] :: movement end
Nesting earns its place when something happens at the outer level too, or when there is an else at each level and the two mean different things.
This is the shape for a list of cases where exactly one should win: colour bands, distance bands, speed ranges. EV3 Classroom has no else-if block, so you build a chain by putting the next if inside the else of the last one.
And here is why it matters, because this is the single commonest bug in this whole module. Three bands written as three separate ifs are each perfectly correct, and together they are wrong: a reading of 20 is under 30 and under 60 and under 90, so all three run and the last one to run is the one that sticks.
three separate ifs
chained — if / else / if
↑ the rest is inside the else — never asked
Separate ifs are not wrong here so much as unguarded: nothing stops a second one matching. Chaining is what makes “the first one wins” true.
The rule to carry away: if the cases are meant to be exclusive, they must be made exclusive. Chaining does it by construction. Separate ifs only work if you are careful to write non-overlapping bands yourself — light < 30, 30 to 60, 60 and over — which is more to get right and easy to break later.
This is the point at which a machine stops following a script and starts responding. A thermostat, an automatic door, a robot vacuum — all of them are a decision inside a loop.
Say this back before you move on: “or ends the race. if names the winner.”
Look at your machine. Which electronic parts can you find? How many of each? Today, the part you have two of is the one that matters.
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | The referee. It watches both buttons. Nothing else in the room is fast enough to judge a close round. |
| Touch Sensor — player one | The left button. It looks just like the other one. |
| Touch Sensor — player two | The right button. Nothing on the part tells you which player it is. Only the cable does. |
| Large Motor — the turntable | Swings the whole turntable round. It is a Large Motor because it moves the arm and everything fixed to it. |
| Medium Motor — the arm | Rides on the turntable and drives the pointer arm. It is a Medium Motor because it gets carried round. Light is better when it spins. |
You met this first on the Machine Gun in Level 1. Two Touch Sensors look the same, feel the same and give the same answer. The port is the only difference between them. Swap the two cables, and the game runs fine. But it names the wrong winner every time, and there is no error anywhere.
Put a sticker on each button now: 1 and 2. Thirty seconds of tape saves ten very confusing minutes at step 9.
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 |
|---|---|---|
| Player one’s button | 1 | The Touch Sensor’s usual home in this course. |
| Player two’s button | 2 | Usually this is the Gyro’s port. But this model has no Gyro, so 2 is free. We tell you here, so it does not surprise you. |
| Arm motor (Medium) | A | A motor doing its own job. The manual puts the Medium Motor here too. |
| Turntable motor (Large) | D | A second motor with a different job goes in D. It skips B and C, so nobody drives the two as a pair. The manual agrees: “Large motors connect to port D.” |
The manual puts the two buttons in ports 1 and 4, not 1 and 2. Either works. The sensors are the same, and a cable moves in a second. But this lesson’s programs say 1 and 2. So move the second cable to port 2, or change every 4 in your program. Do not do half of each.
Check your own wiring 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.
Two players will be grabbing at this machine. Cable or Bluetooth, keep the cables off the edge of the table. Keep them out of the way of fast hands.
Stuck? The long version, with a photograph of every screen, is in the Brick & Bluetooth guide.
Change one thing at a time. Play a real round after each change. This is a game. So the test is: is it fun, and is it fair?
or for two waits, one after the other. First [1 v] wait until [pressed v] then the same for 2. Play five rounds. Now player two can only win by pressing after player one. That is the opposite of a race!or back. Change wait (3) seconds to wait (pick random (2) to (6)) seconds. Now nobody can guess when it will start. Is the game better?or to an and and run it. Now the wait only ends when both buttons are held down together. The game turns into a puzzle you solve as a team. Same two sensors, one word changed.or inside an or. It gives the referee a stop button.forever loop. Add a wait (3) seconds at the end. Now it plays round after round, and you do not have to restart it.Talk about step 1 afterwards. The program was not broken. There was no error, and it named a winner every round. It was just asking the wrong question. Only playing it showed that. Some bugs cannot be found by reading.
Checking two things one after the other is not the same as watching both at once.

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.
One round of the game: get ready, a pause, go, and a winner.
```ev3blocks The beep is the start of the race. The or is the finish line. The if is the photo that decides who won.
when program starts :: events hat
clear display :: display
write [GET READY] at line (1) :: display
[A v] start motor [clockwise v] :: motors
wait (3) seconds
[A v] stop motor :: motors
write [GO! ] at line (1) :: display
play beep (76) for (0.3) seconds :: sound
wait until <<[1 v] is pressed? :: sensors> or <[2 v] is pressed? :: sensors>>
if <[1 v] is pressed? :: sensors> then
write [PLAYER 1 WINS] at line (3) :: display
else
write [PLAYER 2 WINS] at line (3) :: display
end
play sound [Communication / Hello v] until done :: sound
1. **The arm spins during GET READY** and stops on *GO!*. It gives the players something to watch. Then nobody can count to the beep. Port **A** is the arm. Use **D** instead if you want the whole turntable to swing.
2. **The beep and the screen change at the same time.** A player notices a sound faster than a screen. So the beep is the real start. The words are for the people watching.
3. **One block watches both buttons.** This is the fair part. Neither button is checked before the other.
4. **Then, and only then, the `if` asks who.** By the time it runs, the race is already over.
**What success looks like:** the arm spins for three seconds. The Brick beeps. Two people dive for their buttons. The screen names one of them before either one lets go.
> **Does it always say PLAYER 2?** Player one's button is not reaching port 1. Go back to step 8. Does it name a winner *before* the beep? Somebody is leaning on a button. The `or` is doing just what it was told.
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.
Play five rounds. The Brick must name the winner each time. It plays a beep only for the start signal.
Keep score. The first player to win three rounds ends the game, with a different sound. Both scores stay on the screen the whole time.
Catch a false start. If a player presses before the start beep, they lose that round. The screen says why.
Design a fair game for four players, with three rounds. They share two buttons. The game must catch false starts. It must keep the scores and show them as it goes. It must not start a round until both buttons are let go. It must name the winner at the end. Write your rules down first. Then test them against somebody who is trying hard to cheat.