The Saw Machine. A Large Motor turns a blade. You must hold down a Touch Sensor for the blade to turn. Let go and it stops.
Most machines start when you press Play. They run until they decide to finish. This one is different. That difference is the whole lesson.
The person using it has to keep saying yes. Not just once at the start. They say yes all the time the blade is moving. As soon as they stop, so does the machine.
In the real world 5 min
Where you have seen it
A big saw blade at a wood mill can be a metre across. It spins so fast you cannot see the teeth. It cuts through a tree trunk without slowing down. Think what it could do to an arm.
A round saw blade on a small wood mill. Photo: Ben Franske / Wikimedia Commons (CC BY-SA 4.0).
Why it is built that way
Look at any dangerous machine. A hedge trimmer, a chainsaw, a paper cutter, a lawnmower. They all have the same thing. There is a control you must hold. To the machine it means “a person is still here and still wants this”.
It is called a dead-man’s switch. Builders think like this. If the person lets go, something has gone wrong. They slipped, or fainted, or got scared, or were pulled away. So the safest thing the machine can do is stop. Letting go is not seen as a mistake. It is seen as an order to stop.
Trains have them too. If the driver stops holding the pedal, the brakes go on by themselves.
What would go wrong without it
Think of a blade with just an on switch and an off switch. It keeps spinning, whatever happens to the person using it. With a hold-to-run control, doing nothing is the safe choice. And doing nothing is just what a hurt or scared person does.
Plan it so that when everything goes wrong, the thing that happens is the safe thing.
The main concept — a loop that watches press and let go 6 min
Two waits inside a forever loop. One waits for a press. One waits for a let-go. That is the whole idea. Learn it by heart.
forever
[1 v] wait until [pressed v] :: sensors
[A v] start motor at (75) % speed :: motors
[1 v] wait until [released v] :: sensors
[A v] stop motor :: motors
end
Wait for the press, then start. Wait for the let-go, then stop. Round again, for ever.
Go round the loop once, slowly:
The loop reaches wait until pressed and stops there. The blade is still. Nothing is happening. Nothing may happen for hours.
You press. The wait ends, and start motor runs. You saw in Lesson 15 that it does not wait for anything. The blade turns, and the stack has already moved on.
The loop reaches wait until released and stops there. The blade keeps turning the whole time. Nothing has told it to stop.
You let go. The wait ends, and stop motor runs. The loop goes back to the top to wait for the next press.
Step 3 is the one people get wrong. The program seems to do nothing while the blade spins. And it is doing nothing. That is right. The blade does not need the program to keep turning. It only needs the program to stop.
Why this needs `start motor` and not `run for`
Try it with run for (5) rotations instead. The stack would sit on that block for five turns. It could not notice the let-go until they were done. You let go, and the blade carries on. A hold-to-run control that ignores you for five turns does not keep you safe.
Why the stop setting matters most here
stop motor uses the setting you met in Lesson 26. On coast, a blade at 75% keeps spinning for a while after you let go. On brake, it stops much faster.
Setting
What happens when you let go
coast
The blade slows down on its own. Kind to the gears, but wrong for a saw.
brake
The blade stops fast. A real saw has a blade brake that does this. That is why it is there.
ComponentSensing5 min
The Touch Sensor
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.
released
pressed
The red button out, and the same sensor with it pushed in. These two states are the entire output of this sensor — there is nothing in between.
Blocks reference
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.
Three different events
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.
when program starts
forever
if 1 is pressed? then
change count by 1
versus two hat blocks
1 when pressed
1 when bumped
0is pressed? in a loop0when pressed0when bumped
In a loop: 0 answers from one pressBumped: exactly one
Nobody is touching the sensor. All three programs are watching it.A finger presses the button. Watch the red button go in — a couple of millimetres is the sensor's entire movement.The finger is still down. The loop checking «is pressed?» has already run hundreds of times, and every one of them counted.The finger lifts. Only now does «bumped» count, because bumped means pressed AND released.One press. Three completely different answers.Finished. The same press, counted three ways.
released
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:
Pressed — the button is down right now. Good for “hold to run”.
Released — it is up again. Good for acting when somebody lets go.
Bumped — pressed and released. This is what you want for “click to start”, because it will not fire repeatedly while a finger stays down.
The classic bumper
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.
Why it matters
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.
Hold-to-run is not just “on and off”. The machine needs a yes all the time.
▶Loops that never endThe forever loop, and how to get out of one. Open it if forever still feels risky.Show meHide
ComponentControl5 min
Repeating
Machines repeat. A wiper sweeps, a conveyor runs, a ride goes round — and none of that should mean copying the same blocks over and over. A loop says “do this again” once.
Blocks reference
Block
What it does
repeat (10)
end
Runs the blocks inside a set number of times, then carries on below.
forever
end
Runs the blocks inside over and over, and never carries on below.
repeat until <>
end
Repeats until a condition becomes true — a loop with a sensor as its exit.
Forever really does mean forever
Anything placed after a forever loop will never run. Not “runs late” — never. Both programs below end with the same block: set the status light green.
repeat (3)
repeat 3
A run clockwise for 0.25rotations
set status light to green
forever
forever
A run clockwise for 0.25rotations
set status light to green
↑ this block never runs
0passes · repeat (3)0passes · forever
repeat (3): still goingforever: light never set
Both loops begin. Each pass turns the motor a quarter turn.Pass 1.Pass 2.Pass 3 — and repeat (3) has now done its three.The left program carries on to the block underneath and sets its light green. The right one has jumped back to the top of the loop, and it always will.The left program has finished. The right program has not, and will not.
starting
Both programs contain the same green-light block. Let it run as long as you like — the right-hand ring will never turn green.
The repeat loop counts its three passes, stops, and moves on to the block underneath, so its light turns green. The forever loop reaches the bottom of its own blocks and jumps straight back to the top, so the block underneath is never reached — however long you leave it. If a program seems to stop half way through, look for a forever loop above the blocks that are not happening.
Why a sensor program needs a loop at all
A program is a list, and the Brick works down it once. Every block runs, in order, and when the last one is done the program is over. That is fine for a list of instructions — drive, turn, beep, stop — because each is a thing you do once.
A sensor is not a thing you do once. Asking is 1 pressed? gives you an answer about this instant, and an instant later it may be wrong. Checking a sensor once tells you what the world was like at the moment the program started — which is almost never what you wanted to know.
So a program that has to react must ask again, and again, for as long as it is running. That is the whole job of the loop: not to repeat an action, but to keep the question being asked.
Read, decide, act — and then do it again
Wrap a sensor check and the motor it controls in a forever loop and you have built a closed-loop control system — the pattern behind every line follower, thermostat and cruise control:
Read the sensor.
Decide what that reading means.
Act on the motors.
Go back to 1 — immediately, thousands of times a minute.
It is called closed because the output feeds back round to the input: the motors move the robot, moving the robot changes what the sensor sees, and what the sensor sees changes the motors. Break the circle at any point and the robot stops responding.
when program starts :: events hat
forever
if <[1 v] is pressed? :: sensors> then
[A v] start motor [clockwise v] :: motors
else
[A v] stop motor :: motors
end
end
Read it as a sentence and it is almost too simple to need explaining: for ever, if the button is pressed run the motor, otherwise stop it. The motor now follows the button for as long as the program is running.
The same program without the loop
This is the mistake nearly everybody makes first, and it is a hard one to spot because nothing about it looks wrong:
when program starts :: events hat
if <[1 v] is pressed? :: sensors> then
[A v] start motor [clockwise v] :: motors
else
[A v] stop motor :: motors
end
The logic is perfect. The ports are right. Nothing is misspelled. And the robot will ignore the button completely — because the Brick reaches that if/else a few milliseconds after you press Run, finds the button not pressed, takes the else branch, stops the motor, runs out of blocks and ends. By the time a finger arrives, there is no program left to notice it.
with forever — a closed loop
when program starts
forever
if 1 is pressed? then
A start motor clockwise
else
A stop motor
without it — the common mistake
when program starts
if 1 is pressed? then
A start motor clockwise
else
A stop motor
↑ running — for the only time
40checks · with forever1checks · no loop
Looped: motor off, matching the buttonNo loop: motor off for ever, whatever you press
Both programs start. The button is not pressed, so both take the else branch and leave the motor off. So far they agree exactly.The right-hand program has already finished. One if/else, checked once, and there were no more blocks after it — the program ended in a few milliseconds.Press the button. The looped program comes round, checks again, sees `pressed`, and starts the motor. The finished program cannot: it is not running.Release. The looped program comes round again and stops the motor. The other one has not looked at the sensor since the instant it started.Press again, and again. Every pass round the loop is another check — that constant read, decide, act is what a closed loop IS.Finished. The looped program answered the button every time. The other answered it once, before anybody had touched it.
button released
Both programs contain exactly the same if/else. The only difference is the forever block around one of them.
Both programs contain exactly the same if/else. The counter is what gives it away: one keeps checking for as long as it runs, the other is stuck on the single check it made before anybody touched anything. A student who has seen this once stops writing it.
The tell on a real robot is a program that ends the instant you start it — the Brick returns to its menu almost immediately. If a sensor program finishes rather than waits, the loop is what is missing.
Choosing the right loop
Known number of times — repeat (n). A wiper that sweeps five times.
Until something happens — repeat until. Drive until the wall is close.
For as long as the machine is on — forever. A fan, a ride, a monitor.
Say this back before moving on: “Letting go is a command, not a mistake.”
What’s in this build 4 min
Part
What it is doing here
EV3 Intelligent Brick
Checks the button many times a second. How fast it notices is what keeps the machine safe.
Large Motor — the blade
Spins the saw. It is Large because cutting takes force. A blade that gets stuck in the cut is worse than a slow one.
Touch Sensor
The dead-man’s switch. Put it where your hand rests, away from the blade. Where it goes is part of the design.
The blade and guard (not electronic)
The guard is a cover that keeps fingers off the blade. It is not just for show. If your model has one, it stays on.
Where the button goes
Hold the machine as if you were about to push paper in. Where does your other hand sit?
Put the Touch Sensor there. Check that while you hold it, that hand is somewhere the blade cannot reach.
Press it and let go a few times. It should be easy to hold down for ten seconds. It should let go straight away.
If a button is hard to reach, someone will jam it down with a brick. If yours is awkward, move it now.
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
Blade motor (Large)
A
One motor with one job: turning the blade.
Touch Sensor
1
Touch always goes in port 1. Today it is also the only thing between the blade and whatever is in front of it.
Check your own build now:
Motor in A, Touch in 1.
Lay the sensor cable so your moving hand cannot pull it out. If it comes loose in the middle of a cut, the blade keeps spinning. Then the only way to stop it is the stop button.
Keep the blade clear of the table and the cable.
Agree who is using the machine before you switch anything on.
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.
Know where Stop is before you run this. However you connect, find the stop button in EV3 Classroom now. Find the grey button on the Brick too. A forever loop does not end by itself. On this model, you may really want to end it early.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
A Large Motor on A and a Touch on 1.
Press and let go of the Touch Sensor a few times. Watch its tile. It must change every single time. If the sensor sticks, the blade will not stop.
Turn the blade by hand and check tile A counts.
Do not run anything until you know the button works. In this lesson, this check really matters.
Change it and test 8 min
Keep the blade clear of everything for all of these. Some tests break the safety lock on purpose. For those, keep one hand on the Brick’s stop button.
Change brake to coast. Hold the button, then let go. Count how long the blade takes to stop. Then put brake back and count again. Write down both numbers.
Swap start motor at (70) % speed for [A v] run for (3) [rotations v] at (70) % speed. Hold the button, then let go straight away. The blade still finishes its three turns. The safety lock no longer works.
Put it back. Then swap the two waits round: released first, pressed second. Guess what the machine will do. Then run it and find out.
Try a lower speed: run at 30% instead of 70. Does a slower blade feel safer? Or does it just get stuck in the paper?
Add play beep (50) for (0.1) seconds just after the press, before the motor starts. Now a beep warns you before anything moves. Real machines do this, and now you know why.
Step 2 is the important one. It should worry you. Nothing broke. No error showed. The program still looks like a hold-to-run control. But it is not one any more. You only find that out by testing the let-go, not the press.
Test a safety feature by trying to beat it. If nobody has tried, nobody has checked it.
This is what you are building: the Saw Machine.
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
Here is the safety lock. The screen shows what the machine is doing, so anyone can tell with one look.
when program starts :: events hat
[A v] set motor to [brake v] at stop :: motors
clear display :: display
forever
write [STOPPED] at line (1) :: display
[1 v] wait until [pressed v] :: sensors
write [CUTTING] at line (1) :: display
[A v] start motor at (70) % speed :: motors
[1 v] wait until [released v] :: sensors
[A v] stop motor :: motors
end
It starts stopped. The blade only turns between a press and a let-go. The screen always says which.
brake at stop. It is set once, before the loop. It makes the blade stop fast when you let go, not slowly.
write STOPPED. This is at the top of every loop. So the screen is right as soon as the blade stops.
wait until pressed. The machine sits here doing nothing. It stays safe for as long as nobody touches it.
CUTTING, then start motor. The blade starts to spin. The screen changes before the motor starts, on purpose.
wait until released, then stop. Then round again.
What success looks like: the blade only runs while you hold the button. Every time. With no delay you can see. Press and let go fast ten times. The tenth time should work just like the first.
If the blade keeps running after you let go, the Brick does not see the button let go. Most often, the build is holding the button down. Fix how the sensor sits in the build, not the program.
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
Prove the interlock works. The interlock is the safety rule: the blade only turns while you hold the button. Press and let go ten times in a row, fast. The blade must do the same thing every time. It starts only when you press. It stops when you let go. There must be no delay you can see.
Challenge 2
Measure the run-down. That is how long the blade keeps turning after you let go. Time it on coast, then on brake. Do each one three times. Take the middle number. Report both. Say which one you would put on a real saw, and why.
Challenge 3
Add a warning before anything moves. When you press, the Brick must play a sound and show a message on the screen. This must happen BEFORE the blade starts to turn. Leave a short pause between the warning and the movement. Then decide. Does the pause make the machine safer, or more annoying? Both answers are fine if you can give good reasons.
Extra challenge
Try to beat your own safety rule. Then fix what you find.
A guard nobody has attacked is a guard nobody has checked. Your job is to break your own interlock on purpose. Try as many ways as you can. Then close the gaps.
Work through it one step at a time. Write down each try. What did you do? Did the blade keep turning when it should have stopped? What did you change? Try holding the button down with something that is not a hand. Try pulling out the sensor cable in the middle of a cut. Try pressing Play while the button is already held down. Try letting go in the very first moment of a cut.
You can fix some of these in the program. Some need a change to the model. Some you cannot fix at all with the parts you have. Say which is which.
Answer two questions when you show it. Which attack was easiest? Is your fix a real fix, or does it just make the problem harder to cause? Also, a real saw stops its blade in well under a second. Brake alone does not do that. Say what you would have to add to this model to match a real saw.