The Rafflesia: a huge, fleshy flower whose petals open and close on a single Medium Motor, with an Ultrasonic Sensor in the middle of the bloom watching for anything that comes close.
Every model you have programmed so far was told how far to move. This one is told where to end up, and left to work out the moving for itself — which means it can be pushed, held, or interfered with, and it will still get there.
By the end of the lesson your flower will hold its petals at an opening that tracks your hand — closer means wider — and it will keep correcting for as long as the program runs.
In the real world 5 min
Where you have seen it
Rafflesia arnoldii grows in the rainforests of Sumatra and Borneo and produces the largest single flower on Earth — up to a metre across and around ten kilograms. It has no leaves, no stem and no roots. It lives inside a vine, and for most of its life it is nothing but threads within its host.
It smells of rotting meat, which is not an accident: it is advertising to carrion flies. The bloom lasts about five days, after up to nine months of the bud swelling. Everything about the plant is a long, slow adjustment towards one short event.
Why it is built that way
Plants do not follow a schedule; they follow feedback. A stem grows towards light because the shaded side elongates faster — a continuous measure and correct that runs for the plant’s whole life. A flower opens when temperature and moisture say so, not on a fixed date.
That is the difference between a schedule and a feedback loop. A schedule says “open on the twelfth of March”. Feedback says “keep checking, and adjust towards where you should be”. Only one of those survives a cold spring.
What would go wrong without it
A machine driven by a schedule works only if the world matches the schedule. A thermostat that ran the heating for a fixed forty minutes would overheat the house on a mild day. A cruise control that held a fixed throttle would crawl up hills and race down them. Both work by measuring the gap and acting on it.
Do not tell a machine how far to move. Tell it where to be, and let it keep checking.
The main concept — the closed loop 6 min
Everything you have written so far has been open loop: the program gives an instruction and never finds out whether it worked. A closed loop checks, every time round, and uses the difference to decide what to do next.
Open loop (Levels 1–2)
Closed loop (today)
The instruction
“Run 180 degrees.”
“Be at 180 degrees.”
If something blocks it
It fails and never knows.
It keeps pushing, because the gap is still there.
If the target moves
Nothing. The instruction is already given.
It follows, because the gap changed.
When it finishes
When the movement is done.
It does not finish. It keeps correcting.
The three steps, and the one line that matters
Measure — read where you actually are.
Compare — work out the error: error = target − measured.
Correct — move in proportion to the error, then go round again.
The error carries two pieces of information at once. Its sign says which way to move — positive means one way, negative the other — and its size says how hard. You never need an if to choose a direction: the arithmetic already knows.
when program starts :: events hat
[A v] reset degrees counted :: motors
forever
set [target v] to ((60) - ([4 v] distance in cm)) :: variables
set [error v] to ((target) - ([A v] degrees counted)) :: variables
[A v] start motor at ((error) * (0.5)) % speed :: motors
end
Four lines and no if anywhere. Hand closer → target bigger → error positive → petals open. Hand away → error negative → motor reverses on its own.
Why multiply by a number smaller than one
That 0.5 is the gain — how strongly the machine reacts to being wrong. Too small and it creeps towards the target and never quite arrives. Too large and it overshoots, corrects too hard the other way, and shakes.
Finding the gain is a practical job, not a calculation. You start low, raise it until the machine starts to wobble, then come back down. Every real control system in the world is tuned this way.
ComponentData6 min
Variables
Why anybody needs one
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.
Abby never remembers the numberBen never sees a henThe wall holds it for both
Abby has a gate and a wall. Before a single hen comes through she chalks 0 on the wall — that is where the number is going to live.A hen goes through. Abby rubs out the 0 and chalks 1. Another goes through, and she does it again.Three hens have been through, and the wall says 3. Abby is not remembering the number — she is reading her own wall each time and writing the next one.Ben has been at the market all morning. He has not seen one hen. He walks up, reads the wall, and knows the answer — without asking Abby anything.That is a variable. Not a number in somebody's head, but a place both of them agreed on: one writes to it, the other reads from it, and it keeps the number in between.Finished. Abby wrote, Ben read, and the wall is what joined them up.
the wall holds it
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.
The paper, and the two things you can do to it
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.
score
0
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.
change leaves a trail — every value follows from the one before it. This is what counting is.
set wipes the sheet. Use it to start a count, never to continue one.
Press set score to 0 after counting up a few times and watch the whole history vanish. That is what happens to a count when a set block ends up in the wrong place — and it is the commonest variable bug there is.
Blocks reference
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, or change?
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
when program starts
set count to 0
repeat 4
A run clockwise for 1rotations
change count by 1
set inside it
repeat 4
set count to 0
A run clockwise for 1rotations
change count by 1
Before the loop: counted 0Inside the loop: stuck at 0
Both programs count the turns of a motor. The left sets the count to zero before the loop; the right sets it inside.Turn 1. Both counters read 1, and so far the two programs agree.Turn 2. The left count is 2. The right was set back to zero at the top of the loop, so it is 1 again.Turn 3. The left reads 3. The right still reads 1.Turn 4. The motor turned four times on both robots — only one of them counted them.Finished. Four turns, and one of the two counts is fiction.
stopped
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.
Anything oval is a number you can pick up
EV3 Classroom tells you what a block does by its shape, and once you have noticed that, a whole set of questions answers itself:
Oval — reports a number. The blue degrees counted, the timer, a distance, your own variable.
Pointed — reports true or false. These go in an if or a wait until, not in a variable.
Block-shaped — does something. These stack up; they do not fit inside anything.
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
set degree_turn to A degrees countedkeep it in a variable of your own
A degrees counted+10do arithmetic with it
A degrees counted>50compare it with a number
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.
Reset at the start, every time
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.
Why it matters
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.
ComponentControl5 min
Comparing and combining
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.
Blocks reference
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.
Try it: which way round does it go?
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.
-3 < 4true
is x to the LEFT of it?
< is true while x sits on the left. Slide x past the marker and it flips.
> is the same question the other way round — so exactly one of the two is true, unless the markers are on the same spot.
= is true for one single position out of twenty-one. Try landing on it. That is why a sensor is almost never compared with =: a reading passes straight through the exact number without ever being measured there.
not flips the answer, whatever it was. not (x < 4) covers everything x < 4 does not — including landing exactly on 4.
Try it: which numbers make it true?
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.
x < 0.2x < 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:
Hollow ○ — the boundary is not included. x < 0.2 shades everything left of 0.2 but leaves 0.2 itself out, because 0.2 is not less than 0.2.
Filled ● — the boundary is included. Choose = and nothing is shaded at all: one single number qualifies.
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.
Try it: and, or, not
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: trueandbumper: falsefalse
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.
and is true on one row out of four. It narrows — the robot acts less often, but more certainly.
or is true on three rows out of four. It widens — the robot acts more readily.
The two agree on the top and bottom rows and disagree in the middle. Whenever swapping one for the other seems to make no difference, you have only tried the rows where they agree.
Watch them decide
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.
when program starts
forever
if distance < 15 and is pressed? then
stop moving
if distance < 15 or is pressed? then
play beep 60 for 0.2 seconds
Nothing is within 15 cm and the bumper is out. Both conditions are false.Something comes close. The comparison flips to true — the bumper has not been touched.It backs away, and instead the bumper is pressed. Now the other condition is the true one.Close AND pressed. Only now is «and» true — while «or» has been true ever since the first of them was.Finished. Four situations, and the two operators disagreed in three of them.
and false · or false
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.
Choosing the threshold
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.
Combining two conditions
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.
ComponentSensing6 min
The Ultrasonic Sensor
The Ultrasonic Sensor measures distance. It sends out a burst of sound too high for people to hear, listens for the echo, and works out how far away the surface is from how long the echo took — exactly how a bat finds a moth, and how a submarine uses sonar.
front
side
The two round openings on the front are the point of this sensor: one sends the burst of sound out, the other listens for the echo coming back.
Blocks reference
Block
What it does
([4 v] distance in [cm v] :: sensors)
Reports how far away the nearest thing in front of the sensor is, as a number in centimetres.
wait until <([4 v] distance in [cm v] :: sensors) < (15)>
Holds the program until something comes closer than 15 cm.
A number, not a yes or no
This is the important step up from the Touch Sensor. Touch gives you true or false; the Ultrasonic gives you a number, and the deciding is left to you. Pick a threshold below and watch where the robot ends up.
when program starts
start moving straight: 0
4 wait until distance <15cm
stop moving
60cm · reading15cm · threshold
Nothing is close. The sensor reports about 60 cm and the program waits.The robot drives forward. The sensor is sending a burst of sound and timing its echo, over and over, and the number falls.The reading has dropped past the threshold. The condition is true, so the robot stops.Try another threshold. The program is identical — only that one number is different.Finished. The threshold is yours to choose — the sensor only supplies the number.
stopped
The black line on the bar is the threshold; the blue fill is the reading. The robot stops the instant the fill crosses the line.
Three different robots, and only one number is different between them. That is what having a number rather than a yes-or-no buys you: the behaviour is tuned by editing one slot, not by rebuilding the program. It also means the sensor can never tell you it is “close” — close is a decision you make about a reading.
Why it matters
Car parking sensors, automatic doors at a shopping centre, and the sensor that stops a lift door closing on somebody all work this way. Reacting before contact is what makes a machine feel safe.
If your set has an Infrared Sensor instead
The Home/Retail EV3 set (31313) ships an Infrared Sensor and a Beacon in place of the Ultrasonic and Gyro sensors. The Infrared Sensor also measures distance, so the programs in this module work with it — but it reports a rough 0–100 proximity rather than real centimetres, and it is affected by sunlight and by dark surfaces in ways the Ultrasonic is not.
IR Sensor
Beacon
The Infrared Sensor and its Beacon, from the Home set. If your kit has these, expect proximity numbers rather than centimetres — and retune any threshold accordingly.
Measure. Subtract. Act in proportion. Repeat for ever — that is a closed loop, and it is the idea the rest of Level 3 is built on.
▶Proportional responseFrom Level 2, Lesson 43 — reacting in proportion to how wrong you are. Today it goes in a loop and never stops.Show meHide
ComponentControl5 min
Comparing and combining
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.
Blocks reference
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.
Try it: which way round does it go?
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.
-3 < 4true
is x to the LEFT of it?
< is true while x sits on the left. Slide x past the marker and it flips.
> is the same question the other way round — so exactly one of the two is true, unless the markers are on the same spot.
= is true for one single position out of twenty-one. Try landing on it. That is why a sensor is almost never compared with =: a reading passes straight through the exact number without ever being measured there.
not flips the answer, whatever it was. not (x < 4) covers everything x < 4 does not — including landing exactly on 4.
Try it: which numbers make it true?
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.
x < 0.2x < 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:
Hollow ○ — the boundary is not included. x < 0.2 shades everything left of 0.2 but leaves 0.2 itself out, because 0.2 is not less than 0.2.
Filled ● — the boundary is included. Choose = and nothing is shaded at all: one single number qualifies.
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.
Try it: and, or, not
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: trueandbumper: falsefalse
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.
and is true on one row out of four. It narrows — the robot acts less often, but more certainly.
or is true on three rows out of four. It widens — the robot acts more readily.
The two agree on the top and bottom rows and disagree in the middle. Whenever swapping one for the other seems to make no difference, you have only tried the rows where they agree.
Watch them decide
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.
when program starts
forever
if distance < 15 and is pressed? then
stop moving
if distance < 15 or is pressed? then
play beep 60 for 0.2 seconds
Nothing is within 15 cm and the bumper is out. Both conditions are false.Something comes close. The comparison flips to true — the bumper has not been touched.It backs away, and instead the bumper is pressed. Now the other condition is the true one.Close AND pressed. Only now is «and» true — while «or» has been true ever since the first of them was.Finished. Four situations, and the two operators disagreed in three of them.
and false · or false
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.
Choosing the threshold
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.
Combining two conditions
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.
Say this back before moving on: “Where should I be, where am I, how big is the gap?”
What’s in this build 4 min
Open and close the petals by hand and count how far the motor turns between shut and fully open. You need that number before you can give the loop a target.
Part
What it is doing here
EV3 Intelligent Brick
The base of the flower. Today its screen is an instrument — you will watch the error on it while the loop runs.
Medium Motor — the petals
Drives all the petals through one linkage. Its own rotation counter is the measured half of the loop — the flower knows how open it is because the motor remembers.
Ultrasonic Sensor — in the bloom
Watches for a visitor. It supplies the target: nearer hand, wider flower.
Touch Sensor — the reset
Re-zeroes the petal count when the flower is fully shut. Without it, every restart guesses where “closed” is.
The petal linkage (not electronic)
Must move freely in both directions. A linkage that sticks makes the loop push harder and harder against nothing — you will hear the motor straining, and that is the loop doing its job on a broken machine.
A closed loop will fight you, and that is the point. Hold a petal shut while the program wants it open and the motor pushes harder the longer you hold. Let go gently — do not fight it back, and do not hold it for more than a second or two.
Ports — and the rule 4 min
Sensors go in ports 1, 2, 3, 4. Motors go in ports A, B, C, D. They are not interchangeable, and nothing will tell you politely if you swap them.
Part
Port
Why this one
Petals (Medium)
A
The only motor, and the one whose degrees counter is half of the loop.
Visitor sensor (Ultrasonic)
4
Ultrasonic stays on 4 across the course.
Reset (Touch)
1
Touch stays on 1 across the course.
Check your own build now:
Petals in A, Ultrasonic in 4, Touch in 1.
Close the petals fully before every run. The program zeroes the counter at the start and measures everything from there.
Check the Ultrasonic Sensor faces up and out of the bloom, not into a petal. A sensor looking at its own flower reads a few centimetres for ever.
Turn the petal linkage through its whole range and confirm nothing binds at either end.
Connect the Brick 4 min
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.
▶How to connect the BrickUSB and Bluetooth, step by step, with a photograph of every screen. Open it if you have not done this before — or if pairing is not working.Show meHide
USB — the reliable one
Switch the Brick on with the dark grey centre button.
Cable into the Brick’s PC port — the small square socket beside the numbered ports, not one of the numbered ones.
Other end into the computer.
Bluetooth — name it first
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.
Name your Brick. On the Brick: Settings (the spanner) → Brick Name. Type something nobody else will pick, then press the tick. Every Brick is called EV3 until somebody changes it.
Turn Bluetooth on. Settings → Bluetooth. Tick Bluetooth and Visibility. Leave iPhone/iPad/iPod unticked.
Connect from EV3 Classroom. Click the Brick icon at the top of the programming area, find your Brick by name, and click Connect.
Say yes on the Brick. It asks “Connect?” with the computer’s name — choose the tick, then accept the passkey, which is already 1234.
Where to read it. The name sits in the bar across the very top of the screen, on every screen — so you can check which Brick you are holding at any moment without going into a menu. This one is EV3VE. A Brick nobody has renamed says EV3.Step 3, and the reason step 1 exists. Three Bricks in range — read the name before you click Connect. Pairing with the wrong one is not an error: it works perfectly, on somebody else’s robot.
Step 2.Bluetooth switches the radio on; Visibility is what lets the computer find you. With Visibility off your Brick works perfectly and simply never appears in the list.Step 4. Look at the Brick. It asks whether to accept and names the computer. Choose the tick.Then the passkey, already 1234. Press the tick again and you are connected.
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.
USB is fine and probably better. The flower does not go anywhere, and you will be adjusting one number — the gain — over and over, downloading each time. Anything that shortens that cycle is worth having.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
One motor tile — A.
Two sensor tiles — 1 (Touch) and 4 (Ultrasonic).
Close the petals, then open them fully by hand and read tile A. Write the number down — it is the widest target your loop should ever be given, and challenge 2 asks you to enforce it.
Stuck? The long version, with a photograph of every screen, is in the Brick & Bluetooth guide.
Make it move 10 min
Build it in two goes: a loop with a fixed target first, so you can see it hold a position, then let the sensor move the target.
Step 1 — hold one position
when program starts :: events hat
[A v] reset degrees counted :: motors
set [target v] to (120) :: variables
forever
set [error v] to ((target) - ([A v] degrees counted)) :: variables
[A v] start motor at ((error) * (0.5)) % speed :: motors
write (error) at line (3) :: display
end
The petals open to 120 and stay there. Push them and they push back — because the error came back and the loop acted on it.
Try this before going on. Push a petal gently closed and watch line 3: the error grows, the motor works harder, and when you let go it returns. That is the whole idea, and it is worth thirty seconds of playing with.
Step 2 — let the visitor set the target
when program starts :: events hat
wait until <[1 v] is pressed? :: sensors>
[A v] reset degrees counted :: motors
clear display :: display
forever
set [target v] to (((60) - ([4 v] distance in cm)) * (4)) :: variables
set [error v] to ((target) - ([A v] degrees counted)) :: variables
[A v] start motor at ((error) * (0.5)) % speed :: motors
write (target) at line (2) :: display
write (error) at line (4) :: display
end
Hand at 60 cm → target 0, shut. Hand at 15 cm → target 180, wide open. Move your hand slowly and the flower follows.
The Touch Sensor sets the zero. Shut the petals, press, and the flower now knows what closed means. Skip this and every run starts from a different idea of zero.
60 − distance flips the sensor round. Ultrasonic gives a bigger number when things are further away, and you want the opposite, so subtract it from a constant.
The × 4 converts centimetres into petal degrees. Your model’s number may differ — use the full-open figure you wrote down in step 8.
Nothing here decides a direction. Read the program again and satisfy yourself there is no if in it. The sign of the error is doing that work.
What success looks like: move your hand towards the bloom and the petals open smoothly; take it away and they close. Hold still and they hold still, with the error hovering near zero.
If the petals slam open and shut and buzz, the gain is too high — drop 0.5 to 0.2. If they drift open lazily and never arrive, it is too low — try 0.8. If they run the wrong way entirely, swap the two terms in the subtraction.
Change it and test 8 min
One change at a time. Predict, then run, then look. Today you are tuning a control loop, which is a real engineering skill and is done exactly like this.
Gain 0.1. Predict first. The flower should move sluggishly and settle short of its target — too weak to close the last of the gap.
Gain 2.0. Predict first. It should overshoot and oscillate. Listen to the motor: the buzzing is the loop correcting faster than the petals can respond.
Find your own best gain. Raise it until it just starts to wobble, then take it back down about a third. Write the number on the board — every group’s will differ slightly, and that is the honest result.
Hold the petals shut for three seconds while it runs. Watch the error on screen grow. This is a closed loop refusing to give up — and it is why real systems need a limit on how hard they may push.
Break the loop on purpose. Move reset degrees counted inside the forever. The measured value is now always zero, so the error never shrinks and the flower runs away. A loop that cannot measure is not a loop.
Too little gain never arrives. Too much never settles. Tuning is finding the edge and stepping back from it.
Where this goes 3 min
You have just written the most important four lines in Level 3. Every self-correcting machine — a thermostat, a drone holding altitude, a line follower, a self-balancing robot — is this loop with more terms added.
Two problems are already visible if you watched carefully:
It never fully settles. Even tuned well, the petals twitch around the target rather than stopping dead. Lesson 10 fixes that with a deadband.
Your numbers are not the next group’s numbers. The × 4 and the gain were found for this flower, in this room. Lesson 12 turns that from guesswork into calibration.
Before either of those, the next lesson asks a different question: what if the machine has to react to more than one condition at once, and treat some combinations differently from others? That is boolean logic, and it is a drum kit.
Open loop says what to do. Closed loop says where to be. Only one of them survives contact with the world.
This is what you are building: the EV3 Flower Rafflesia.
Challenges & mission 27 min
Work through the challenges in order — each is harder than the last. The mission comes after all three, and it is meant to make you plan before you build.
Challenge 1
Tune it properly and write the number down.
Find the gain that makes your flower follow a moving hand quickly without buzzing. Start at 0.2 and work up.
Compare with another group. If your numbers differ, that is the right answer — the machines differ. Say what would have to change for your gain to work on their flower.
Challenge 2
Stop it hurting itself.
Right now a big error commands a big speed, and the petals will drive hard into their end stops.
Limit the target so it can never ask for more than the fully-open figure you measured, and never less than zero. The loop should still correct — it just may not be asked for the impossible.
Challenge 3
Make it breathe.
With no hand present, the flower should slowly open and close on its own, about once every four seconds, as if breathing. The moment a hand comes within 30 cm it must switch to following the hand instead.
The breathing is a moving target, not a different program — you are changing what the target is, not how the loop works.
Mission
Build a flower that behaves as if it were alive.
It must respond to a visitor in a way that is convincing rather than mechanical, using nothing but a target that changes and a loop that chases it. Ideas worth trying: opening faster than it closes, hesitating before it commits, opening further for something that stays than for something passing.
Two rules:
1. There is ONE closed loop in your program, and it never changes. All your behaviour comes from changing the target.
2. Nobody watching should be able to guess where the numbers came from.
Before you build, write down in one sentence what you want a visitor to feel. Then work out what the target has to do to produce it. This is the first time in the course the interesting question is not "does it work" but "does it convince".
Build it 15 min
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.
Use the viewer's own controls to zoom and turn pages. Fullscreen makes it big enough to build from.
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.