The Radar Device: an Ultrasonic Sensor on a Medium Motor. It turns slowly from side to side. At each step, it tells you what it finds.
You have used sensors like a doorbell before. Wait until the button is pressed. Then do the next thing. The program stopped. The sensor let it go on.
That is not what a radar does. A radar never waits. It keeps turning. At every angle it asks, “How far is the thing in front of me?” Then it writes the answer down.
In the real world 5 min
Where you have seen it
The slowly turning dish next to an airport runway. It goes round once every few seconds, all day. Some people guide the planes in. From that one dish, they can see every plane for a hundred kilometres.
The radar station at Zagreb Airport. Photo: WizardOfOz / Wikimedia Commons (CC BY-SA 3.0).
Why it is built that way
The dish can only look one way at a time. So it turns. Every reading is two facts, not one. How far away is it? And which way was the dish pointing? Distance alone is not enough. A plane 40 km away could be anywhere, until you know which way.
Your radar has both. The distance comes from the Ultrasonic. The direction comes from the motor’s degrees counter. You have watched it count on the port tile. Today the program reads it. Those two together make the radar.
What would go wrong without it
Some sensor blocks only wait for a trigger. A trigger is a sign that says “now”. That kind of sensor cannot make a map. “Something is close” tells you to stop. It does not tell you where the gap is. Or which side is clearer. Or how big the room is. Robots that find their own way read numbers. They do not just wait for triggers.
A trigger tells you when. A reading tells you how much. And you can compare how much.
The big idea — asking instead of waiting 6 min
The Ultrasonic Sensor is new today. It gives you a number in centimetres. It does this any time you ask.
([4 v] distance in [cm v]) :: sensors
A reporter, just like timer on the Stop Watch in Lesson 35. It is round. That is because it is a number, not an order.
Here are the two ways to use the sensor:
Block
Shape
What it does to the program
[4 v] wait until distance < (15) cm
Stack
Stops everything until it is true. The program is frozen. You learn just one thing. It happened.
([4 v] distance in [cm v])
Reporter
Stops nothing. It gives you the number right now. The program carries straight on.
Put the reporter into a display block. Now the Brick can measure things:
write ([4 v] distance in [cm v]) at line (3) :: display
Centimetres on the screen, right now. Wave your hand in front of the sensor. Watch it change.
Two numbers make a position
One reading on its own is not much. Take a reading at every step as it turns. Write it next to the motor’s angle. Now you have a map of the room:
Angle
Distance
What that means
0°
62 cm
Far wall, straight ahead.
30°
18 cm
Something close, this way. Something is in the way.
60°
65 cm
Clear again. The thing in the way was thin.
The program did not stop and wait for anything. Three angles and three numbers. Now you know a thin object is about 30° to one side.
ComponentSensing6 min
The Ultrasonic Sensor
The Ultrasonic Sensor measures distance. It sends out a burst of sound too high for people to hear, listens for the echo, and works out how far away the surface is from how long the echo took — exactly how a bat finds a moth, and how a submarine uses sonar.
front
side
The two round openings on the front are the point of this sensor: one sends the burst of sound out, the other listens for the echo coming back.
Blocks reference
Block
What it does
([4 v] distance in [cm v] :: sensors)
Reports how far away the nearest thing in front of the sensor is, as a number in centimetres.
wait until <([4 v] distance in [cm v] :: sensors) < (15)>
Holds the program until something comes closer than 15 cm.
A number, not a yes or no
This is the important step up from the Touch Sensor. Touch gives you true or false; the Ultrasonic gives you a number, and the deciding is left to you. Pick a threshold below and watch where the robot ends up.
when program starts
start moving straight: 0
4 wait until distance <15cm
stop moving
60cm · reading15cm · threshold
Nothing is close. The sensor reports about 60 cm and the program waits.The robot drives forward. The sensor is sending a burst of sound and timing its echo, over and over, and the number falls.The reading has dropped past the threshold. The condition is true, so the robot stops.Try another threshold. The program is identical — only that one number is different.Finished. The threshold is yours to choose — the sensor only supplies the number.
stopped
The black line on the bar is the threshold; the blue fill is the reading. The robot stops the instant the fill crosses the line.
Three different robots, and only one number is different between them. That is what having a number rather than a yes-or-no buys you: the behaviour is tuned by editing one slot, not by rebuilding the program. It also means the sensor can never tell you it is “close” — close is a decision you make about a reading.
Why it matters
Car parking sensors, automatic doors at a shopping centre, and the sensor that stops a lift door closing on somebody all work this way. Reacting before contact is what makes a machine feel safe.
If your set has an Infrared Sensor instead
The Home/Retail EV3 set (31313) ships an Infrared Sensor and a Beacon in place of the Ultrasonic and Gyro sensors. The Infrared Sensor also measures distance, so the programs in this module work with it — but it reports a rough 0–100 proximity rather than real centimetres, and it is affected by sunlight and by dark surfaces in ways the Ultrasonic is not.
IR Sensor
Beacon
The Infrared Sensor and its Beacon, from the Home set. If your kit has these, expect proximity numbers rather than centimetres — and retune any threshold accordingly.
Stop waiting for the sensor to stop you. Start asking it for a number.
▶The motor's degree counterThe motor's own counter. It gives the angle for every reading here.Show meHide
ComponentSensing5 min
Reading a motor's position
Every EV3 motor contains a sensor that counts how far it has actually turned. That means a motor is not only an output — you can ask it where it is, and the answer describes what really happened rather than what you asked for.
The counting happens inside the motor housing, on this shaft. That is why the reading describes what the motor did — not necessarily what the robot did, if a wheel slipped.
Blocks reference
Block
What it does
([A v] degrees counted :: sensors)
Reports how far this motor has actually turned since the count was last reset, in degrees.
[A v] reset degrees counted :: motors
Sets the count back to zero, making right here the new reference point.
([A v] speed :: sensors)
Reports how fast the motor is turning right now, as a percentage. A motor that is being driven but reads zero is a motor that is stuck.
Asked for, versus achieved
Those two are not always the same. Here are two identical motors, running the same program, with only their mechanisms different.
Both motors are told to turn two rotations — 720 degrees. Both counters start at zero.Both turning. The counters climb together, and so far the two motors agree.The right-hand arm has run into the post and cannot go past it. The motor is still straining against it, the counter has stopped, and the program is still waiting on that block.The left motor finished at 720. The right is stuck at 284 — it never got past the post, and that gap is the only way the robot can tell.Finished on the left. The right-hand program is still waiting, and will wait for ever.
stopped
Nothing on the Brick announces a stall. The only evidence is that the counter stopped changing while the motor was still being told to turn.
Nothing on the Brick announces the jam. The motor is still being driven, the program is still sitting on the same block, and the only trace of the problem anywhere is a counter that has stopped climbing. Comparing what you asked for with what was counted is how a robot notices — which is the whole of stall detection.
Zero is wherever you say it is
When the Brick powers on, the count is simply whatever it happens to be. It is not a position on the machine — it becomes one only when you tie it to something physical.
That is what reset degrees counted is for, and it is not just a tidy-up block for the top of a program. Where you put it decides what zero means, so putting it part-way through — after the mechanism has been driven somewhere known — is the normal way to use it, not an abuse of it.
Find home first, then reset
A conveyor has no idea where it is. Give it a touch sensor at one end and it can find out: drive it until the sensor is pressed, and it is now at a place you can name. Only then reset the count, and that end becomes 0.
when program starts :: events hat
[A v] start motor [counterclockwise v] :: motors
[1 v] wait until [pressed v] :: sensors
[A v] stop motor :: motors
[A v] reset degrees counted :: motors
The order is the whole point. Reset before the sensor is pressed and you have zeroed a random spot; reset after it, and every later reading means “how far from home”. This is called homing, and it is why a printer rattles its head to one side when you switch it on.
Drive towards home gently. The mechanism is deliberately being run into its own end stop, so a slow speed saves the gears — and the touch sensor is what stops it, which means it stops in the same place every time regardless of where it started.
Putting zero somewhere more useful
Home is often a corner, and a corner is an awkward place to measure from. Say the conveyor carries a chute that dispenses bricks, and you would rather describe its position as left and right of the middle. Then home once, drive the known distance to the middle, and reset again there:
when program starts :: events hat
[A v] start motor [counterclockwise v] :: motors
[1 v] wait until [pressed v] :: sensors
[A v] stop motor :: motors
[A v] reset degrees counted :: motors
[A v] run [clockwise v] for (900) [degrees v] :: motors
[A v] reset degrees counted :: motors
Now the middle is 0. Moving right counts up, moving left counts down past zero into negative numbers — the count is perfectly happy to go negative — and “go back to the middle” becomes the simplest instruction in the program: drive until the count reaches 0.
Both resets earn their place. The first one turns a meaningless number into a distance from a real, repeatable place. The second one moves zero to where the maths is easiest. A reset in the middle of a program is only a mistake when the mechanism is somewhere you cannot name.
Turning turns into distance
Because the count is in degrees, and a wheel of known size travels a known distance per turn, the reading can be converted into how far the robot has actually driven. That is how a robot reports a distance in centimetres rather than in rotations — and it is why changing the wheels changes the answer.
Why it matters
This is how a printer knows the paper jammed, how a car window stops when it meets your hand, and how a robot arm knows it has reached its limit. A machine that can only give orders is fragile; one that can check what happened can recover.
Say this out loud before you move on: “A reading does not stop the program.”
What’s in this build 4 min
Part
What it is doing here
EV3 Intelligent Brick
Puts each distance with its angle, and shows both on screen.
Medium Motor — the turntable
Turns the sensor from side to side. We use the Medium Motor, not the Large one. It turns almost no weight. So it needs to be exact, not strong.
Ultrasonic Sensor
The two “eyes” are a speaker and a microphone. It sends a click you cannot hear. Then it times the echo. That is why it measures distance, not colour or light.
The Brick speaker
One ping for each step. You can hear the rhythm without watching.
What the sensor can and cannot see
Sound does not bounce back off everything the same. Learn this now. It will save you lots of muddle later.
Hold a book flat in front of the sensor, about 30 cm away. Watch the reading. Now tilt the book a lot. The reading gets worse or goes away. The echo is bouncing away, not back.
Try a soft jumper or a cushion. Soft things soak up the click. They read badly, or not at all.
Point it at nothing, out across the room. It shows its biggest number, 255 cm.
Hold your hand right up against it. Very close readings are wrong too. There is a smallest number as well as a biggest.
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
Turntable (Medium Motor)
A
A motor with its own job. It gives the direction for every reading.
Ultrasonic Sensor
4
In this course, Ultrasonic always goes in port 4. That is true in every lesson and level.
Check your own build now:
Motor in A, Ultrasonic in 4.
The sensor must sit flat and face out. If it tilts down, it measures the table. Then every reading will be about 10 cm. It will not matter what is in the room.
Check the sensor cable is loose. It must turn all the way and back without pulling. If the radar winds up its own cable, it will get stuck halfway.
Put the radar in the middle of an empty space. Put two objects near it. Measure how far away they are.
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 is best here. You will read the Brick screen while the sensor turns. A USB cable keeps the Brick by the laptop. Then you cannot see it.
Confirm the connection 2 min
Look at the Brick icon. Is it connected?
A Medium Motor on A and an Ultrasonic on 4.
Wave your hand in front of the sensor. Watch its tile change. This is the biggest check in the lesson. Everything today needs that number to change.
Turn the motor by hand. Watch tile A count. Now you know both parts of every reading work.
Change it and test 8 min
Keep one object in the same place for all of these. Then you are testing the radar, not moving the room around.
Change the step to 15 degrees and the loop to 12. The same 180°, with twice as many readings. Can you see better where the object is?
Change the step to 60 degrees and the loop to 3. It turns fast, in big steps. Put a thin object in front of it. Can the radar miss it?
Delete the wait (0.3) seconds. Now it never stops turning. The sensor is never still. Do the readings get worse?
Inside the loop, move the distance write block. Put it before the motor block. Now each reading is taken at the angle before. The screen shows each distance with the wrong angle. It is hard to spot, and totally wrong.
Make a real map. Run the radar. Write all six angles and distances on paper. Then draw them as dots on a fan shape. That drawing is a map of your room, made by a robot!
People argue about step 2. Big steps are faster. But they can miss a chair leg and still look right. Every real radar has to choose. The answer is never “as much as you can get”. It is “enough for what I am looking for”.
A reading only helps if you know which way the robot pointed.
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.
This is what you are building: the Radar Device.
Make it move 10 min
Set the motor speed to 20%
When Up button is pressed, motor will turn clockwise.
When Down button is pressed, motor will turn counterclockwise.
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
Set the motor speed to 20%
- When Center button is pressed, motor will turn counterclockwise here with one full round.
- After waiting for 1 second, it will turn clockwise back to start point.
- After waiting for 1 second, repeat this continuous loop.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
Challenge 2
Set the motor speed to 20%
- When the Center button is pressed, the motor continuously turns counterclockwise for one full round, then turns clockwise back to the start point. (refer to challenge 1)
- If the ultrasonic sensor detect an object closer than 10 cm, the motor will stop, play a sound "Information/Detected" and exit the program.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
Challenge 3
Set the motor speed to 20%
- When the center button is pressed, continuously repeat the sweeping loop and set direction to -20, reset degrees counted, and start the motor at direction % speed until degrees counted is less than -1080. Stop the motor and wait for 1 second.
- Set direction to 20, reset degrees counted, and start the motor at direction % speed until degrees counted is greater than 1080. Stop the motor and wait for 1 second.
- If the ultrasonic sensor detects an object closer than 10 cm, the motor will stop and play the sound "Information/Detected".
- The motor will pause until the object moves further than 10 cm away, then automatically resume starting the motor at direction % speed.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
Extra challenge
Set the motor speed to 20%
- When the Center button is pressed, continuously repeat the sweeping loop (refer to Challenge 3).
- If the ultrasonic sensor detects an object close than 10 cm, the motor stops.
- Calculate the angle using [current_angle] (adjusting for direction so it counts up when moving left and down when returning) and [display_degree] so the value stays between 0° and 360°.
- Clear the display and write Degree: [display_degree] at position (1, 50) using large black font.
- The status light turns red and play the sound "Information/Detected"
- When the object moves further than 10 cm away, set the status light to green and resume starting the motor at direction % speed.
Fullscreen it while you build — you can pause and scrub with the player's own controls.
Log in to see hints.
The program, block by block
Motors A · Speed 20% · Sensors none
What it does
Turns the EV3 brick into a hand controller for the radar dish. Up turns the motor
clockwise, Down turns it counterclockwise, and letting go of every button stops it.
Nothing is automatic. There is no loop and no sensor, so the dish only moves while a person
is holding a button. Each press starts the motor; only the release handler ends it.
Worth noticing
Start, not run for. Both buttons use start motor, which runs until told otherwise.
That is why holding Up keeps the dish turning for as long as you hold it.
Speed is set once. The set speed to 20% block sits under when program starts, so
every press after that uses it. There is nowhere else to look.
The release handler is load-bearing. Its dropdown says no, meaning no button is
being held. It is not the centre button. Remove it and a started motor never stops.