Challenge 1
Make the performer do five trips out and back. It must stop at the near end. Show the trip count on the screen.
Quick Learn — the model, the instructions, the program and the challenges. The theory is in Full Lesson.
EV3 Robotics›Level 2 · Intermediate›Lesson 40
Level 2 · Lesson 40 · EV3-L02-4060 minutes · Ages 8+ · Model: Balance Unicycle
The Balance Unicycle. A little LEGO rider sits on one wheel. It rides along a rope made of a rubber band. A motor at one end moves the rope.
The rider has no motor or sensor at all. It balances because of how it is built. Its weight hangs below the rope. It moves because the rope moves under it.
By the end of the lesson, the rider will go to the end of the rope. It will turn round by itself and come back. It will do this for ever. And no number in the program will say how long the rope is.
A tightrope walker crosses a high wire holding a long pole. The pole is not just for show. It is not for holding on to either. It is the most important thing they carry.

A long pole makes the walker slower to tip. The pole puts weight far out to each side. To lean, the walker must move all that weight a long way. That takes time. The walker uses that time to fix the lean.
Even better, the pole often bends down at the ends and hangs below the wire. The point where all the weight seems to sit is called the centre of gravity. The bent pole pulls it down low. When the weight is below the wire, a lean does not tip the walker over. Gravity pulls them back up. They swing like a pendulum instead of falling.
Your rider does the same thing. Its weight hangs below the rope. That is why it stays up with no sensor and no code.
With the weight above the wire, every wobble gets bigger. With the weight below, every wobble gets smaller. That is the difference between a scary stunt and a swing.
Some problems are fixed by how you build. No program can fix them for you.
Lesson 25’s crane knew where to stop because you measured it and typed in the numbers. That works, until something slips.
This machine moves a rubber band. A rubber band stretches. It grips in a different way when it is warm. It slips when the rider gets caught on something. After ten minutes of running, “800 degrees” is not the end of the rope any more.
[A v] start motor [clockwise v] :: motors [2 v] wait until [pressed v] :: sensors [A v] stop motor :: motors
| An encoder limit (Lesson 25) | An end stop: a switch at the end (today) | |
|---|---|---|
| How it knows where the end is | a number you measured before | a real switch is there |
| If the band slips | wrong, and gets worse | still right |
| If somebody moves the model | wrong straight away | still right |
| What it costs | nothing. The motor already counts | a sensor, a port and a place to fix it on |
This is why a printer makes a noise when you switch it on. It is also why a garage door goes all the way up when it first gets power. The machine is homing. That means it drives until it hits a stop it knows. Then it counts everything from a real place.
forever [A v] start motor [clockwise v] :: motors [2 v] wait until [pressed v] :: sensors [A v] start motor [counterclockwise v] :: motors [1 v] wait until [pressed v] :: sensors end
This program works on a rope of any length. It still works after the band stretches. That is a big deal. Programs in class often break for one reason. Something moved, but the number stayed the same.
The Touch Sensor is the simplest input the EV3 has: a button that is either pressed or not. That sounds trivial, but it is how a robot knows it has hit a wall, reached the end of a track, or been told to start by a person.
| Block | What it does |
|---|---|
wait until <[1 v] is pressed? :: sensors> | Holds the program here until somebody presses the sensor. |
<[1 v] is pressed? :: sensors> | Reports true or false. Drop it into a condition to make a decision rather than a wait. |
[1 v] when [bumped v] :: events hat | Starts a whole stack of its own. The dropdown chooses the moment: pressed, released or bumped. |
A button is not only “pressed”. One press is three things: the moment it goes down, the time it stays down, and the moment it comes back up. Watch what a single press does to three programs at once.
versus two hat blocks
The middle counter is the one that surprises people. Nothing is wrong with it — a loop really does check that fast, and every check really is a separate answer.
Nothing there is broken. A loop really does get round hundreds of times a second, and each time it asks is pressed? the honest answer is still yes — so if that loop plays a sound or counts something, it does it hundreds of times from one finger. The two hat blocks each fire once, and they fire at different moments: pressed the instant the button goes down, bumped only when it comes back up.
The three options, and what each is for:
when program starts :: events hat set movement motors to [B v] and [C v] :: movement start moving [straight: 0] :: movement wait until <[1 v] is pressed? :: sensors> stop moving :: movement
The robot drives until something presses the sensor. Note that the movement is started unmeasured on purpose — the sensor decides when to stop, not a distance.
Touch sensors are everywhere in machines you cannot see into: a lift knows the doors are shut, a printer knows the lid is closed, a washing machine will not spin until it is latched. They are safety devices as much as inputs.
Waiting is how a program gives the physical world time to catch up. There are two kinds, and choosing between them is one of the first real design decisions in robotics.
| Block | What it does |
|---|---|
wait (1) seconds | Holds the program for a fixed length of time, whatever else is happening. |
wait until <> | Holds the program until a condition becomes true — usually a sensor reading. |
Most sensors bring their own ready-made wait block, already coloured to match the sensor and with its comparison built in. They are all the same idea — hold here until this is true — and they live in the sensor’s own palette rather than in Control.
| Sensor | Block | Waits until |
|---|---|---|
| Touch | [1 v] wait until [pressed v] :: sensors | the button is pressed. The dropdown also offers released and bumped. |
| Colour | [3 v] wait until color is [red v] :: sensors | the surface underneath is that one of the eight colours. |
| Ultrasonic | [4 v] wait until distance [< v] (15) [cm v] :: sensors | something is nearer than 15 cm. Flip the dropdown to > to wait for something to move away. |
| Gyro | [2 v] wait until angle [< v] (45) :: sensors | the robot has turned past that angle. |
| Brick buttons | wait until [center v] button is [pressed v] :: sensors | somebody presses that button on the Brick. No port — it is built in. |
Some readings have no wait block of their own — reflected light, ambient light, the timer, and a motor’s degrees counted. For those, drop the matching boolean into the plain wait until from Control. It does exactly the same job:
wait until <[3 v] is reflected light intensity [< v] (30) %? :: sensors> wait until <[3 v] is ambient light intensity [> v] (50) %? :: sensors> wait until <(timer) > (5)> wait until <([A v] degrees counted :: sensors) > (720)>
This is also the way to wait for two things at once, which no ready-made block can do — the sensor blocks each take one condition, but a boolean can be combined:
wait until <<[1 v] is pressed? :: sensors> or <(timer) > (5)>>
That one says “stop waiting when the button is pressed, or after five seconds, whichever comes first” — which is how you stop a wait hanging for ever when the thing you are waiting for never happens.
Two robots, the same job: drive up to the wall and stop. One waits two seconds; the other waits for the wall. Let it run several times — the interesting part is what happens on the second and third run.
wait for a length of time
wait for a condition
Each orange dash is where a previous timed run finished. The sensing robot has never left a second mark, because it has never stopped anywhere else.
The timed robot is not being careless. Two seconds is a perfectly good guess, and on the first run it may look exactly right. But a second covers a different distance on a fresh battery, on a dusty floor, or with a heavier load, so the robot finishes somewhere new every run — sometimes short, sometimes into the wall. The sensing robot has never had to guess.
Prefer waiting for a condition wherever a sensor can tell you. Keep timed waits for things with no sensor to check — letting a sound finish, or pausing so a person can watch.
A lift that waits three seconds for its doors is guessing; one that waits for the door sensor knows. The first eventually closes on somebody.
When things can move, check the real world. Do not trust a number you wrote down.
Every object behaves, as far as balancing is concerned, as though all its weight were concentrated at a single point: its centre of gravity. Find that point and you can predict whether a robot stands up or falls over, without knowing anything else about it.
Drop a vertical line from the centre of gravity. If it lands inside the base — the patch of floor between the parts touching the ground — the object stands. If it lands outside, it tips.
That is the whole of it. Everything else — wide wheelbases, low batteries, counterweights — is a way of keeping that line inside that patch.
The red line is the pull of gravity through the centre of the whole robot. It tips the moment that line lands outside the wheels.
It stands. Raising the load costs nothing while the robot is level, and costs everything the moment it tilts: this one goes over at about 42°.
Two ways to make a robot harder to tip, and they are both in the numbers above: put the heavy parts low so the line barely moves when it tilts, and make the wheelbase wide so there is more floor for the line to land on.
This is the part worth being deliberate about, because it is why a robot passes every test on the bench and falls over in the competition.
Standing level, a load carried high is exactly as stable as the same load carried low — the line comes down in the same place either way. Tilt the robot, though, and the line swings sideways by an amount proportional to how high the centre of gravity is. A tall robot needs only a small tilt to push the line past its wheels; a low one can be tipped a long way and still come back.
A robot does not have to be on a ramp to be tilted, either. Accelerating hard, braking hard and turning sharply all lean the effective pull of gravity to one side, and a tall robot finds that out at the first corner.
There is a cost to a very low, very wide robot: it cannot climb over anything and it will not fit through gaps. Like everything else in mechanics, it is a trade.
Balance the robot on one finger, or on the edge of a ruler, until it sits level. The centre of gravity is directly above where you are supporting it. Do it from two directions — front to back, then side to side — and you have located it well enough to build around.
Then test it properly: raise one side of a board until the robot goes over, and measure the angle. Change one thing, do it again, and record both. That is the same one-thing-at-a-time discipline Mechanisms without motors asks for everywhere else.
Racing cars are built low and wide for exactly this reason, and double-decker buses are tested by tilting them until they fall. A crane carries huge counterweights so that the line from its centre of gravity stays inside its tracks even with a load out at full reach.
Say this back before moving on: “The switch is at the end, so the end cannot move.”
Look at your model. Which parts have wires? Which parts do their job just by their shape? This build is good for that question. The star of the show has no wires at all.
| Part | What it is doing here |
|---|---|
| EV3 Intelligent Brick | Holds one end of the rope and runs the program. |
| Large Motor — the roller | Turns the roller that moves the rubber band. It is Large, not Medium. It has to pull the band against the rider’s weight and the band’s own stretch. |
| Touch Sensor — near end | Says “you are home”. |
| Touch Sensor — far end | Says “you are there”. It is just like the other one. Only the cable tells them apart. |
| The rider (no wires) | Rides the band on one wheel. Its weight hangs below the band. That is the only reason it stays up. |
| The rubber band (no wires) | This is the rope. It is why we need today’s idea. It stretches and slips, so distances measured with it slowly go wrong. |
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 |
|---|---|---|
| Roller motor | A | One motor with its own job. |
| Near-end switch | 1 | The Touch Sensor’s usual port. |
| Far-end switch | 2 | This is usually the Gyro’s port. We borrow it because this model has no Gyro. The Lift in Lesson 35 did the same, and told you why in the same way. |
The manual wires this model differently: motor to B, switches to 2 and 4. This lesson uses the course’s usual ports. A single motor goes on A. The Touch Sensor goes on 1. That is what the programs here say. It is three cables and ten seconds. Move them, or change every port in every program. Do not do half of each.
Check your own wiring now:
Two routes, and either is fine. USB is the reliable one and the one to fall back on when a room’s Bluetooth is busy; Bluetooth leaves the robot free to move, which some models need.
Do these in order. Naming the Brick after you go looking for it in the list is how groups end up driving each other’s robots.
EV3 until somebody changes it.EV3.The two failures, every class, every time. The Brick has gone to sleep while you were building — press the centre button to wake it. Or you have paired with the group at the next table, which is why the name matters.
The long version, including Port View and how to read the port tiles, is in the Brick & Bluetooth guide.
Keep the cable off the rope. This model only just balances. A cable lying on the band slows it down at one spot. The rider will get stuck right there every run.
Stuck? The long version has a photo of every screen. It is in the Brick & Bluetooth guide.
One change at a time. Guess first. The best runs here are the ones that go wrong slowly.
wait (1) seconds after each beep. The rider now stops at each end, and you can watch it settle. Does it swing? How long until it is still?Steps 2 and 3 show why this lesson matters. The counting version works well for a while. Then it does not. And nothing tells you it stopped working. It slowly goes wrong without a sound. End stops are there to stop that.
A count slowly goes wrong. A switch does not. When it matters, use a port for a switch.

Build the model before you read any further. Everything after this is about making it do something, and none of it will make much sense with nothing on the table in front of you.
One page at a time — use Next and Previous, or the ← → keys. Fullscreen makes it big enough to build from.
The same build on Google Drive — sometimes a video, sometimes a scan:
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Check the finished build against the picture before you switch anything on. A motor mounted the wrong way round is far easier to spot now than it is to debug later, when it looks like a program fault.
The whole show. Go home first. Then go back and forth for as long as anyone is watching.
when program starts :: events hat clear display :: display write [FIND HOME] at line (1) :: display [A v] start motor [counterclockwise v] :: motors [1 v] wait until [pressed v] :: sensors [A v] stop motor :: motors write [SHOWTIME ] at line (1) :: display forever [A v] start motor [clockwise v] :: motors [2 v] wait until [pressed v] :: sensors play beep (72) for (0.2) seconds :: sound [A v] start motor [counterclockwise v] :: motors [1 v] wait until [pressed v] :: sensors play beep (60) for (0.2) seconds :: sound end
stop motor inside the loop. The next start motor just turns it the other way. A stop would make the rider pause and swing at each end. You can try that on purpose later.What success looks like: the rider glides to the far end. The Brick beeps high. It comes back. The Brick beeps low. It keeps going. It should never run off the end, and never stop halfway.
Does it turn back straight away and get stuck? Then switches 1 and 2 are swapped. Does it run off the end? Then the rider is missing the switch. Go back to the hand check in step 5. No program can fix a switch that is never pressed.
Work through them in order — each is harder than the last. The extra challenge comes after all three, and it is meant to make you plan before you build.
Make the performer do five trips out and back. It must stop at the near end. Show the trip count on the screen.
Add a pause and a bow. At each end, the performer stops for two seconds. The Brick plays a different sound. Then the performer sets off back.
Bring the performer home from wherever it is sitting. The program must not know which way it needs to go first.
Send the performer to the far end and back. Then make it stop in the MIDDLE of the wire. There is no switch in the middle. An end stop is the switch at each end. Use the two end stops and the encoder together to find the centre. Work out how. Then prove your way still works after somebody stretches the rubber band. It must also work after they take it off and put it back.