Abrish Fatimaaah
Published © GPL3+

Arduino Distance Indicator

An Arduino-based distance indicator that uses an HC-SR04 ultrasonic sensor and colorful LEDs to visualize object distance in real time.

BeginnerFull instructions provided1 hour30
Arduino Distance Indicator

Things used in this project

Hardware components

Male/Male Jumper Wires
×15
Resistor 220 ohm
Resistor 220 ohm
×10
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
Arduino UNO
Arduino UNO
×1
USB-A to Mini-USB Cable
USB-A to Mini-USB Cable
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit diagram

Here’s the wiring behind the project! πŸ”Œβš‘ The Arduino UNO is connected to the HC-SR04 ultrasonic sensor and 8 LEDs through a breadboard and resistors. The sensor detects the distance, while the Arduino processes it and controls the LEDs to create the visual distance indicator. 🌈

Assembly

I assembled the project on a breadboard by connecting the Arduino UNO, HC-SR04 ultrasonic sensor, 8 LEDs, and current-limiting resistors using jumper wires. The LEDs were arranged according to their colors (blue β†’ green β†’ yellow β†’ red) to make the distance indication easy to understand. After completing the connections, I checked the wiring and tested the circuit with the Arduino to make sure everything responded correctly.

Result

The project successfully detected the distance of an object using the HC-SR04 ultrasonic sensor and displayed the result through the LEDs. As the object moved closer to the sensor, the LEDs changed accordingly from blue β†’ green β†’ yellow β†’ red. The system responded in real time and worked as expected during testing. 🚦🌈

Seeing the LEDs respond to my hand movement was honestly the most satisfying part! πŸ˜‚βš‘ This small project gave me a fun hands-on experience with Arduino, sensors, and basic embedded system logic.

Video

A quick demonstration of my Arduino Distance Indicator! 🚦 As the object moves closer to the HC-SR04, the LEDs change from blue β†’ green β†’ yellow β†’ red in real time.

Code

Code

C/C++
This Arduino code controls the HC-SR04 ultrasonic sensor and the LED distance indicator. It measures the distance of an object and uses different distance ranges to control the blue, green, yellow, and red LEDs. As the object gets closer, the LED indication changes accordingly, providing a simple visual representation of distance.
const int trigPin = 11;
const int echoPin = 12;
long duration;
int distanceCm, distanceInch;
void setup()
{

Serial.begin(9600); 
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);



}
void loop() 
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;
Serial.println("Distance: ");
Serial.println(distanceCm);
delay(100);

if(distanceCm <6)
{
  digitalWrite(3,HIGH);
}
if(distanceCm >6)
{
  digitalWrite(3,LOW);
}

if(distanceCm <10)
{
  digitalWrite(4,HIGH);
}

if(distanceCm >10)
{
  digitalWrite(4,LOW);
}

if(distanceCm <15)
{
  digitalWrite(5,HIGH);
}

if(distanceCm >15)
{
  digitalWrite(5,LOW);
}


if(distanceCm <19)
{
  digitalWrite(6,HIGH);
}

if(distanceCm >19)
{
  digitalWrite(6,LOW);
}

if(distanceCm <23)
{
  digitalWrite(7,HIGH);
}

if(distanceCm >23)
{
  digitalWrite(7,LOW);
}


if(distanceCm <27)
{
  digitalWrite(8,HIGH);
}

if(distanceCm >27)
{
  digitalWrite(8,LOW);
}

if(distanceCm <30)
{
  digitalWrite(9,HIGH);
}

if(distanceCm >30)
{
  digitalWrite(9,LOW);
}

if(distanceCm <34)
{
  digitalWrite(10,HIGH);
}

if(distanceCm >34)
{
  digitalWrite(10,LOW);
}
}

Credits

Abrish Fatimaaah
4 projects β€’ 1 follower

Comments