What it shows
An ultrasonic sensor measures distance from the time an echo takes to return. The Arduino turns this distance into LED steps and a beeping speed, like the sensor in a car bumper.
The science
The sensor sends a 40 kHz sound pulse and times the echo. Sound travels about 343 m/s, or 0.0343 cm per microsecond, and the sound goes there and back, so distance in cm is the echo time in microseconds divided by 58. The program maps distance ranges to LEDs and sets the pause between beeps shorter as the distance falls, with a continuous tone below 10 cm.
Materials
Cost: under Rs 1,500. Many items come from home or from waste; spare parts such as LEDs, motors and wire are in the store.
- An Arduino Uno or compatible board with a USB cable
- An HC-SR04 ultrasonic sensor
- A piezo buzzer (active)
- Green, yellow and red LEDs with three 220 Ω resistors
- A breadboard and jumper wires
- A cardboard toy car or box to mount the sensor
Safety
For this project: Powered from a USB port or a laptop only. Check the sensor power wires before plugging in, because reversed 5 V and ground can damage the module.
Never use mains electricity: power models with cells, batteries or a low-voltage adapter. Sharp and hot tools, flames and lab chemicals need an adult or your teacher beside you. Keep magnets, button cells and small parts away from young children, and wash your hands after making.
All the safety rulesStep by step
8 steps. Do them in order, and test each part before you go on to the next. Write what you notice in a notebook as you go.
Connect the sensor VCC to 5 V, GND to GND, TRIG to pin 9 and ECHO to pin 10.
Connect the buzzer positive to pin 8 and its negative to GND.
Connect the green, yellow and red LEDs, each with a 220 Ω resistor, to pins 5, 6 and 7 and to GND.
In the sketch, send a 10 microsecond pulse on TRIG and use pulseIn on ECHO to get the time; divide by 58 to get centimetres.
Light green for more than 60 cm, yellow from 30 to 60 cm, and red below 30 cm.
Make the buzzer beep with a delay equal to the distance in cm multiplied by 5 milliseconds, and stay on below 10 cm.
Open the Serial Monitor at 9600 baud to check the distances against a ruler.
Move a book towards the sensor, and tune the distances so the steps feel natural.
What you should see
The LEDs change from green to red and the beeps become faster as the object approaches, with distance readings accurate to about a centimetre.
Viva questions
A teacher or a judge will ask how it works. Try to answer each question before you open it, then compare.
1Why divide the echo time by 58?
Sound travels about 0.0343 cm per microsecond and covers the distance twice, to and from the object.
2What frequency does the sensor use?
About 40 kHz, which is ultrasonic and not heard by people.
3What can make the reading wrong?
Soft cloth, a slanted surface or very small objects absorb or reflect the sound away.
4Why use pulseIn?
It measures how long a pin stays high, which is the echo time.
Take it further
Add a small OLED display that shows the distance in centimetres in large digits.
Change one thing, measure what happens, and add a table or chart of your readings: that is what turns a model into your own investigation.
