The Crane: a tall tower with a hook. The tower turns, and the hook goes up and down. You drive it with the Brick’s buttons: up, down, left and right. It has limits, so it cannot hurt itself.
Most machines you have built this level did a set job. You pressed Play and it did its thing.
A crane has no set job. A person drives it, one moment at a time. That person is called the operator. The crane does what it is told. But it says no to the few things that would break it.
In the real world 5 min
Where you have seen it
Tall tower cranes stand over building sites. They lift steel and concrete all day. One operator sits at the top with two joysticks and a screen. Everything the crane does comes from those hands.
A tower crane at a building site in Portland, Oregon. Photo: PortlandAppraisalBlog / Wikimedia Commons (CC BY-SA 4.0).
Why it is built that way
A building site changes every hour. Loads arrive in new places. People move about. The wind changes. No set job could cope with all that. So the crane does not try. It is a set of controls, and the operator does the thinking.
But it is not only controls. It also has limits the operator cannot turn off. The hook stops before it hits the top. The tower can only turn so far. And the crane will refuse a lift so heavy it would tip over. The operator decides what to do. The machine decides what is safe.
What would go wrong without it
With controls and no limits, one tired moment could break the crane. With limits and no controls, the crane could only do what someone planned before. Real machines need both. And nobody can argue with the limits.
The operator says what to do. The machine says what it will not do.
The main concept — one control, one stack 6 min
A control panel is not one big program. It is lots of small ones, all running at once. Each one has one control and one motor.
when [up v] button [pressed v] :: events hat
[A v] run for (90) [degrees v] at (30) % speed :: motors
when [down v] button [pressed v] :: events hat
[A v] run for (90) [degrees v] at (-30) % speed :: motors
Two hats, one motor, two ways round. They do not talk to each other. Each one just waits for its own button.
You have seen every piece of this before. The Minesweeper, in Level 1, ran two stacks at once. The Archery Robot, in Lesson 19, had a button hat that waits for its own button. What is new is how you use them. You build an interface: a set of controls a person uses, not a set job.
The rule that keeps it safe
One motor, one stack at a time. Two stacks must never drive the same motor. A control panel is where people break that rule. Two hats may both use motor A, like the ones above. That is only because you cannot press up and down at the same moment. What if two controls could both run at once on the same motor? The motor would obey whichever order came last. Then it would act differently each run.
Limits are a must
Someone holding the up button does not want to think about the top of the tower. So the control checks for them. It uses the motor count, as the Swing Ride did in Lesson 6:
when [up v] button [pressed v] :: events hat
if <([A v] degrees counted) < (1000)> then
[A v] run for (90) [degrees v] at (30) % speed :: motors
else
play beep (45) for (0.3) seconds :: sound
end
At the limit, the control still answers. It says no with a beep you can hear. If it stayed quiet, you could not tell it from a broken button.
That else matters a lot. A control that does nothing when it says no feels broken. Then the operator presses harder, or tries to find another way round.
ComponentSensing4 min
The Brick buttons
The Brick has five buttons of its own — up, down, left, right and centre. They need no sensor, no cable and no port, which makes them the easiest way to let a person tell the robot to do something.
Five buttons — up, down, left, right and centre — built into the Brick. No cable, no port, no sensor to plug in.
Blocks reference
Block
What it does
when [center v] button [pressed v] :: events hat
Starts a whole stack when that button is pressed.
wait until <is [center v] button pressed? :: sensors>
Holds an existing program until the button is pressed.
Press to begin
A program sitting on a wait block looks exactly like a program that has crashed. Watch one wait — including through two presses of the wrong button.
when program starts
wait until is center button pressed?
A run clockwise for 1rotations
the other way to do it
when center button pressed
A run clockwise for 1rotations
The program has reached the wait block. It is not stuck — it is waiting, and nothing below it will run until the centre button goes down.Up is pressed. The button reporter changes to 4, but this wait is watching the centre button, so the program stays where it is.Right: 3. Still not the one.Centre: 2. The condition is true and the wait lets go.The motor runs. One press, at the moment a person chose.Finished. The robot did nothing at all until a person said so.
waiting for centre
A program parked on a wait block looks identical to a crashed one. This is why the status light or a line on the screen is worth setting before you wait.
The wait is watching one button. Up and right change the (button) reading, and the program does not care. That reading is a number rather than a name: 0 for nothing, then 1 left, 2 centre, 3 right, 4 up, 5 down.
A hat, or a wait?
A hat gives the button its own separate stack, which can run at any time. Good for a control the user may press whenever they like.
A wait puts the button in the middle of a sequence. Good for “press to begin”, where nothing should happen before it.
Why it matters
Nearly every machine has a start button that is deliberately separate from switching the power on. A robot that begins moving the instant it is powered up is hard to set down and hard to test — one that waits for a press can be positioned first.
Give every control its own stack, its own motor, and a limit nobody can get round.
▶Separate stacksWhy lots of hats run at once, and the one motor rule.Show meHide
ComponentControl5 min
Two things at once
A program does not have to be one long column of blocks. Several stacks can run at the same time, each doing its own job — one driving, one watching a sensor, one keeping the display up to date.
How it is done
Give each stack its own hat block. Every stack beginning with when program starts starts at the same instant — not one after another — and from then on they run alongside each other.
Nor is it limited to two. Below, three stacks run together: a Medium Motor turning an attachment, the status light flashing, and the drive base rolling. Watch the arrows at the top — they all begin at once, and no stack waits for any other.
when program starts :: events hat
[A v] start motor [clockwise v] :: motors
when program starts :: events hat
forever
set status light to [green v] :: display
wait (0.5) seconds
set status light to [red v] :: display
wait (0.5) seconds
end
when program starts :: events hat
start moving [straight: 0] :: movement
Written down they have to go one under another, because a page is a column — but that is an accident of paper. On the Brick they sit side by side, and nothing in the first stack happens before anything in the third.
The rule: one owner per thing
Parallel stacks go wrong when two of them try to control the same thing. Use the switch below to take the wheels away from the third stack and point it at motor A, which the first stack is already driving.
the program starts — all of these begin here
stack 1 · Medium Motor
when program starts
A start motor clockwise
stack 2 · status light
when program starts
forever
set status light to green
wait 0.5 seconds
set status light to red
wait 0.5 seconds
stack 3 · drive base
when program starts
start moving straight: 0
One stack, one jobAll three at once
Three stacks, each with its own hat block. All three start the moment the program starts — none of them waits for the others.All three are running in the same instant: the Medium Motor is turning, the light is flashing, and the drive base is rolling.Each stack owns one thing and never touches another stack's job. That is the rule that makes this work.Finished. All three jobs ran the whole time, and none got in another's way.
three stacks, three jobs
Every stack is highlighted at the same moment on purpose — that is what running in parallel looks like. The switch above changes only what the third stack controls.
With one owner each, all three stacks are highlighted at the same instant and all three jobs get done. With two owners, motor A is handed contradictory orders hundreds of times a second and shivers instead of turning — and notice the second cost, which is easy to miss: the wheels now have nobody driving them. A stack that goes to fight over someone else’s motor has abandoned its own job. Nothing reports an error either way; as far as the Brick is concerned every stack is working perfectly. The same happens to a display line or a variable that two stacks both write to.
The discipline is simple: give each stack sole ownership of what it controls. One stack owns the motors, another owns the screen, another watches the sensors and tells the others what it found — which is what broadcasting is for.
Say this back before moving on: “One control, one stack, one motor.”
What’s in this build 4 min
Part
What it is doing here
EV3 Intelligent Brick
The driver’s seat. Its five buttons are the whole control panel. Its screen shows you what the crane is doing.
Large Motor — the hoist
Lifts and lowers the hook. It must hold still when it stops. If not, the load drops each time you let go.
Large Motor — the slew
Turns the tower. Turning is called slewing. It has lots of gears to slow it down. Turning the long arm with a load is the hardest job on this model.
The jib and counterweight (not electronic)
The jib is the long arm. The counterweight is a heavy block on the other side. It stops the crane tipping when the load is far out. Take it off and the model will show you why real cranes have one.
Find the limits before you program them
Wind the hoist all the way down by hand. Reset the count there. That is zero.
Wind it up until the hook is near the top. Stop well before anything touches. Read the count. Your top limit goes a little below that.
Do the same for the slew. Find how far the tower can turn each way before a cable gets tight. Write down both numbers.
Wind everything back to a start spot you know. Every run starts from there. The motor count is the only thing the crane knows about itself.
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
Hoist (Large)
A
Up and down. Its port is in both of those stacks and both limits.
Slew (Large)
D
Left and right. It is far from A, so one wrong letter cannot make the hook turn the tower.
Sensors
none
The Brick’s buttons are the controls. The motor counts are the limits. In the challenges, you can add a Touch Sensor as a real stop.
Check your own build now:
Hoist in A, slew in D.
Lay the hoist cable so the tower can turn all the way without winding it up. This model is the one most likely to tangle itself.
Set both motors to their start spot. Reset the counts each time you begin.
Put nothing precious under the hook. You are testing the limits today, so you are also finding them.
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.
Bluetooth. The Brick is the driver’s seat. You will hold it and press its buttons while you watch the hook. A cable would decide where you have to stand.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
Two Large Motor tiles, on A and D.
Wind the hoist and check tile A. Turn the tower and check D. If they are swapped, up will turn the tower and left will lift the hook.
Check both counts show what you expect at your start spot.
Change it and test 8 min
Test the panel the way an operator would: use it. Try to do a real job with it. Notice what annoys you.
Take the limit off the up control. Hold the button. Watch the hoist hit the top and strain. Stop it, and put the limit back. This is what the limit is for.
Take away the else beeps. Now drive to a limit and hold the button. Nothing happens. No sound, no message. Ask someone else to use it. Do they think it is broken?
Change the hoist step from 90 degrees to 360. That means fewer, bigger moves. Is the crane nicer or worse to drive? Does it still stop at the limit, or sail past it?
Add a fifth control on the centre button. It takes the hook back to a set height. Run the hoist until its count gets there. That is a “home” button. Every real machine has one.
Show the hook height and tower angle on the screen. Make them change as you drive. Now you have a display as well as controls.
Step 2 is the interesting one, and it is not really about code. The machine works perfectly. It is keeping itself safe, just as planned. But it feels broken. A machine is nice to use when it tells you what it is doing. It should also tell you when it says no.
A “no” must make a sound. A machine that ignores you in silence looks just like a broken one.
This is what you are building: the Crane.
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.
One page at a time — use Next and Previous, or the ← → keys. 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.
Make it move 10 min
Set the both motor speed to 20%
When Left button is pressed, the crane turns left; when Right button is pressed, the crane turns right.
When Up button is pressed, the crane hook will move up; when Down button is pressed, the crane hook will move down.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
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
- When the center button is pressed, it will play a sound "Mechanical/Motor start" and start to move the crane hook down to reach the box.
- After 2 seconds, pick up the magnet from the box and play a sound "Information/Activate" and the hook will move up to the original position. It will play a sound "Communication/Bravo" when finished.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
Extra challenge
Design and build a custom hook (not the original hook) to pick up an object (not a magnet). Control it using the manual control, same as the basic challenge.
The program, block by block
Motors C (hook) and D (turn) · Speed 20%, both · Sensors none
What it does
Turns the EV3 brick into a hand controller for the crane. Left and right turn the
crane on motor D. Up and down wind the hook on motor C. Letting go of every button
stops both motors.
Nothing happens by itself. Each press starts a motor, and only the release stack ends it.
Worth noticing
Start, not run for. Every button uses start motor, which runs until told to stop.
That is why the crane keeps moving for as long as the button is held.
The no button stack is the brake. Its dropdown says no, meaning no button is
being held. It is not the centre button. Remove it and a started motor never stops.
Speed is set once. Change the two blocks in the start stack and the whole crane
changes speed. There is nowhere else to look.
Direction depends on the build. If up lowers the hook, swap clockwise and
counterclockwise in the up and down stacks. Do not swap the ports.