The Balance is a pan on a beam. Put something on the pan, and the beam tips down. A sensor measures how far it has tipped.
The sensor gives you degrees. Nobody wants degrees. They want grams. But no sensor in the kit measures grams. Grams depend on this beam, this spring and how you built it.
By the end, your balance will show a real weight in grams. First you show it two things whose weight you know. It will also tell you when it does not trust its own answer.
In the real world 5 min
Where you have seen it
An old beam balance does not measure weight at all. It compares. Put the thing on one side. Put weights you know on the other side until it is level. Now you know the weight, because you know the weights. You only have to trust the weights.
A balance from about 1850. Photo: User:Poussin jean / Wikimedia Commons (CC BY-SA 3.0).
An electronic scale cannot do that. Inside is a tiny part that bends. It gives a tiny electric signal. That signal means nothing on its own. So at the factory, people put known weights on it. They write down what it reads. That is how it learns grams.
Why it is built that way
A sensor measures its own thing, not the thing you want. The part in a scale measures bending. A heat sensor measures electricity. Your Gyro measures degrees. Each one needs someone to work out what its numbers mean in the real world.
In Britain, shop scales are checked and sealed by Trading Standards. That is because a scale can slowly go wrong. A scale that is a little bit wrong looks fine. Nobody can tell until it is tested with a known weight.
What would go wrong without it
Say a machine just shows the sensor number. Only the person who built it knows what it means. Rebuild the beam, and every number changes. Nobody can compare two machines. Nobody can check if either one is right.
A sensor gives you a number. Only a known weight turns it into a real measurement.
The main concept — two points make a scale 6 min
Today you take two readings and keep the whole line between them. That turns any reading into grams. This is called calibration.
The two references
Empty pan. Write down the reading. That is your zero. It is the point where the answer is 0 g.
A known weight. Put something on the pan that you know the weight of. Write down 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 weight give per unit. That is how many grams one step of the sensor is worth. After that, you just multiply.
This turns one set of numbers into another. The real world gives you the ends. The empty pan sets one end. A known weight sets the other. The maths does the rest, and the answer is in grams.
Tare: moving the zero
Put a bowl on a kitchen scale and press Tare. The screen goes back to zero. Now it only weighs what you add. In code, that is one line. Take the reading now and make it the new zero:
// TARE: whatever is on the pan now counts as nothing
set [zero reading v] to (reading) :: variables
The grams per unit do not change. Only the zero moves. That is why you do not need to calibrate again after a tare.
The assumption, and how to test it
Two points make a straight line. So you are guessing the beam moves in a straight line too. A spring is nearly straight for small weights. It is not straight when it is stretched a lot.
So test it with a third weight you did not calibrate on. Does a known 50 g read 50? Then the line works. Does it read 43? Then the beam is not moving in a straight line. Two points are not enough for those weights.
Third weight reads
Means
Do
Close to its true mass
The line works for your weights.
Nothing. It works.
Wrong by about the same amount every time
The zero is wrong.
Re-tare with an empty pan.
More wrong for heavy weights than light ones
Not a straight line.
Only weigh lighter things. Or calibrate at more points and use the two nearest.
Say how much you trust it
A balance that shows 37.4213 g is pretending to be very exact. It is not. Weigh the same thing a few times. Do the answers change by two grams? Then show whole grams. The extra digits are just noise.
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 one tells you if you can trust it.
▶CalibrationMeasure the two ends, then work it out from them. Today you get grams.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 go back to just where it started? If not, calibration cannot help. The zero moves by itself.
Part
What it is doing here
EV3 Intelligent Brick
The base and the screen. It shows grams. It also shows how sure it should be about them.
Gyro Sensor — the tilt
Measures how far the beam has tipped. It gives degrees, and degrees are not grams. Turning one into the other is the whole lesson.
Large Motor — the beam
Holds the beam and brings it back. Its encoder can also measure the tip. That is a second way to check. The Ticket Checker in Lesson 31 also used two sensors to check each other.
Touch Sensor — tare / calibrate
Your way to say “this is zero” and “this is the known weight”. Each press teaches the robot one number.
The beam and spring (not electronic)
This decides if the balance is right or wrong. It must go back to the same place every time. It must tip smoothly. Rubbing in the pivot is bad. Then the reading depends on which way the beam last moved.
Set the balance down and leave it alone while it works. The Gyro sets its zero when the program starts. If you move the model, the Gyro drifts. So if you pick it up while it weighs, the number 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. You cannot swap them. If you do, nothing warns you. The robot just will not work.
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 table and leave it there before you start the program. The Gyro finds its zero in that first moment.
Find two or three things you really know the weight of. Coins are great. A UK 2p is 7.12 g. A £1 coin is 8.75 g. Ten 2p coins make a good 71 g weight.
Put a weight on the pan and take it off, three times. Check the empty reading goes back 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.
Use USB, and do not lean on the table. This balance feels even a small knock. Keep the cable loose. Keep everything still while it takes a reading.
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 three times. Then read it with your known weight on, three times. Write down all six numbers. Are the three empty numbers more than a degree or two apart? Then fix the pivot before you write any code. Your balance can never be better than that.
Test with a third weight. Calibrate on empty and 71 g. Then weigh something else you know the weight of. Write down its real weight and what the balance said. The gap shows how good your balance is.
Test with heavy things. Weigh something much heavier than your 71 g. How wrong is it? A spring stops being a straight line when it is stretched a lot. This is where you will see it.
Put a pot on the pan and tare. Then put things in the pot. It should only show what is in the pot. It is one line of code. People use it more than anything else on a kitchen scale.
Weigh the same thing five times. Take it off each time. How far apart are the answers? Then choose how many digits to show. Change the rounding to match.
Average one reading instead of ten. Watch the screen flicker. Then put it back. How many readings does your balance really need?
Calibrate on two, check on a third. Never show more digits than you can get right every time.
Where this goes 3 min
Today the machine measured something. It used a sensor to find a real number.
The next model is a lift. It has a car on a string, and two buttons. But nothing tells it where the top is. There is no sensor up there, so it cannot measure.
So a person has to decide. The lift only moves while you hold a button down. Let go, and it stops. That is Lesson 35.
Today the machine told the truth about a number. Next, a machine that cannot know, so you decide for it.
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.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
This is what you are building: the EV3 Electronic Balance.
Make it move 10 min
Calibrate first. Then weigh. The second half never uses 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. Later, the same button does the tare. After calibrating, only the zero ever needs to move.
Every reading is the average of ten. One Gyro reading jumps about. Taking an average like this is called smoothing. It makes the number steady and easy to read.
per unit is worked out once, from the two weights. Nothing after that uses the known weight. The scale is set, and the machine just uses it.
Line 6 shows the sensor number as well as the grams. Does a weight look wrong? The sensor number tells you if the sensor or the maths is to blame.
The answer is rounded. Do not show more digits than the balance can get right every time.
What success looks like: calibrate with an empty pan and a known 71 g. Then put on a different thing you know the weight of. The balance shows a sensible number of grams. You can check it on a real scale.
Does the screen show a silly answer, like Infinity? Your two calibration readings were the same. So per unit divided by zero. Use a heavier weight. Is the answer below zero? The beam tips the other way. Swap the two numbers in the take-away.
Challenges 27 min
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Challenge 1
Test with a third weight.
Calibrate on an empty pan and one known mass. Then weigh a different object. You must know its true mass. You must NOT have used it to calibrate.
Report its real mass and what your balance said. The gap between them is your accuracy. It is the only honest way to measure it.
Challenge 2
Tare with a pot.
Put a small pot on the pan. Press tare. Then put things in the pot. The balance should show only what is in the pot.
This takes one line of code. Say why tare does not mean you must calibrate again.
Challenge 3
Find where the line breaks.
Weigh something much heavier than your calibration weight. Check the error. Then weigh something much lighter.
Near their limits, springs stop acting in a straight line. Report the range where your balance can be trusted. Say how you found the edges.
Extra challenge
Build a balance somebody could really weigh things with.
It must show grams. A stranger must be able to use it. It must be honest about how close to right it is.
It needs all of these:
- steps to calibrate it that a stranger can follow from the screen alone.
- tare, working, on a button.
- the result rounded to a number of digits you can explain. Weigh the same object five times and let the spread decide.
- a working range you state, tested at both ends with known masses.
- it will not calibrate if the two readings are too close together, and it says so
Then do the real test. Weigh five things from home. Check each one on a kitchen scale. Show your errors in a table.
Last, answer this in two sentences. Your balance shows grams, but nothing in the kit measures grams. Where did the grams really come from?