Build yours at home
Echo parking sensor
What we're doing
Build a parking sensor like a car's. The echo sensor sends out a sound too high for us to hear and times its echo. The closer your hand, the faster it beeps.
About 30 minutes.
Goes with these lessons
No kit? Try this
Echo hunt: clap in a stairwell, a tunnel, a big empty room and a room full of cushions. Where does the echo come back? Soft things swallow it.
Get these parts
New to breadboards? See Getting set up- The ultrasonic sensor (the echo sensor), the passive buzzer, the breadboard and jumper wires (Elegoo kit)
- The Mega and its USB cable (Elegoo kit)
- A computer with the Arduino app (see Getting set up) (household)
Keep it safe
No batteries: the USB cable powers it. Keep the Mega on a dry table.
Steps
- 1
Warm-up with no parts: stand far from a wall and clap. Listen for the echo. Move close to the wall and clap again. Which echo came back sooner?
- 2
Push the sensor's four pins into four rows, with its two round 'ears' facing out.
- 3
With jumper wires, join each sensor pin to the Mega: VCC to 5V, GND to GND, TRIG to pin 9, ECHO to pin 10. The names are printed on the sensor.
- 4
Push the buzzer's two legs into two rows. Join one leg to pin 8 and the other to a GND pin. Either way round works.
- 5
Plug in the USB cable and upload the sketch below.
- 6
Hold a hand far from the sensor and bring it slowly closer. The beeps speed up: a quick echo means something is close.
Not working? No beeps? Check TRIG is on pin 9 and ECHO on pin 10, then upload again.
- 7
Try a cushion, then a tilted book. Soft or tilted things soak up the sound or bounce it away, so the sensor can miss them.
- 8
Unplug the USB cable.
Talk while you build
- What happens to the beeps when your hand gets closer?
- Does the sensor notice a cushion as well as a wall?
Spot it at home
- Car parking beeps, bats at dusk, echoes in a tunnel or stairwell.
Where have we heard an echo?
Echo parking sketch · beeps faster as a hand gets closer
// Echo parking sensor: shorter gap between beeps when closer.
// Wiring: TRIG to pin 9, ECHO to pin 10, buzzer to pin 8 and GND.
const int TRIG = 9;
const int ECHO = 10;
const int BUZZER = 8;
void setup() {
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BUZZER, OUTPUT);
}
void loop() {
digitalWrite(TRIG, LOW); delayMicroseconds(2);
digitalWrite(TRIG, HIGH); delayMicroseconds(10); // send one ping
digitalWrite(TRIG, LOW);
long us = pulseIn(ECHO, HIGH, 30000); // echo time, give up after 30 ms
long cm = us / 58; // 58 us per centimetre, there and back
if (cm < 5 || cm > 80) cm = 80; // treat misses as far away
tone(BUZZER, 880, 60); // one short beep
delay(cm * 8 + 80); // closer hand, shorter wait
}