انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Maker: home
0. Lab tour1
1. The start: the Arduino6
2. Wiring and the traffic light4
3. Inputs: the button4
4. Sound and movement5
5. Sensors and numbers5
6. Distance, the screen and colours5
7. Motors and the car4
8. The project: the city's smart gate3
9. From blocks to C++ code5
10. Sensors and screens in code5
11. Smart systems5
12. Bluetooth: control from the phone1

The distance sensor

Section 6: Distance, the screen and coloursLesson 6.1 · ⏱ 8 min

The distance sensor (ultrasonic) sends a sound we can't hear and catches its echo, like a bat, so it knows how far the obstacle is in centimetres.

🧩 The distance alarm
Blocks: loop — repeats forever
🖥️ What happens on the stage?
When something comes closer than 20 cm, the buzzer rings.

📌 Another example: an alarm with a note

If something comes closer than 20 cm, the buzzer beeps.

🧩 An alarm with a note
Blocks: loop — repeats forever
Far (50): silent
Far (50): silent
Close (10): beeping
Close (10): beeping
✍️ Practise
Print the distance on the Serial.
✍️ Practise here in the lessonor open the lab in a new page ↗
✍️ Practise
Build the distance alarm.
✍️ Practise here in the lessonor open the lab in a new page ↗

🎯 Challenge yourself

Easy

Close (below 30): the LED is red, otherwise green.

👀 Show the solution
🧩 Solution
Blocks: loop — repeats forever
In the lab
In the lab

Result: green, then red.

Medium

Print the distance on the Serial.

👀 Show the solution
🧩 Solution
Blocks: setup — runs once, loop — repeats forever
In the lab
In the lab

Result: the distance appears in centimetres.

Hard

The closer the thing, the faster it beeps: the wait = the distance × 10.

👀 Show the solution
🧩 Solution
Blocks: loop — repeats forever
In the lab
In the lab

Result: fast beeping when it gets close.

Finished the lesson? Mark it so your progress counts.