Basic
Follow the black line from the start box to Home. Stop fully inside Home.

Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 18
Level 2 · Lesson 18 · EV3-L02-1860 minutes · Ages 8+ · Model: Battle Rescue Robot
The Battle Rescue Robot: a driving base with a holder for up to ten short beams. The holder is called a magazine. A Medium Motor lets go of a rubber band. That shoots the beams out one at a time.
You send it where a person should not go. It can clear a path, knock something over, or go in and come back. One machine, lots of jobs.
By the end of the lesson, your robot will have a menu. It will have three jobs to pick from. Each job is called a mode. One button moves through the modes. Another button says “do it”. The screen always shows the mode you are in.
Safety comes first. This model shoots a beam. Point it at a wall or a cardboard box. Never point it at a person, an animal or a window. Everyone within two metres wears eye protection. That rule stays all lesson, for everyone.
Bomb robots go in so that a person does not have to. One robot carries a camera, an arm, a gripper, and sometimes a tool to break the bomb. A person far away picks which one to use.

One robot with lots of tools is better than lots of robots with one tool each. It costs less. There is only one thing to carry and fix. But the real reason is this. You do not know which tool the job needs until you get there.
But it makes a new problem. A robot with one job never has it. The same button now does different things in different modes. The person in charge must know the mode before they touch anything.
You know this problem already. Type your password with Caps Lock on. Every key does something you did not mean. Nothing warns you. You only find out after. The keyboard was in a mode, and it did not tell you.
Pilots have a name for this: mode confusion. It has caused real plane crashes. The pilots thought the autopilot was in one mode. It was really in another. They gave the right orders, but for the wrong mode. The fix is always the same: show the mode, all the time, where the person is looking.
A mode you cannot see is a trap. If a machine has modes, the most important job of its screen is to show the mode.
A variable is a box that holds a number. The Minesweeper used one to count mines, in Level 1, Lesson 44. A button can change the number too. Flip it between 0 and 1, and you get two modes. But it does not have to stop at two.
change [mod v] by (1) if <(mod) > (3)> then set [mod v] to (1) end write (mod) at line (1) :: display
if makes it go round and round. Without it, the number would just keep growing.Going from 3 back to 1 is called the wrap. Without those three lines, the number goes 4, 5, 6. Then every mode check after 3 fails. The robot ends up in no mode at all. Nothing tells you. change by 1 gives no warning. To a number, counting past 3 is fine.
Check for greater than, not equals. if <(mod) > (3)> catches 4. It also catches 7, if the number ever skipped. if <(mod) = (4)> works until the number goes up by two at once. Then the menu is broken until you restart.
One button picks the mode. Another button does it. Keeping them apart is the whole plan:
if <(mod) = (1)> then
move [forward v] for (2) [rotations v] at (40) % speed :: movement
else
if <(mod) = (2)> then
[A v] run [clockwise v] for (1) [rotations v] at (100) % speed :: motors
else
move [backward v] for (3) [rotations v] at (60) % speed :: movement
end
endThere is no fourth branch. You do not need one. The last else catches every number that is not 1 or 2. The wrap keeps mod between 1 and 3. So that means 3.
Long before there were computers, people had exactly this problem. A shepherd counting sheep through a gate, a trader counting sacks of grain, a builder counting days — none of them can hold the number in their head while they get on with the work. So they scratched a mark on a wall, cut a notch in a stick, or wrote a number on a piece of paper. The number lived outside the person, in a place they had agreed on, and they could go back to it, read it, and change it.
Better still, once the number is written down somebody else can use it. Watch these two: one of them counts and writes, the other never sees a single animal and simply reads the wall.
Notice what never happens: Ben never asks Abby. He does not need to — the number is not in her head, it is on the wall, and the wall is there for anyone who needs it.
Neither Abby nor Ben is holding the number — the wall is. And notice what never happens: Ben does not ask Abby. He does not need to, because the count is not in her head. It is in a place they both agreed on, which is what makes it useful to more than one of them.
That is all a variable is. The robot cannot hold a number in its head either, so you give it a wall of its own, write a name at the top so everyone knows which wall is which — score, count, degree_turn — and the program can read what is on it and write something new. One part of the program writes; another part reads. Exactly Abby and Ben.
Say we are counting rotations of a motor. Before we start we write 0 on the paper. Every time the motor completes a turn we cross out what is there and write one more: 0 becomes 1, then 2, then 3. That is change — it has to read the old number to work out the new one.
set is the other thing you can do, and it is completely different: rub the whole paper out and write the number you want. It does not care what was there. Press the buttons and watch what happens to the crossings-out.
The paper starts blank, so we write 0 on it. That is what a variable is: a place to keep a number while the robot works.
| Block | What it does |
|---|---|
set [count v] to (0) | Puts a value in, replacing whatever was there. |
change [count v] by (1) | Adds to what is already there. |
(count) | Reports the current value, for use in a comparison or on the display. |
set replaces; change adds. Counting things needs change. Starting a count needs set. Both programs below have both blocks — the only difference is whether the set block is inside the loop or above it.
set before the loop
set inside it
Both programs contain both blocks. Only the position of set [count] to 0 is different.
The count on the right is not broken; it is being told to start again on every pass. Each time round the loop it is wiped back to zero and then changed by one, so the honest answer is always 1 — while the motor cheerfully turns four times. A counter stuck at 1 almost always means a set block that has slipped inside the loop.
EV3 Classroom tells you what a block does by its shape, and once you have noticed that, a whole set of questions answers itself:
So when a slot is oval, any oval fits it — and it does not matter in the least where that number came from. You can take the motor’s own A degrees counted and keep it in a variable you named degree_turn, then compare that with a number later. Pick an oval below and watch the same one drop into all three kinds of slot.
pick an oval
the same oval fits all three
Every one of those slots is oval-shaped, and A degrees counted is an oval — so it drops in. Nothing about where the number came from matters.
This is what makes a variable more than a counter. A sensor reading is true only at the instant you read it; copying it into a variable freezes it, so the robot can compare where it is now against where it was when something happened:
when program starts :: events hat [A v] reset degrees counted :: motors set [degree_turn v] to ([A v] degrees counted :: sensors) start moving [right: 30] :: movement wait until <(([A v] degrees counted :: sensors) - (degree_turn)) > (400)> stop moving :: movement
Read the condition aloud: how far the motor has gone now, minus where it was when we started, is more than 400. Both are ovals, so both can go into a subtraction, and the subtraction is an oval too — which is why it can go into a comparison. Ovals nest inside ovals as deep as you need.
A variable keeps its value after the program ends. Run the program again without setting it back and the second run begins where the first left off — the count starts at 14, the robot thinks it has already done the job. Every variable a program changes must be set to its starting value at the top.
A variable is the difference between a machine that repeats a fixed routine and one that responds to how things have gone — counting parts, tracking a score, remembering where it started.
The Brick has five buttons of its own — up, down, left, right and centre. They need no sensor, no cable and no port, which makes them the easiest way to let a person tell the robot to do something.
| Block | What it does |
|---|---|
when [center v] button [pressed v] :: events hat | Starts a whole stack when that button is pressed. |
wait until <is [center v] button pressed? :: sensors> | Holds an existing program until the button is pressed. |
A program sitting on a wait block looks exactly like a program that has crashed. Watch one wait — including through two presses of the wrong button.
the other way to do it
A program parked on a wait block looks identical to a crashed one. This is why the status light or a line on the screen is worth setting before you wait.
The wait is watching one button. Up and right change the (button) reading, and the program does not care. That reading is a number rather than a name: 0 for nothing, then 1 left, 2 centre, 3 right, 4 up, 5 down.
Nearly every machine has a start button that is deliberately separate from switching the power on. A robot that begins moving the instant it is powered up is hard to set down and hard to test — one that waits for a press can be positioned first.
A mode is a variable with more than two values. Wrap it. Show it.
Long before there were computers, people had exactly this problem. A shepherd counting sheep through a gate, a trader counting sacks of grain, a builder counting days — none of them can hold the number in their head while they get on with the work. So they scratched a mark on a wall, cut a notch in a stick, or wrote a number on a piece of paper. The number lived outside the person, in a place they had agreed on, and they could go back to it, read it, and change it.
Better still, once the number is written down somebody else can use it. Watch these two: one of them counts and writes, the other never sees a single animal and simply reads the wall.
Notice what never happens: Ben never asks Abby. He does not need to — the number is not in her head, it is on the wall, and the wall is there for anyone who needs it.
Neither Abby nor Ben is holding the number — the wall is. And notice what never happens: Ben does not ask Abby. He does not need to, because the count is not in her head. It is in a place they both agreed on, which is what makes it useful to more than one of them.
That is all a variable is. The robot cannot hold a number in its head either, so you give it a wall of its own, write a name at the top so everyone knows which wall is which — score, count, degree_turn — and the program can read what is on it and write something new. One part of the program writes; another part reads. Exactly Abby and Ben.
Say we are counting rotations of a motor. Before we start we write 0 on the paper. Every time the motor completes a turn we cross out what is there and write one more: 0 becomes 1, then 2, then 3. That is change — it has to read the old number to work out the new one.
set is the other thing you can do, and it is completely different: rub the whole paper out and write the number you want. It does not care what was there. Press the buttons and watch what happens to the crossings-out.
The paper starts blank, so we write 0 on it. That is what a variable is: a place to keep a number while the robot works.
| Block | What it does |
|---|---|
set [count v] to (0) | Puts a value in, replacing whatever was there. |
change [count v] by (1) | Adds to what is already there. |
(count) | Reports the current value, for use in a comparison or on the display. |
set replaces; change adds. Counting things needs change. Starting a count needs set. Both programs below have both blocks — the only difference is whether the set block is inside the loop or above it.
set before the loop
set inside it
Both programs contain both blocks. Only the position of set [count] to 0 is different.
The count on the right is not broken; it is being told to start again on every pass. Each time round the loop it is wiped back to zero and then changed by one, so the honest answer is always 1 — while the motor cheerfully turns four times. A counter stuck at 1 almost always means a set block that has slipped inside the loop.
EV3 Classroom tells you what a block does by its shape, and once you have noticed that, a whole set of questions answers itself:
So when a slot is oval, any oval fits it — and it does not matter in the least where that number came from. You can take the motor’s own A degrees counted and keep it in a variable you named degree_turn, then compare that with a number later. Pick an oval below and watch the same one drop into all three kinds of slot.
pick an oval
the same oval fits all three
Every one of those slots is oval-shaped, and A degrees counted is an oval — so it drops in. Nothing about where the number came from matters.
This is what makes a variable more than a counter. A sensor reading is true only at the instant you read it; copying it into a variable freezes it, so the robot can compare where it is now against where it was when something happened:
when program starts :: events hat [A v] reset degrees counted :: motors set [degree_turn v] to ([A v] degrees counted :: sensors) start moving [right: 30] :: movement wait until <(([A v] degrees counted :: sensors) - (degree_turn)) > (400)> stop moving :: movement
Read the condition aloud: how far the motor has gone now, minus where it was when we started, is more than 400. Both are ovals, so both can go into a subtraction, and the subtraction is an oval too — which is why it can go into a comparison. Ovals nest inside ovals as deep as you need.
A variable keeps its value after the program ends. Run the program again without setting it back and the second run begins where the first left off — the count starts at 14, the robot thinks it has already done the job. Every variable a program changes must be set to its starting value at the top.
A variable is the difference between a machine that repeats a fixed routine and one that responds to how things have gone — counting parts, tracking a score, remembering where it started.
Say this out loud before you go on: “Cycle, wrap, show. Then act.”
Look at your robot. Three motors and no sensors. So how does the robot know anything? (From you. That is what the menu is for.)
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | The robot and the control panel. Its screen is the most important part today. It is the only thing that tells you which mode you are in. |
| Large Motor ×2 — the drive | A matching pair. They drive the robot in and bring it back. |
| Medium Motor — the launcher | Lets go of the band. One shot for each rotation. So it gets its own port and its own mode. |
| The magazine and band (not electronic) | Holds up to ten beams. The stretched band holds the energy. Nothing here counts the beams. You could add a counter for them. |
Step 3 matters more than it looks. Someone will get the starting mode by mistake. So make it the one that cannot hurt anybody.
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 drive wheel | B | The pair. Two motors, one job. |
| Right drive wheel | C | The other half of the pair. |
| Launcher | A | Its own job, away from the pair. |
| Sensors | none | A person picks the mode. A person decides when to act. In the challenges, you can add a sensor that picks the mode. |
The manual never says which port anything goes in. It ends at the last build step, with no cables drawn. So the ports above are this course’s usual ports, not the manual’s. Nothing in your build goes against them.
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. Keep the Brick where you can read it. The whole lesson needs you to see the mode. What if the screen is face down while the robot drives away? Then you have built the trap from step 2.
Stuck? The long version, with a photo of every screen, is in the Brick & Bluetooth guide.
Make one change at a time. After each one, hand the Brick to someone else. Do not explain it. Can they use it? That is the only test that counts.
mod is 6. No branch matches it, except the last else. So the wrong thing happens. Find out what.if <(mod) = (4)>. It works. Now press left very fast. Can you make it skip past 4? This is why greater than is safer.ammo. Set it to 10, and take 1 away at each shot. Do not fire when ammo is 0. Show it on line 2.Step 3 and step 6 are the same idea, from opposite ends. Take the screen away, and nobody can use a robot that works. Add a light with no words, and people can use it from further away. None of that changed what the robot does. All of it changed whether a person can use it.
Every time the mode changes, the screen must change too. Every time, or the screen will lie.

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.
Three stacks. One sets up. One moves through the menu. One does the mode you picked.
when program starts :: events hat
set movement motors to [B v] and [C v] :: movement
set [mod v] to (1)
clear display :: display
write [1 FORWARD] at line (1) :: display
when [left v] button [pressed v] :: events hat
change [mod v] by (1)
if <(mod) > (3)> then
set [mod v] to (1)
end
if <(mod) = (1)> then
write [1 FORWARD] at line (1) :: display
else
if <(mod) = (2)> then
write [2 LAUNCH ] at line (1) :: display
else
write [3 BACK ] at line (1) :: display
end
end
when [center v] button [pressed v] :: events hat
if <(mod) = (1)> then
move [forward v] for (2) [rotations v] at (40) % speed :: movement
else
if <(mod) = (2)> then
[A v] run [clockwise v] for (1) [rotations v] at (100) % speed :: motors
else
move [backward v] for (3) [rotations v] at (60) % speed :: movement
end
endWhat a good run looks like: the screen says 1 FORWARD. Press left twice. It says 3 BACK. Press left once more. It wraps to 1 FORWARD. Press centre. The robot does just what the screen says. It does it every time, with no surprises.
Does the screen say one thing, and the robot do another? Then your two Switch chains are no longer the same. That is mode confusion in a tiny robot. Stop and think about it. The robot does its job perfectly, but the screen lies about it.
This model drives, so its challenges are run on a mat. Mats differ between branches — check you are looking at the one in your room.

WRO 2019 RoboMission Elementary — Smart Passenger Transport · official WRO game mat, 2362 × 1143 mm
The challenges name these places rather than distances, so the same challenge works on any mat:
Written for the WRO 2019 RoboMission Elementary mat. Each one is a single program run that starts in the ✕ box.
Follow the black line from the start box to Home. Stop fully inside Home.

In one program run, follow the black line to Home, then on to School.

In one run, go to Home, then School, then the Zoo. Stay on the black line all the way.

In one run, go to Home, School and the Zoo, then the Shopping Center. Stay on the black line all the way.

In one run, charge at the Battery Area first. Then go to the Shopping Center, the Cinema, and finish at Home. Stay on the black line all the way.

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.
Go through three named modes, one after another. A mode is one job the robot is set to do. Make the robot do each job. The screen must always show the mode it is in.
Add a fourth mode. The wrap is going from the last mode back to the first. Make sure the wrap still works when someone presses the button very fast.
Show the mode on the status light as well as the screen. Then someone across the room can tell the mode without reading any words.
Plan a rescue mission with three stages. You switch the robot from one stage to the next at the right moments. First it moves forward. Then it clears something out of its way. Then it goes back with something it has rescued. Then hand the Brick to someone who has never seen your program. Can they finish the mission using only the screen?