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.

🖥️ 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.



✍️ Practise
Print the distance on the Serial.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
✍️ Practise
Build the distance alarm.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Close (below 30): the LED is red, otherwise green.
👀 Show the solution🙈 Hide the solution


Result: green, then red.
Medium
Print the distance on the Serial.
👀 Show the solution🙈 Hide the solution


Result: the distance appears in centimetres.
Hard
The closer the thing, the faster it beeps: the wait = the distance × 10.
👀 Show the solution🙈 Hide the solution


Result: fast beeping when it gets close.

