Challenge 1
Make a flight with a clear take-off and a clear glide. Make the screen say which one is happening. Someone across the room should be able to tell you when it switched. Do not tell them what to look for.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 8
Level 2 · Lesson 8 · EV3-L02-0860 minutes · Ages 8+ · Model: EV3 Dinosaur Pterosaur
The Pterosaur. It is a flying reptile with a long, pointed head. Its wings are much wider than its body. One motor moves the wings up and down, through a set of joined parts called a linkage.
In Lesson 6, your Swing Ride learned to decide whether to do something. This model needs more than that. A pterosaur is never doing nothing. It is flapping, or it is gliding. It is always doing one of them.
That is a different kind of question. Not “should I?” but “which one?”
You can see Pteranodon hanging from the ceiling in some museums. Its wings were six or seven metres wide. But its body was no heavier than a big dog. It lived at the same time as the dinosaurs, but it was not one. It caught fish in the seas that covered much of North America.

Flapping is hard work. Moving the wings uses much more energy than holding them still. So a big flier flaps as little as it can. It flaps to go higher or faster. Then it holds its wings still and glides. It sinks slowly, but it uses almost no energy.
Seabirds still do this today. An albatross can cross a whole ocean and hardly flap at all. It rides the wind that rises off the waves. Its wings are long and thin, just like Pteranodon’s were.
A flier that could only flap would get too tired to find food. A flier that could only glide would sink into the sea. It could never get back up. Neither one is any use alone. The animal needs both, and it needs to switch between them.
Some choices are not “do it or do nothing”. Some are always one thing or the other.
Now the Switch gets a second gap for blocks. It checks the question in the six-sided slot. Then just one of the two halves runs. Never both, and never none.
if <([A v] degrees counted) < (1440)> then [A v] set speed to (70) % :: motors write [FLAP] at line (3) :: display else [A v] set speed to (15) % :: motors write [GLIDE] at line (3) :: display end
| if / then | if / then / else | |
|---|---|---|
| Answer is yes | Runs the inside. | Runs the top half. |
| Answer is no | Does nothing at all. | Runs the bottom half. |
| Use it for | Something extra, only sometimes. | Picking one of two ways to act. |
Lesson 6 ended with a beep that would not stop. Once the answer became yes, it stayed yes. So the if ran every time round the loop. An if/else does not have that problem here. Whatever the answer is, just one thing happens each time round. So the machine settles into one way of acting. Actions do not pile up.
This does not mean one block is better. It means you should ask what you really want. Is it an extra thing, only sometimes? Or is it one of two things, always?
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.
If/then adds something. If/then/else chooses something.
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.
Watch which way the arrow points. This lesson uses less than. So the busy part comes first, and the calm part comes at the end. Turn the arrow round, and your pterosaur glides first and flaps later. That is a fine animal too. But it is a different one.
Say this back before you move on: “One of the two always runs.”
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | Picks one of two ways to act, many times a second. It shows which one it picked. |
| One motor — the wings | Moves both wings through the linkage, so they always beat together. The motor also counts how far it has turned. That count is the number the question checks. |
| The wing linkage (not electronic) | Turns the spin into a wingbeat. Like the Hammer Bot’s cam, it is harder to turn at some points than others. So a slow glide does not just sound slower than a fast flap. It sounds different. |
| The Brick screen and speaker | Tell you which half is running. When a machine makes choices, seeing the choice helps you find most problems. |
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 |
|---|---|---|
| Wing motor | A | One job motor. Its port is in four places: the start block, both speed blocks and the question. All four must match. |
| Sensors | none | The pterosaur decides by counting its own wingbeats. It does not sense anything around it. |
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 if you can. A cable near flapping wings gets caught. A caught cable stops the motor halfway through.
Make one change each run. Watch the word on the screen. It tells you which half is running. Then you do not have to guess from the wings.
Stop and think about step 5. Turning the arrow round does the same thing as swapping the halves. So there is more than one right way to write the same choice. Pick the one that sounds most like what you would say out loud.
An empty else is not the same as no else. But from the outside, they look the same. That is why it is worth knowing.
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.

Take off with hard flapping. Then switch to a glide. Show on the screen which one it is doing the whole time.
when program starts :: events hat
clear display :: display
[A v] reset degrees counted :: motors
write [PTEROSAUR] at line (1) :: display
[A v] start motor at (70) % speed :: motors
repeat (30)
if <([A v] degrees counted) < (1440)> then
[A v] set speed to (70) % :: motors
write [FLAP ] at line (3) :: display
else
[A v] set speed to (15) % :: motors
write [GLIDE] at line (3) :: display
end
wait (0.2) seconds
end
[A v] stop motor :: motors
write [LANDED] at line (5) :: displayWhat success looks like: fast, noisy flapping for the first few seconds, with FLAP on the screen. Then a clear change to a slow, heavy beat, with GLIDE on the screen. It should change once and stay that way.
Does it flick between FLAP and GLIDE? Then the count is stuck right next to your threshold. Most likely the wings are stuck, and the count is hardly moving. Look at the model, not the program.
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 flight with a clear take-off and a clear glide. Make the screen say which one is happening. Someone across the room should be able to tell you when it switched. Do not tell them what to look for.
Fly a whole trip. Flap up, glide, then flap again to land. That is two changes, not one. So one Switch will not be enough. Say what you used, and why.
Write the same choice in two different ways. First use less-than, with the branches one way round. Then use greater-than, with the branches swapped. Both must make the same flight. Then say which one you would keep, and why. The answer is about which is easier to read, not which runs better.
Design a flight for an animal that has to save its energy. Your pterosaur is flying over water. It cannot flap the whole way. It only has so much flapping in it. For the rest of the trip, it has to glide. First, write the rule as one sentence, before any blocks. What makes it flap? What makes it glide? How does it know? Write the sentence down. You will be marked on whether the machine does what your sentence says. Then build it and fly it. Time the whole flight. Roughly how much of it was flapping? When you show it, answer two questions. What part of the flight was flapping? Could you cut it down more without the animal sinking? And your pterosaur decides by counting its own wingbeats. It has no idea where the water ends. What would you add so it flapped because it needed to, not because the count said so?