The Balance: a pan on a beam that deflects when something is put on it, with a sensor measuring how far it has tilted.
The sensor reports degrees. Nobody wants degrees. They want grams — and no sensor in the kit measures grams, because grams depend on this beam, this spring and this arrangement.
By the end of the lesson your balance will report a real weight, in real units, after being shown two things whose weight is known — and it will tell you when it does not trust its own answer.
In the real world 5 min
Where you have seen it
A beam balance does not measure weight at all — it compares. Put the thing on one side and known masses on the other until it levels, and you know the weight because you know the masses. There is no scale to trust, only the reference weights.
A tobacco balance, c. 1850. Photo: User:Poussin jean / Wikimedia Commons (CC BY-SA 3.0).
An electronic scale has no such luxury. Inside is a strain gauge producing a tiny voltage that means nothing on its own — and the manufacturer turns it into grams by putting known weights on it in the factory and recording what it reads.
Why it is built that way
Because a sensor measures its own quantity, not yours. A strain gauge measures stretch; a thermocouple measures voltage; your Gyro measures degrees. Every one of them needs somebody to establish what its numbers correspond to in the world.
Shops in Britain have their scales checked and sealed by Trading Standards precisely because the conversion can drift — and a scale that is wrong by two per cent is invisible to everybody until it is tested against a known mass.
What would go wrong without it
A machine reporting raw sensor units gives a number that only means something to the person who built it. Rebuild the beam and every reading changes. Nobody can compare two machines, and nobody can check either one is right.
A sensor gives you a number. Only a known reference turns it into a measurement.
The main concept — two points make a scale 6 min
Lesson 12 took two samples — bright and dark — and found the midpoint between them. Today you take two samples and keep the whole line, which converts any reading into a real unit rather than just splitting them in two.
The two references
Empty pan. Record the reading. That is your zero — the point where the answer is 0 g.
A known weight. Put something whose mass you know on the pan and record the reading. Now you have two points.
set [zero reading v] to (-14) :: variables
set [known reading v] to (46) :: variables
set [known grams v] to (100) :: variables
set [per unit v] to ((known grams) / ((known reading) - (zero reading))) :: variables
set [grams v] to (((reading) - (zero reading)) * (per unit)) :: variables
Two readings and one known mass give per unit — how many grams one unit of sensor reading is worth. Everything afterwards is one multiplication.
This is Lesson 17’s range mapping, with the output range supplied by reality rather than by you. There you decided both ends; here the world decides one of them and a known weight decides the other. Same arithmetic, and now the answer has a unit.
Tare — moving the zero
Put a bowl on a kitchen scale and press Tare: the display returns to zero and now weighs only what you add. That is one line — take the current reading and make it the new zero:
// TARE: whatever is on the pan now counts as nothing
set [zero reading v] to (reading) :: variables
The scale — how many grams per unit — is untouched. Only the origin moves, which is why tare does not need recalibrating.
The assumption, and how to test it
Two points define a straight line, and using them assumes the relationship is a straight line. Springs are nearly linear over a small range, and noticeably not near their limits.
So test it with a third weight you did not calibrate on. If a known 50 g reads 50, the line holds. If it reads 43, the beam is not behaving linearly and two points are not enough for that range.
Third weight reads
Means
Do
Close to its true mass
The line holds across your range.
Nothing. It works.
Off by a similar amount every time
A zero error.
Re-tare with an empty pan.
Off more at heavy weights than light
Not linear.
Use a smaller range, or calibrate at more points and pick the nearest pair.
Say how much you trust it
A balance that reports 37.4213 g is claiming a precision it does not have. If repeated weighings of the same object vary by two grams, report whole grams — the extra digits are noise dressed as knowledge.
ComponentSensing6 min
The Gyro Sensor
The Gyro Sensor measures how far the robot has turned, in degrees. Wheels slip and floors vary, so counting wheel rotations is a poor way to turn accurately — the gyro measures the turn itself rather than inferring it.
from above
front
The arrows moulded into the top show which way round the sensor measures. Mount it flat and the wrong way up and it will read your turns backwards.
Blocks reference
Block
What it does
([2 v] angle :: sensors)
Reports how far the robot has turned since the angle was last reset.
[2 v] reset angle :: sensors
Sets the current heading as zero.
Always reset before you turn
The angle is measured from wherever it was last zeroed — not from where this turn started. Here are two robots given the same instruction, one with a reset block and one without.
reset first
when program starts
2 reset angle
start moving right: 100
2 wait until angle >90
stop moving
no reset
start moving right: 100
2 wait until angle >90
0°actually turned · reset0°actually turned · no reset
Reset: a real 90° turnNo reset: 0°, and no warning
Both robots have been sitting still. Both gyros already read about 34° — left over from an earlier turn — and the reading is creeping upward even now. That creep is drift.The left program resets its angle to zero. The right program has no reset block.Both turn. Both stop the moment their gyro reads more than 90.The left robot turned 90°. The right one turned 55°, because it started counting from 34 — and it stopped at 90 all the same.Finished. Both readings say 90. Only one of the robots turned 90.
still
Both programs are correct about what they asked for. Only the left one asked the question from a known starting point.
Both programs did exactly what they said. Both gyros stopped at 90. But the robot on the right had 34 degrees already on the clock, so it only turned 55 — and nothing about the program looks wrong. Watch the first step too: neither robot is moving and the reading is still climbing. That is drift, and it is why the reset belongs immediately before the turn.
Reset with the robot completely still, as late as you can.
when program starts :: events hat
[2 v] reset angle :: sensors
start moving [straight: 0] :: movement
wait until <([2 v] angle :: sensors) > (90)>
stop moving :: movement
That program is the obvious one to write, and it will not give you a 90 degree turn. The next section is why.
Stop before you get there
Asking to stop at 90 does not stop the robot at 90. Between the gyro reaching 90 and the wheels actually standing still there is a delay — the sensor has to be read, the next block has to run, and the motors have to physically brake. The robot is still turning through all of it, so it ends up past where you asked.
The fix is to ask for less than you want. Aim for a 90 degree turn by waiting for 86: the robot coasts the last few degrees on its own and settles at roughly 89 to 91.
ask for exactly 90
2 reset angle
start moving right: 30
2 wait until angle >90
stop moving
stop 4° early
2 wait until angle >86
stop moving
slowthis run · 50°/s+4°carried past the stop86tolerance needed here
Asked for 90: ended at 0°Asked for 86: ended at 0°
Both robots are told to turn 90°. The left one waits for the angle to pass 90; the right one gives up 4° early and waits for 86.They turn. Each stops the moment its own condition is met — and then keeps going.That extra sweep in red is the latency: the time to read the gyro, decide, and actually halt the motors. Nothing was wrong with either program.Finished. At this speed the robot carries on about 4° past whatever angle the program stopped at.
slow turn
The tolerance has to match the speed. At 50°/s the number that lands this turn on 90° is 86 — let it loop, and watch that number change when the speed does.
The size of that gap is not a fixed property of the robot — it is the delay multiplied by how fast you are turning. The delay stays about the same whatever you do, so a turn at double the speed carries you about double the distance past the mark.
Turn speed
Carried past the stop
Wait for
Ends up at
slow
about 4°
86
about 90°
fast
about 10°
80
about 90°
So the tolerance and the speed have to be chosen together. Turn faster and you must give up more; if you speed a turn up and forget to lower the number, the robot starts overshooting every corner and the program that worked last week no longer does.
when program starts :: events hat
[2 v] reset angle :: sensors
start moving [right: 30] :: movement
wait until <([2 v] angle :: sensors) > (86)>
stop moving :: movement
Find your own number rather than copying this one — it depends on your robot’s weight, its wheels and the speed you turn at. Run the turn, measure where it actually stops, and move the number by however far it missed. Two or three tries is usually enough.
The other half of the answer is to slow down. A slower turn overshoots less, so it needs less guessing and repeats more reliably — which is why a turn worth getting right is rarely worth rushing.
Drift — the thing that catches everyone
A gyro slowly loses its zero even when nothing is moving. Leave a robot sitting still for a minute and the angle may have wandered several degrees all by itself. That is drift, and it is a property of the hardware, not a bug in your program.
Two habits deal with it: reset the angle as late as possible before a turn, and keep the robot dead still while the reset happens. Resetting while the robot is rolling bakes the error in permanently.
Why it matters
Aircraft, ships and phones all use gyros to know their orientation — it is how a phone knows you have turned it sideways. A robot that can turn exactly 90 degrees on any surface is far more reliable than one that guesses with wheel rotations.
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.
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.
Two known points make a scale. A third, unused one tells you whether to believe it.
▶CalibrationFrom Lesson 12 — measuring the extremes and computing from them. Today the result is a unit, not a threshold.Show meHide
ComponentSensing6 min
The Gyro Sensor
The Gyro Sensor measures how far the robot has turned, in degrees. Wheels slip and floors vary, so counting wheel rotations is a poor way to turn accurately — the gyro measures the turn itself rather than inferring it.
from above
front
The arrows moulded into the top show which way round the sensor measures. Mount it flat and the wrong way up and it will read your turns backwards.
Blocks reference
Block
What it does
([2 v] angle :: sensors)
Reports how far the robot has turned since the angle was last reset.
[2 v] reset angle :: sensors
Sets the current heading as zero.
Always reset before you turn
The angle is measured from wherever it was last zeroed — not from where this turn started. Here are two robots given the same instruction, one with a reset block and one without.
reset first
when program starts
2 reset angle
start moving right: 100
2 wait until angle >90
stop moving
no reset
start moving right: 100
2 wait until angle >90
0°actually turned · reset0°actually turned · no reset
Reset: a real 90° turnNo reset: 0°, and no warning
Both robots have been sitting still. Both gyros already read about 34° — left over from an earlier turn — and the reading is creeping upward even now. That creep is drift.The left program resets its angle to zero. The right program has no reset block.Both turn. Both stop the moment their gyro reads more than 90.The left robot turned 90°. The right one turned 55°, because it started counting from 34 — and it stopped at 90 all the same.Finished. Both readings say 90. Only one of the robots turned 90.
still
Both programs are correct about what they asked for. Only the left one asked the question from a known starting point.
Both programs did exactly what they said. Both gyros stopped at 90. But the robot on the right had 34 degrees already on the clock, so it only turned 55 — and nothing about the program looks wrong. Watch the first step too: neither robot is moving and the reading is still climbing. That is drift, and it is why the reset belongs immediately before the turn.
Reset with the robot completely still, as late as you can.
when program starts :: events hat
[2 v] reset angle :: sensors
start moving [straight: 0] :: movement
wait until <([2 v] angle :: sensors) > (90)>
stop moving :: movement
That program is the obvious one to write, and it will not give you a 90 degree turn. The next section is why.
Stop before you get there
Asking to stop at 90 does not stop the robot at 90. Between the gyro reaching 90 and the wheels actually standing still there is a delay — the sensor has to be read, the next block has to run, and the motors have to physically brake. The robot is still turning through all of it, so it ends up past where you asked.
The fix is to ask for less than you want. Aim for a 90 degree turn by waiting for 86: the robot coasts the last few degrees on its own and settles at roughly 89 to 91.
ask for exactly 90
2 reset angle
start moving right: 30
2 wait until angle >90
stop moving
stop 4° early
2 wait until angle >86
stop moving
slowthis run · 50°/s+4°carried past the stop86tolerance needed here
Asked for 90: ended at 0°Asked for 86: ended at 0°
Both robots are told to turn 90°. The left one waits for the angle to pass 90; the right one gives up 4° early and waits for 86.They turn. Each stops the moment its own condition is met — and then keeps going.That extra sweep in red is the latency: the time to read the gyro, decide, and actually halt the motors. Nothing was wrong with either program.Finished. At this speed the robot carries on about 4° past whatever angle the program stopped at.
slow turn
The tolerance has to match the speed. At 50°/s the number that lands this turn on 90° is 86 — let it loop, and watch that number change when the speed does.
The size of that gap is not a fixed property of the robot — it is the delay multiplied by how fast you are turning. The delay stays about the same whatever you do, so a turn at double the speed carries you about double the distance past the mark.
Turn speed
Carried past the stop
Wait for
Ends up at
slow
about 4°
86
about 90°
fast
about 10°
80
about 90°
So the tolerance and the speed have to be chosen together. Turn faster and you must give up more; if you speed a turn up and forget to lower the number, the robot starts overshooting every corner and the program that worked last week no longer does.
when program starts :: events hat
[2 v] reset angle :: sensors
start moving [right: 30] :: movement
wait until <([2 v] angle :: sensors) > (86)>
stop moving :: movement
Find your own number rather than copying this one — it depends on your robot’s weight, its wheels and the speed you turn at. Run the turn, measure where it actually stops, and move the number by however far it missed. Two or three tries is usually enough.
The other half of the answer is to slow down. A slower turn overshoots less, so it needs less guessing and repeats more reliably — which is why a turn worth getting right is rarely worth rushing.
Drift — the thing that catches everyone
A gyro slowly loses its zero even when nothing is moving. Leave a robot sitting still for a minute and the angle may have wandered several degrees all by itself. That is drift, and it is a property of the hardware, not a bug in your program.
Two habits deal with it: reset the angle as late as possible before a turn, and keep the robot dead still while the reset happens. Resetting while the robot is rolling bakes the error in permanently.
Why it matters
Aircraft, ships and phones all use gyros to know their orientation — it is how a phone knows you have turned it sideways. A robot that can turn exactly 90 degrees on any surface is far more reliable than one that guesses with wheel rotations.
Say this back before moving on: “What is zero, and what does one unit weigh?”
What’s in this build 4 min
Press the pan down gently and let go. Does it return to exactly where it started? If not, no calibration will save it — the zero moves on its own.
Part
What it is doing here
EV3 Intelligent Brick
The base and the display. It shows grams, and — importantly — how confident it is entitled to be about them.
Gyro Sensor — the tilt
Measures how far the beam has deflected. It reports degrees, and degrees are not grams. Turning one into the other is the entire lesson.
Large Motor — the beam
Holds and returns the beam. Its own encoder is a second, independent measure of deflection — useful for cross-checking, which is Lesson 13.
Touch Sensor — tare / calibrate
The user’s way of saying “this is zero” and “this is the known weight” — the teaching idea from Lesson 26, applied to measurement.
The beam and spring (not electronic)
Where accuracy is won or lost. It must return to the same place every time and deflect smoothly. Friction in the pivot is the enemy: it makes the reading depend on which direction the beam last moved.
Set the balance down and leave it alone while it works. The Gyro zeroes itself when the program starts and drifts if the whole model is moved — so a balance that is picked up mid-weighing is reporting a number that includes your hands.
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
Beam (Large)
A
The only motor.
Tilt (Gyro)
2
Gyro stays on 2 across the course.
Tare (Touch)
1
Touch stays on 1 across the course.
Check your own build now:
Beam in A, Gyro in 2, button in 1.
Put the balance on a flat, still surface and leave it there before starting the program — the Gyro finds its zero in that first moment.
Find two or three objects whose weight you actually know. Coins are ideal: a UK 2p is 7.12 g, a £1 coin 8.75 g. Ten 2p pieces is a respectable 71 g reference.
Load and unload the pan three times and check the empty reading returns to the same number each time.
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, and do not lean on the table. A balance this sensitive responds to the table being knocked, so keep the cable slack and everything still while a reading is being taken.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
One motor tile — A.
One sensor tile — 2, in degrees.
Read the empty pan, then read it with your known weight on, three times each. Write down all six numbers. If the three empties differ by more than a degree or two, fix the pivot before you write any code — that spread is the best your balance can ever be.
Stuck? The long version, with a photograph of every screen, is in the Brick & Bluetooth guide.
Make it move 10 min
Calibrate first, weigh second. The second half never mentions a number you typed.
when program starts :: events hat
[2 v] reset gyro sensor :: sensors
set [known grams v] to (71) :: variables
clear display :: display
// ---- 1. empty pan ----
write [EMPTY PAN, PRESS] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [total v] to (0) :: variables
repeat (10)
set [total v] to ((total) + ([2 v] angle)) :: variables
end
set [zero reading v] to ((total) / (10)) :: variables
play sound [Mechanical / Blip 1 v] :: sound
wait until <not <[1 v] is pressed? :: sensors>> :: control
// ---- 2. the known weight ----
write [ADD KNOWN, PRESS] at line (1) :: display
wait until <[1 v] is pressed? :: sensors>
set [total v] to (0) :: variables
repeat (10)
set [total v] to ((total) + ([2 v] angle)) :: variables
end
set [known reading v] to ((total) / (10)) :: variables
play sound [Mechanical / Blip 1 v] :: sound
wait until <not <[1 v] is pressed? :: sensors>> :: control
// ---- 3. the scale ----
set [per unit v] to ((known grams) / ((known reading) - (zero reading))) :: variables
write [READY] at line (1) :: display
// ---- 4. weighing ----
forever
set [total v] to (0) :: variables
repeat (10)
set [total v] to ((total) + ([2 v] angle)) :: variables
end
set [reading v] to ((total) / (10)) :: variables
set [grams v] to (((reading) - (zero reading)) * (per unit)) :: variables
write ([round v] of (grams)) at line (3) :: display
write (reading) at line (6) :: display
if <[1 v] is pressed? :: sensors> then
set [zero reading v] to (reading) :: variables
write [TARED] at line (1) :: display
play sound [Mechanical / Blip 4 v] :: sound
wait until <not <[1 v] is pressed? :: sensors>> :: control
write [READY] at line (1) :: display
end
end
Two presses to calibrate, then it weighs. The same button later tares, because once calibrated the only thing that ever needs moving is the zero.
Every reading is an average of ten. A single Gyro sample jumps about, and Lesson 14’s smoothing is what makes a balance readable rather than flickering.
per unit is computed once, from the two references. Nothing after that mentions the known weight — the scale is established and the machine just uses it.
Line 6 shows the raw reading as well as the grams. When a weight looks wrong, the raw number tells you whether the sensor or the arithmetic is at fault.
The answer is rounded. Reporting more digits than the balance can repeat is a claim it cannot support.
What success looks like: calibrate with an empty pan and a known 71 g, then put a different known object on and read a sensible number of grams — one you can check against a real scale.
If everything reads zero, your two calibration readings were the same, so per unit divided by nothing — use a heavier reference. If the sign is inverted, the beam tilts the other way; swap the two terms in the subtraction.
Change it and test 8 min
One change at a time. Predict, then run, then look.
Test with a third weight. Calibrate on empty and 71 g, then weigh a known object you did not calibrate on. Report its true mass and what the balance said. That difference is your accuracy.
Test the line at the top of the range. Weigh something much heavier than your reference and check the error. Springs go non-linear near their limits, and this is where you will see it.
Tare with a container on the pan, then add contents. It should report only the contents. One line of code, and it is the feature people use most on a kitchen scale.
Weigh the same object five times, removing it in between. Report the spread. Then decide how many digits you are entitled to show and change the rounding to match.
Average one reading instead of ten. Watch the display flicker, then put it back — and say how many samples your balance actually needs.
Calibrate on two, check on a third. And never show more digits than you can repeat.
Where this goes 3 min
Everything in this course has been built to be predictable. The same input gives the same output, and when it does not, you have found a bug.
The last model of this set wants the opposite. A ball conveyor that always delivered the same colour in the same order would be a poor game — it needs to be unpredictable on purpose.
Deliberate randomness is easy to add and surprisingly easy to get wrong — random is not the same as fair, an unlucky run is not a broken machine, and there are parts of any machine that must never be random. That is the last lesson of this twelve.
Today the machine told the truth about a number. Next it learns when not to be predictable.
This is what you are building: the EV3 Electronic Balance.
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.
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
Test with a third weight.
Calibrate on an empty pan and one known mass. Then weigh a different object whose true mass you know and did NOT calibrate on.
Report its real mass and what your balance said. That difference is your accuracy, and it is the only honest measure of it.
Challenge 2
Tare with a container.
Put a small pot on the pan, press tare, then add contents. It should report only the contents.
One line of code. Say why tare does not require recalibrating.
Challenge 3
Find where the line breaks.
Weigh something much heavier than your calibration weight and check the error. Then something much lighter.
Springs go non-linear near their limits. Report the range over which your balance is trustworthy, and say how you found the edges.
Mission
Build a balance somebody could actually weigh with.
It must report grams, be usable by a stranger, and be honest about its own accuracy.
Requirements:
- a calibration routine a stranger can follow from the screen alone
- tare, working, on a button
- the result rounded to a number of digits you can justify — weigh the same object five times and let the spread decide
- a stated working range, tested at both ends with known masses
- it refuses to calibrate if the two readings are too close together, and says so
Then the real test: weigh five household objects and check each against a kitchen scale. Report your errors as a table.
Finally, answer this in two sentences: your balance reports grams, but nothing in the kit measures grams. Where did the grams actually come from?