The Fencing model: a long, light sword with a Touch Sensor at its tip. Touch something with the point, and the Brick knows at once.
There is no motor in this build. Not one. The only electronic parts are the Brick and one Touch Sensor. Nothing on the model moves by itself.
The Elastic Car in Lesson 14 had moving parts and no electronics. This is the opposite. It senses, but it does not move. Its only job is to notice, and then tell you. So it is a good place to learn a new way for the Brick to tell you things.
In the real world 5 min
Where you have seen it
Fencing matches have used electric swords since the 1930s. Each sword has a switch in its tip. A wire joins it to a scoring box. A hit makes a light and a sound, faster than any judge could see it.
An épée bout at the Challenge international de Saint-Maur. Photo: Marie-Lan Nguyen / Wikimedia Commons (CC BY 2.5).
Why it is built that way
A fencing hit takes a few thousandths of a second. Two fencers can both hit at almost the same moment. No person could say which came first. In one kind of fencing, called épée, hits less than a twenty-fifth of a second apart both score.
A person cannot judge that. So the sport gave the job to a switch. It is a button in the tip that clicks when it presses on something. It is not clever. It does not know where it hit. But it is very, very fast.
What would go wrong without it
Before the electric box, four judges stood round the fencers and called the hits. People argued a lot. The switch did not make fencing faster. It made it agreed.
Notice what the box does when it feels a hit. It makes a tone. Not a voice, not a tune. Just one clear note. You can hear it across a noisy hall, and it means just one thing.
When a machine senses something, it must tell you at once. And nobody should be able to mistake it.
The main concept — making a sound instead of playing one 6 min
Most sounds in this course have been a recording picked from a list. The Brick can also make a tone from a number. You have used a beep to end a ride since the Pirate Ship in Lesson 7. Today you find out what its numbers do. And you can change a number.
Block
What it plays
play sound [Information / Blip 1 v] until done :: sound
A recorded file. It is always the same. You pick it from a list.
play beep (60) for (0.2) seconds :: sound
A tone you describe: which note, and how long. Both are numbers.
start playing beep (60) :: sound
The same tone, but the program carries straight on. It is the wait-or-carry-on idea from Lesson 6, the Auto Gate.
The first number is the note. Bigger means higher. You only need to know these numbers roughly:
Number
Sounds like
40
Low. A deep thud you feel more than hear.
60
Middle. The default, and a safe choice.
72
Bright and clear. An octave above the middle. Alarms and scoring boxes use notes like this, because you can hear them over noise.
90
Very high and sharp. Do not use it much, and warn the room first.
There is no plain “beep” block and no “play note” block. In EV3 Classroom, a tone always has a note number and a length. There is no simpler block, so do not look for one.
Here is why this matters for a scoring machine. A sound file says one thing. A number lets one machine say lots of things. A high note for a good hit. A low note for a miss. Another note for the end of the match. All from the same block, with a different number in it.
A sound file is something you pick. A beep is something you can work out with numbers. That is the big difference. It is why beeps can do more than files.
▶Sound and beeps, and the Touch SensorAll the sound blocks, and the sensor this model is built around. Open one if it is not clear yet.Show meHide
ComponentOutput5 min
Sound and beeps
The Brick has a small speaker. It can play one of the built-in sound files, or beep a note you choose. Sound is what makes a machine feel finished — and it is also a way for the robot to tell you something without you having to look at it.
The speaker is in the side of the Brick. It is the one output a person notices without looking at the robot.
Blocks reference
Block
What it does
play sound [Communication / Hello v] until done :: sound
Plays the sound and waits for it to finish before the next block runs.
start sound [Communication / Hello v] :: sound
Starts the sound and moves straight on to the next block, so the sound plays while the robot keeps working.
play beep (60) for (0.5) seconds :: sound
Plays a single note for a set time — useful for short alerts. The number is a note, not a volume: bigger means higher.
set volume to (100) % :: sound
Sets how loud everything after it will be. Worth putting at the top of a program — the Brick remembers the last volume it was given, even from somebody else’s program.
stop all sounds :: sound
Cuts off anything that is still playing, including a long sound started earlier.
Wait for it, or not
These two blocks play the very same file. The difference is what the rest of the program does while it plays — so it cannot be heard on its own, only seen. Here are both, each lifting a barrier.
play sound until done
when program starts
play sound Communication / Hello until done
A run clockwise for 1rotations
start sound
start sound Communication / Hello
A run clockwise for 1rotations
0.0suntil done0.0sstart sound
until done: warn first, then movestart sound: warn while moving
Two programs. Same sound, same movement — only the sound block is different.The sound is playing on both. On the left the program is waiting for it, so the barrier has not moved. On the right the barrier is already lifting.The sound has finished. Only now does the left barrier lift — the right one finished a moment ago, sound and movement together.Both played the warning and both lifted the barrier. One took twice as long to do it.Finished. Neither program is wrong — they are answers to two different questions.
stopped
Watch the barriers, not the clock. On the left the warning finishes before anything moves; on the right it sounds while the barrier lifts.
The bars underneath are when the speaker was on and when the motor was turning. On the left they never overlap: the program is stuck at the sound block until the file has finished, and only then does the barrier lift. On the right they overlap almost completely, and the whole job is done in half the time.
play sound until done — everything stops and waits. Use it for a warning that must be heard before something moves.
start sound — the sound and the movement happen together. Use it when the noise belongs to the movement, like a motor whirring as an arm lifts.
Why it matters
Real machines warn before they move, not after: a lift chimes before the doors close, a reversing lorry beeps while it rolls back, a level crossing sounds before the barrier drops. Getting the order right is the difference between a warning and an apology.
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.
Say this back before moving on: “A beep needs a note number and a length. Bigger number, higher note.”
What’s in this build 4 min
Look at your model and find the parts with cables. There is one. That is a very short parts list.
no hit
hit
The Touch Sensor, let go and pressed. This model only knows these two things. The sword is touching something, or it is not.
Part
What it is doing here
EV3 Intelligent Brick
Runs the program. It is also the scoring box. The speaker, the screen and the light are all on the Brick. None of them needs a cable.
Touch Sensor
At the tip of the sword. It is the only part that tells the Brick anything.
No motor
Nothing here moves by itself. A person moves the sword.
Test the tip before you program
Press the sensor at the very tip with a finger. Does it click, then spring back?
Now press the sword tip straight against a book. Does the sensor click? It must, or the sword scores nothing.
Press at an angle. Does it still click? Most builds are much worse at this. Find out before you blame your program.
Look along the sword. Is the cable taped or clipped to it? It must not catch or pull out when you lunge.
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.
Today the table has a sensor and nothing else. That is a first! Every letter port stays empty.
Part
Port
Why this one
Touch Sensor (the blade tip)
1
In this course, the Touch Sensor always goes in port 1.
Motors
none
A, B, C and D all stay empty. If something is plugged into a letter, it is not part of this model.
Speaker, screen, status light
none
All built into the Brick. Three ways to tell you things, and no cables.
Check your own build now:
Sensor cable in port 1 — a number, not a letter.
Leave the cable loose enough. A long lunge must not pull it out of the Brick.
Volume up on the Brick. Today the sound is the output.
Agree on a safe target with your group: a book, a box or a wall. Never a person, and never anybody’s face. Even a light sword can hurt.
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 suits a sword. This model gets waved about. A USB cable to a laptop is easy to trip over, or to pull off a desk.
Confirm the connection 2 min
Check the Brick icon: connected, or not.
Port 1 shows a Touch Sensor. Every other tile is empty.
Press the sword tip on your hand. Watch the port 1 tile change. Then let go, and watch it change back.
Do it once more with a fast tap, not a slow press. The tile should still show it. If a quick tap does not show, the tip is too loose. Tighten it. No program can fix a hit the sensor never felt.
A scoring machine that misses fast hits is worse than none at all. People will trust it, and it will be wrong.
Change it and test 8 min
One change at a time, and predict before each run — today, predict what it will sound like.
Change the note to 40. Then 90. Stand across the room for each one. Which can you hear best while people talk?
Change the length to 1.5 seconds. Now try two quick hits in a row. The second one is missed, because play beep holds the program while it plays.
Swap it for start playing beep (72). Predict what changes. The program does not wait now, so it is ready for the next hit at once. It is the Lesson 6 idea, in a new place.
Put the 0.3-second version back and add a set status light to [red v] after the beep, and a green one after the release. Now the machine scores with sound and light, like a real box.
Add a second, lower beep straight after the first. Try 72 then 60. Now your machine has a two-note signal. No sound file in the list could do that.
Step 2 catches people out in a real match. A long beep is not just annoying. While it plays, the scoring box cannot see the next hit. In fencing, the next hit is often only a fifth of a second away.
A signal must finish before the next thing happens. Short and high is better than long and loud.
This is what you are building: the Fencing.
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
When touch sensor is press then it will trigger a beep sound
Fullscreen it while you build — you can pause and scrub with the player's own controls.
The program, block by block
Sensor touch on port 2 · New blocks play beep · Motors none
What it does
Each press of the touch sensor plays a short tone: note 60 for 0.2 seconds. A hit
makes the brick beep, like a fencing scoring box.
A note, not a recording
Every sound so far has been a recorded file picked from a list. Play beep makes a tone
from a number instead. 60 is middle C; a bigger number is a higher note. Because it is
a number, it can be changed, which the later lessons build on.
Worth noticing
It reacts to the press, not the hold. Holding the button down beeps once. Let go and
press again for the next beep.
0.2 seconds is short on purpose. A hit should sound like a click of a tone, not a
tune.
The file has an empty when program starts block. It does nothing and can be
ignored.
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 touch sensor is pressed, it will trigger a sound, and when the touch sensor is released, it will trigger another sound different from the press sound.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
Challenge 3
- When the Center button is pressed, it starts a 20-second countdown that counts how many times the Touch Sensor is triggered to determine the highest hit score.
- While counting down, the EV3 screen shows the live time left and current hit score.
- Each sensor tap increases the hit count by 1 only while status = 1.
- When 20 seconds run out, the program sets status = 0 to lock the sensor, plays a finish sound, and displays your final score.