A simple Arduino project that uses an HC-SR04 Ultrasonic Sensor to measure distance and indicate the object's position using three LEDs.
- Measures distance using the HC-SR04 Ultrasonic Sensor
- Displays distance in the Serial Monitor
- Uses 3 LEDs for visual distance indication:
- 🟢 Green LED → Object is far away (> 20 cm)
- 🟡 Yellow LED → Object is at medium distance (10–20 cm)
- 🔴 Red LED → Object is close (< 10 cm)
- Real-time distance updates every 100 ms
| Component | Quantity |
|---|---|
| Arduino Uno | 1 |
| HC-SR04 Ultrasonic Sensor | 1 |
| LEDs (Green, Yellow, Red) | 3 |
| 220Ω Resistors (Optional) | 3 |
| Jumper Wires | Several |
| Breadboard | 1 |
| Sensor Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| TRIG | D9 |
| ECHO | D10 |
| LED | Arduino Pin |
|---|---|
| Green LED (Far) | D2 |
| Yellow LED (Medium) | D3 |
| Red LED (Close) | D4 |
- Long leg (Anode) → 220Ω Resistor → Arduino Pin
- Short leg (Cathode) → GND
| Distance | LED Status |
|---|---|
| Greater than 20 cm | Green LED ON |
| 10 cm to 20 cm | Yellow LED ON |
| Less than 10 cm | Red LED ON |
Only one LED is active at a time.
Upload the provided Arduino sketch to your Arduino Uno using the Arduino IDE.
The program:
- Sends an ultrasonic pulse from the HC-SR04 sensor.
- Receives the reflected pulse.
- Calculates the distance in centimeters.
- Prints the distance to the Serial Monitor.
- Turns on the corresponding LED based on the measured distance.
Distance: 35.42 cm
Distance: 18.76 cm
Distance: 7.84 cm
LED Response:
35 cm → Green LED ON
18 cm → Yellow LED ON
7 cm → Red LED ON
- Obstacle Detection
- Parking Assistance Systems
- Distance Monitoring
- Robotics Projects
- Smart Safety Systems
- Educational Arduino Projects
- Assemble the circuit according to the wiring diagram.
- Open the Arduino IDE.
- Connect the Arduino Uno to your computer.
- Upload the code.
- Open the Serial Monitor.
- Move an object in front of the sensor and observe the LEDs change based on distance.
- Add a buzzer for audible alerts.
- Display distance on an LCD or OLED screen.
- Implement RGB LED indication.
- Add Bluetooth or Wi-Fi monitoring.
- Log distance measurements to a computer.
This project is open-source and available under the MIT License.
Built with Arduino Uno and HC-SR04 Ultrasonic Sensor for simple distance detection and visual indication.