The EV3 Flower: petals on a Medium Motor and a Colour Sensor looking upward, reading how much light is falling on the bloom.
It opens in the light and closes in the dark — which sounds like a two-line program until you carry it to the next room and it never opens again, because “light” there is a different number.
By the end of the lesson your flower will work out its own threshold every time you start it — and will work first time in a room it has never been in.
In the real world 5 min
Where you have seen it
A great many flowers open and close on a daily cycle — nyctinasty. Crocuses and tulips respond mainly to temperature; daisies, whose name comes from “day’s eye”, respond to light. The advantage is straightforward: an open flower at night is exposed to cold and damp and there are no pollinators to reward it.
Leucanthemum vulgare 'Filigran' Flower 2200px. Photo: Photo by and (c)2008 Derek Ramsey (Ram-Man). Co-attribution must be gi / Wikimedia Commons (CC BY-SA 3.0).
The plant does not have a lux meter and a lookup table. It responds to change relative to what it has been experiencing — which is why a daisy in a bright greenhouse and a daisy in a shaded garden both still open in the morning and close at dusk.
Why it is built that way
Because absolute thresholds do not survive a change of conditions. A camera that assumed one fixed brightness would be useless indoors; instead it meters the scene and sets its exposure from what it finds. Your eyes do the same over about half an hour when you walk into a dark room.
The clever part is not the sensor. It is measuring the conditions first and deciding the thresholds afterwards.
What would go wrong without it
Every number you have typed in this course so far is an absolute threshold: 15 cm for the chicken, 25 cm for the bridge car, a gain of 3 for the helicopter. All were found by trying, in one room, on one afternoon, with one battery. They are guesses that happen to be right where they were made.
A machine that measures its world before deciding works in rooms nobody tested it in.
The main concept — calibration 6 min
Calibration is a short routine at the start of a run in which the machine samples the extremes it will actually face, and computes its thresholds from what it measured.
The typed threshold, and why it fails
forever
if <([3 v] reflected light intensity) > (40)> then
[A v] run [clockwise v] for (90) [degrees v] at (30) % speed :: motors
end
end
Works beautifully in the room where 40 was found. In a brighter room the value never drops below 40 and the flower never closes; in a darker one it never rises and the flower never opens.
The calibrated threshold
when program starts :: events hat
write [SHOW ME BRIGHT] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [bright v] to ([3 v] reflected light intensity) :: variables
wait until <not <[1 v] is pressed? :: sensors>> :: control
write [NOW COVER IT] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [dark v] to ([3 v] reflected light intensity) :: variables
wait until <not <[1 v] is pressed? :: sensors>> :: control
set [threshold v] to (((bright) + (dark)) / (2)) :: variables
write (threshold) at line (3) :: display
Two samples and one division. The number is now a fact about this room, today, and the same program produces a different — and correct — threshold everywhere.
The midpoint rule: threshold = (bright + dark) / 2. It puts the decision line as far from both extremes as possible, so noise in either direction has the furthest to travel before it crosses. It is the most reusable formula in robotics, and every line follower you write in Level 4 starts with it.
Calibrate the extremes you will actually meet
Sample the real thing, not something convenient. If the flower will sit under classroom lighting, calibrate under classroom lighting — not by holding it up to a window. A calibration taken in conditions the machine never sees is worse than no calibration, because now the wrong number carries authority.
Typed number
Calibrated number
Where it came from
A person, once, somewhere.
The machine, now, here.
New room
Probably wrong, silently.
Re-measured on the spot.
Costs
Nothing.
Ten seconds at the start of every run.
Fails when
Anything changes.
You calibrate against the wrong extremes.
ComponentSensing6 min
The Colour Sensor
The Colour Sensor looks down at a surface and can answer three quite different questions: what colour is this?, how bright is this? and how light is the room? Choosing the wrong one is the usual reason a line-following robot refuses to work.
front
side
The sensor has its own lamp beside its detector. That is why it must sit close to the surface and at a steady height — lifting it changes the reading even though the surface has not changed.
Blocks reference
Block
What it does
([3 v] color :: sensors)
Reports which colour it sees, from a short list — red, blue, green, black, white and a few more.
([3 v] reflected light intensity :: sensors)
Reports how bright the surface is, as a number from 0 (black) to 100 (white).
<[3 v] is color [red v]? :: sensors>
Reports true or false for one particular colour.
([3 v] ambient light intensity :: sensors)
Reports how much light is falling on the sensor, 0 to 100, with its own lamp switched off.
Which colour, exactly?
The sensor does not describe a colour — it picks one from a list of eight, and that list is the whole of what it can ever say:
Reports
Means
0
no colour — too far away, or too dark to call
1 · 2 · 3
black, blue, green
4 · 5 · 6
yellow, red, white
7
brown
Anything you put under it is forced into one of those eight. There is no orange and no purple: an orange brick comes back as red or as yellow, and often as red one moment and yellow the next as the robot creeps along. Light blue and grey are the other classic pair to avoid — grey is neither black nor white, so it flips between them.
This is why colour mode is a good fit for a task you control and a bad fit for one you do not. Sorting the LEGO bricks that come in the set works, because they are made in exactly these colours. Reading a printed sheet, a coloured tile from another set, or anything pastel is asking the sensor to answer a question it does not have a word for.
Two practical points follow from how it decides. It shines its own lamp and looks at how much red, green and blue comes back, so it must be close — about half a centimetre, and no more than a centimetre. Lift it and the answer decays to 0. And because it takes those three readings before it can answer, colour mode is the slowest thing this sensor does; a robot driving quickly can pass right over a small patch without ever reporting it.
When a colour must be recognised reliably, test it. Drive the robot slowly over the real surface with color shown on the screen and watch what it actually says — including what it says at the edges between two colours, which is where the wrong answers live.
Colour, or brightness?
Both questions are asked of the same surface at the same moment. Watch the two answers travel across a strip of colours and then over the edge of a black line.
when program starts
forever
write 3 color at line 1
write 3 reflected light intensity at line 3
colour: 2 possible answers herereflected light: every value from 88 down to 8
The sensor sits a few millimetres above the surface, with its own lamp shining down.It travels across the coloured patches. One read-out names what it sees; the other says how much light came back.Now the edge of a black line. The name only ever says white or black — but the number slides all the way down, and every value in between means something.Names for sorting. Numbers for following.Finished. Same sensor, same surface, two very different kinds of answer.
reflected light 88
Watch the two read-outs over the last third of the strip. One of them changes once. The other changes the whole way across.
Over the patches, both read-outs are useful. Over the edge of the line they part company: the colour name has only two answers to give and jumps between them, while the number slides smoothly from 88 down to 8. Every value in that slide tells you how far onto the line the sensor is — which is information the name simply does not carry.
Use colour when the answer really is a name — sorting red bricks from blue ones, stopping on a green square.
Use reflected light when the answer is a matter of degree — following the edge of a black line, where the useful readings are all the greys between black and white.
A line follower built on colour names only knows “black” or “not black”, so it can only lurch. Built on reflected light it can tell how far onto the line it has drifted, which is what makes smooth following possible.
The third mode: ambient light
The first two modes both switch the sensor’s own lamp on and measure what bounces back off the surface. Ambient light intensity does the opposite: the lamp goes off, and the sensor simply reports how much light is arriving from wherever — 0 in the dark, up to 100 in bright light.
Mode
Own lamp
Measures
Points
colour
on
which of eight colours the surface is
at the surface, very close
reflected light
on
how much of its own light comes back
at the surface, very close
ambient light
off
how bright the surroundings are
wherever you want to measure
That makes it the only one of the three that is not really about the floor. A number between 0 and 100 means very little on its own, so watch the same sensor sit through five different rooms — nothing underneath it changes at any point.
the sensor’s own lamp is off — it is measuring the room
Start in the dark — a hand over the lens, or the lights off. Almost no light reaches the sensor, and it reports 0.Curtains drawn with one small lamp on. Enough to see by, and the sensor climbs to about 12.An ordinary classroom with the lights on sits somewhere around 38 — the middle of the scale, not the top of it.Move it beside a bright window and the same sensor, in the same room, reads about 72.A torch pointed straight into it pushes the reading to nearly 100 — which is how a light can be used as a signal to a robot.Finished. Same sensor, same floor underneath it — the only thing that changed was the room.
ambient 0
Nothing under the sensor changed at any point in this run. Ambient light is the one mode that is not asking about the surface at all.
Those are the shape of the scale rather than exact figures, but the shape is the useful part: a lit room is nowhere near 100, and the top of the range is reserved for a light pointed straight at the sensor. Cover it with your hand and the number drops to near zero — which is the easiest way to check the sensor is doing what you think.
Point it at the ceiling and it tells you whether the room lights are on; point it forwards and a torch will spike the reading, which is a way of signalling to a robot without touching it.
Do not reach for it as a substitute for reflected light. Room light falling on a black line and on white paper is almost the same, so ambient mode can barely tell them apart — the reason reflected light works is precisely that the sensor brings its own light and measures how much of it survives.
It is also the mode most at the mercy of the room. A reading taken by a window in the morning will not match the same spot in the afternoon, so anything built on ambient light needs measuring on the day, in the place, with the lights as they will be.
Light and height matter
Even the two lamp-on modes are affected by room lighting — a reading taken by a sunny window differs from one taken in a corner. The sensor must also sit close to the surface and at a constant height, because lifting it changes the reading even though the surface has not changed.
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.
Measure the extremes, take the midpoint, decide from that. Ten seconds at the start buys a machine that travels.
▶The Colour SensorReflected light intensity versus colour mode, and why the sensor's own lamp matters.Show meHide
ComponentSensing6 min
The Colour Sensor
The Colour Sensor looks down at a surface and can answer three quite different questions: what colour is this?, how bright is this? and how light is the room? Choosing the wrong one is the usual reason a line-following robot refuses to work.
front
side
The sensor has its own lamp beside its detector. That is why it must sit close to the surface and at a steady height — lifting it changes the reading even though the surface has not changed.
Blocks reference
Block
What it does
([3 v] color :: sensors)
Reports which colour it sees, from a short list — red, blue, green, black, white and a few more.
([3 v] reflected light intensity :: sensors)
Reports how bright the surface is, as a number from 0 (black) to 100 (white).
<[3 v] is color [red v]? :: sensors>
Reports true or false for one particular colour.
([3 v] ambient light intensity :: sensors)
Reports how much light is falling on the sensor, 0 to 100, with its own lamp switched off.
Which colour, exactly?
The sensor does not describe a colour — it picks one from a list of eight, and that list is the whole of what it can ever say:
Reports
Means
0
no colour — too far away, or too dark to call
1 · 2 · 3
black, blue, green
4 · 5 · 6
yellow, red, white
7
brown
Anything you put under it is forced into one of those eight. There is no orange and no purple: an orange brick comes back as red or as yellow, and often as red one moment and yellow the next as the robot creeps along. Light blue and grey are the other classic pair to avoid — grey is neither black nor white, so it flips between them.
This is why colour mode is a good fit for a task you control and a bad fit for one you do not. Sorting the LEGO bricks that come in the set works, because they are made in exactly these colours. Reading a printed sheet, a coloured tile from another set, or anything pastel is asking the sensor to answer a question it does not have a word for.
Two practical points follow from how it decides. It shines its own lamp and looks at how much red, green and blue comes back, so it must be close — about half a centimetre, and no more than a centimetre. Lift it and the answer decays to 0. And because it takes those three readings before it can answer, colour mode is the slowest thing this sensor does; a robot driving quickly can pass right over a small patch without ever reporting it.
When a colour must be recognised reliably, test it. Drive the robot slowly over the real surface with color shown on the screen and watch what it actually says — including what it says at the edges between two colours, which is where the wrong answers live.
Colour, or brightness?
Both questions are asked of the same surface at the same moment. Watch the two answers travel across a strip of colours and then over the edge of a black line.
when program starts
forever
write 3 color at line 1
write 3 reflected light intensity at line 3
colour: 2 possible answers herereflected light: every value from 88 down to 8
The sensor sits a few millimetres above the surface, with its own lamp shining down.It travels across the coloured patches. One read-out names what it sees; the other says how much light came back.Now the edge of a black line. The name only ever says white or black — but the number slides all the way down, and every value in between means something.Names for sorting. Numbers for following.Finished. Same sensor, same surface, two very different kinds of answer.
reflected light 88
Watch the two read-outs over the last third of the strip. One of them changes once. The other changes the whole way across.
Over the patches, both read-outs are useful. Over the edge of the line they part company: the colour name has only two answers to give and jumps between them, while the number slides smoothly from 88 down to 8. Every value in that slide tells you how far onto the line the sensor is — which is information the name simply does not carry.
Use colour when the answer really is a name — sorting red bricks from blue ones, stopping on a green square.
Use reflected light when the answer is a matter of degree — following the edge of a black line, where the useful readings are all the greys between black and white.
A line follower built on colour names only knows “black” or “not black”, so it can only lurch. Built on reflected light it can tell how far onto the line it has drifted, which is what makes smooth following possible.
The third mode: ambient light
The first two modes both switch the sensor’s own lamp on and measure what bounces back off the surface. Ambient light intensity does the opposite: the lamp goes off, and the sensor simply reports how much light is arriving from wherever — 0 in the dark, up to 100 in bright light.
Mode
Own lamp
Measures
Points
colour
on
which of eight colours the surface is
at the surface, very close
reflected light
on
how much of its own light comes back
at the surface, very close
ambient light
off
how bright the surroundings are
wherever you want to measure
That makes it the only one of the three that is not really about the floor. A number between 0 and 100 means very little on its own, so watch the same sensor sit through five different rooms — nothing underneath it changes at any point.
the sensor’s own lamp is off — it is measuring the room
Start in the dark — a hand over the lens, or the lights off. Almost no light reaches the sensor, and it reports 0.Curtains drawn with one small lamp on. Enough to see by, and the sensor climbs to about 12.An ordinary classroom with the lights on sits somewhere around 38 — the middle of the scale, not the top of it.Move it beside a bright window and the same sensor, in the same room, reads about 72.A torch pointed straight into it pushes the reading to nearly 100 — which is how a light can be used as a signal to a robot.Finished. Same sensor, same floor underneath it — the only thing that changed was the room.
ambient 0
Nothing under the sensor changed at any point in this run. Ambient light is the one mode that is not asking about the surface at all.
Those are the shape of the scale rather than exact figures, but the shape is the useful part: a lit room is nowhere near 100, and the top of the range is reserved for a light pointed straight at the sensor. Cover it with your hand and the number drops to near zero — which is the easiest way to check the sensor is doing what you think.
Point it at the ceiling and it tells you whether the room lights are on; point it forwards and a torch will spike the reading, which is a way of signalling to a robot without touching it.
Do not reach for it as a substitute for reflected light. Room light falling on a black line and on white paper is almost the same, so ambient mode can barely tell them apart — the reason reflected light works is precisely that the sensor brings its own light and measures how much of it survives.
It is also the mode most at the mercy of the room. A reading taken by a window in the morning will not match the same spot in the afternoon, so anything built on ambient light needs measuring on the day, in the place, with the lights as they will be.
Light and height matter
Even the two lamp-on modes are affected by room lighting — a reading taken by a sunny window differs from one taken in a corner. The sensor must also sit close to the surface and at a constant height, because lifting it changes the reading even though the surface has not changed.
Say this back before moving on: “Brightest, darkest, halfway between.”
What’s in this build 4 min
Three electronic parts. Find the sensor and check which way it is looking — that decides what you can calibrate against.
Part
What it is doing here
EV3 Intelligent Brick
The pot. Today its screen shows the two samples and the threshold, so a class can compare numbers between tables and see how much rooms differ.
Medium Motor — the petals
Opens and closes the bloom through a linkage. Slow speeds suit it: a flower that snaps open looks like a trap, not a flower.
Colour Sensor — facing up
Reads light level. In reflected light mode it lights its own red lamp and measures what bounces back; in ambient light mode the lamp is off and it measures the room. Both work here — pick one and calibrate in the same mode you will use.
Touch Sensor — the calibrate button
Tells the flower “take your sample now”. Two presses at the start of every run, and the machine sets its own numbers.
The petal linkage (not electronic)
Should open and close without forcing. Check both end positions by hand — the program will drive to them repeatedly.
Do not let your own shadow become the calibration. When you cover the sensor for the dark sample, use the same thing you will use later — a hand, a card, a book — and hold it the same distance away. A dark sample taken with the sensor pressed against a table is far darker than any shadow it will meet, which pushes the midpoint too low.
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.
Light level (Colour)
3
Colour stays on 3 across the course.
Calibrate button (Touch)
1
Touch stays on 1 across the course.
Check your own build now:
Petals in A, Colour in 3, Touch in 1.
Check no petal shades the sensor when the flower is open. If it does, opening lowers the reading, which closes it, which raises the reading, which opens it — a flower that flaps for ever.
Close the petals fully before every run.
Read the sensor on the Brick screen right now, with the room as it is. Write the number down. Then walk to another table and read it again — the difference between those two numbers is why this lesson exists.
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.
Either is fine, but do not lean over the flower. Whichever you choose, keep your head and the laptop lid out of the light path while it calibrates — you are part of the room as far as the sensor is concerned.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
One motor tile — A.
Two sensor tiles — 1 (Touch) and 3 (Colour).
Cover and uncover the Colour Sensor and watch tile 3 swing between its two extremes. Note both numbers — the program is about to measure exactly these, and it is worth knowing roughly what to expect.
Stuck? The long version, with a photograph of every screen, is in the Brick & Bluetooth guide.
Make it move 10 min
Calibrate first, then run. The second half never mentions a light value you typed.
when program starts :: events hat
clear display :: display
write [POINT AT LIGHT, PRESS] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [bright v] to ([3 v] reflected light intensity) :: variables
play sound [Mechanical / Blip 1 v] :: sound
wait until <not <[1 v] is pressed? :: sensors>> :: control
write [COVER IT, PRESS] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [dark v] to ([3 v] reflected light intensity) :: variables
play sound [Mechanical / Blip 1 v] :: sound
wait until <not <[1 v] is pressed? :: sensors>> :: control
set [threshold v] to (((bright) + (dark)) / (2)) :: variables
set [band v] to (((bright) - (dark)) / (10)) :: variables
write (threshold) at line (3) :: display
set [open v] to (0) :: variables
forever
set [light v] to ([3 v] reflected light intensity) :: variables
write (light) at line (5) :: display
if <<(light) > ((threshold) + (band))> and <(open) = (0)>> then
[A v] run [clockwise v] for (180) [degrees v] at (25) % speed :: motors
set [open v] to (1) :: variables
end
if <<(light) < ((threshold) - (band))> and <(open) = (1)>> then
[A v] run [counterclockwise v] for (180) [degrees v] at (25) % speed :: motors
set [open v] to (0) :: variables
end
end
Two samples, one threshold, and a band either side of it so the flower cannot flap on the boundary.
No light number is typed anywhere below the calibration. Search the second half for a number and you will find degrees, speeds and state values — but nothing about light.
band is calibrated too. A tenth of the range between bright and dark: in a high-contrast room the band is wide, in a dim one it is narrow. This is Lesson 10’s deadband, measured rather than guessed.
open is a state, from Lesson 7. Without it, a bright reading would re-open an already-open flower every time round the loop, and the motor would grind against its end stop.
The two tests use different thresholds — one above the line, one below — which is Lesson 10’s hysteresis, again from measured numbers.
What success looks like: two presses to calibrate, a threshold on line 3, then a flower that opens when you take your hand away and closes when you shade it — with no flapping at the boundary.
If it never opens, your bright sample was taken in shadow — recalibrate and watch line 3 for a sensible midpoint. If it opens and closes repeatedly on its own, a petal is shading the sensor; check step 6 again.
Change it and test 8 min
One change at a time. Predict, then run, then look.
Calibrate, then move to a different table and run again without recalibrating. Note the threshold on line 3 and whether the flower still behaves. Now recalibrate in place and compare.
Compare thresholds across the class. Write every group’s number on the board. The spread is the honest answer to “why did we not just type 40?”
Calibrate dishonestly on purpose: take the dark sample with the sensor flat against the table. The threshold drops too low and the flower opens in near-darkness. A bad calibration is worse than none because you now trust it.
Set band to 0. Hold your hand at the exact boundary and watch the flower flap. Then restore it — Lessons 10 and 12 doing their jobs together.
Sample five times and average. Replace each single reading with a short loop that takes five and divides by five. Compare the steadiness of the threshold between runs — this is how real calibration is done.
A calibrated machine is honest about not knowing in advance. That is stronger than a confident guess.
Where this half of Level 3 stops 3 min
Twelve lessons ago your programs were long lists of instructions that worked in one room. Look at what you have now.
You can…
From
Give a routine a name, and give the name a slot
Lessons 1–2
Give a moment a name, and decide whether to wait for it
Lessons 3–4
Correct continuously towards a target
Lesson 5
Combine conditions, and remember which mode you are in
Lessons 6–7
Record a run of values and work out what they mean
Lessons 8–9
Settle instead of twitching, and share a value safely
Lessons 10–11
Measure your own conditions instead of guessing them
Today
The remaining Level 3 lessons put these together on harder models — and Level 4 takes them onto a competition mat, where the closed loop becomes a line follower, calibration becomes the first thing you do at every table, and My Blocks become the only way a program stays readable at competition length.
Level 2 made machines that do the same thing every time. Level 3 makes machines that do the right thing when every time is different.
This is what you are building: the EV3 Flower.
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
Prove that rooms differ.
Calibrate at your table and write the threshold down. Carry the flower to a window, or under a shadow, and calibrate again.
Compare the two numbers, and compare with another group. Then answer: what would have happened with a typed threshold of 40?
Challenge 2
Calibrate the deadband too.
Make the band a tenth of the range between bright and dark, rather than a number you chose.
Test it in a high-contrast spot and a dim one. The band should come out wide in one and narrow in the other — which is the machine adapting a Lesson 10 idea to a Lesson 12 measurement.
Challenge 3
Sample properly.
Replace each single reading with five readings averaged.
Calibrate three times without moving anything and compare the thresholds. With one sample they will differ noticeably; with five they should be close. Report both spreads — that difference is why real calibration always samples more than once.
Mission
Build a flower that could be sold.
It must work, first time, with no adjustment, in a room nobody has tested it in — handed to a stranger who has never seen the program.
That means:
- it tells the user what to do, in words on the screen, without anyone explaining
- it calibrates itself from what the user shows it
- it refuses a bad calibration: if bright and dark are too close together, say so and ask again rather than computing a nonsense threshold
- once running, it opens and closes cleanly with no flapping at any light level
Then do the real test. Give it to someone from another group with no instructions at all and watch them without helping. Every moment they hesitate is a design fault, not a user error.
Finally, write down every number still typed in your program and, for each, say whether it could be measured instead. Some genuinely cannot — motor degrees for the petals are a fact about the model, not the room. Knowing which is which is the last thing this half of Level 3 teaches you.
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.