Project 2.7.2: Backing Distance Meter
| Description | This project uses an ultrasonic sensor to measure proximity and displays the distance zone using a Traffic Light Module (Green=Safe, Yellow=Caution, Red=Danger). |
|---|---|
| Use case | This project can be used in automation systems, interactive installations, and embedded control applications. |
Components (Things You will need)
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|---|---|---|---|---|---|
Building the circuit
Things Needed:
- Arduino Uno = 1
- Arduino USB cable = 1
- Ultrasonic sensor = 1
- Traffic light module = 1
- Jumper wires
- Breadboard = 1
Mounting the component on the breadboard
Step 1: Place the Ultrasonic sensor and the Traffic light module on the breadboard.

WIRING THE CIRCUIT
Step 2: Connect the VCC pin of the sensor to the 5V pin on the Arduino using a male-to-male jumper wire.

Step 3: Connect the GND pin of the sensor to the GND pin on the Arduino using a male-to-male jumper wire.

Step 4: Connect the TRIG pin of the ultrasonic sensor to Digital Pin 9 on the Arduino using a male-to-male jumper wire.

Step 5: Connect the ECHO pin of the ultrasonic sensor to Digital Pin 10 on the Arduino using a male-to-male jumper wire.

Step 6: Connect the Green LED pin to Digital Pin 4 on the Arduino using a male-to-male jumper wire.

Step 7: Connect the Yellow LED pin to Digital Pin 5 on the Arduino using a male-to-male jumper wire.

Step 8: Connect the RED LED pin to Digital Pin 6 on the Arduino using a male-to-male jumper wire.

Step 9: Connect the GND pin of the module to the GND pin on the Arduino using a male-to-male jumper wire.

NB: Make sure all components are securely placed on the breadboard with correct orientation.
Make sure to connect the Arduino USB cable to the Arduino board.
PROGRAMMING
Step 1: Open your Arduino IDE. See how to set up here: Getting Started.
Step 2: Type the following code in your Arduino IDE: const int trigPin = 9;, const int echoPin = 10;, const int greenLED = 4;, const int yellowLED = 5;, const int redLED = 6;, long duration;, float distance; as shown in the image below.

Step 3: Type the following code in your Arduino IDE inside the void setup() pinMode(trigPin, OUTPUT);, pinMode(echoPin, INPUT);, pinMode(greenLED, OUTPUT);, pinMode(yellowLED, OUTPUT);, pinMode(redLED, OUTPUT);, Serial.begin(9600); as shown in the image below.

Step 4: Type the following code in your Arduino IDE inside the void loop() digitalWrite(trigPin, LOW);, delay(2000);, digitalWrite(trigPin, HIGH);, delay(10000);, digitalWrite(trigPin, LOW);, duration = pulseIn(echoPin, HIGH); as shown in the image below.

Step 5: Type the following code in your Arduino IDE inside the void loop() distance = duration * 0.0343 / 2;, Serial.print("Distance: ");, Serial.print(distance);, Serial.println(" cm");, if (distance > 30) {, digitalWrite(greenLED, HIGH);, digitalWrite(yellowLED, LOW);, digitalWrite(redLED, LOW); } as shown in the image below.

Step 6: Type the following code in your Arduino IDE inside the void loop() else if (distance > 15 && distance <= 30) {, digitalWrite(greenLED, LOW);, digitalWrite(yellowLED, HIGH);, digitalWrite(redLED, LOW); } as shown in the image below.

Step 7: Type the following code in your Arduino IDE inside the void loop() else {, digitalWrite(greenLED, LOW);, digitalWrite(yellowLED, LOW);, digitalWrite(redLED, HIGH); }, delay(200) as shown in the image below.

Uploading the code
Step 1: Save your code. See the Getting Started section
Step 2: Select the Arduino board and port. See the Getting Started section
Step 3: Upload your code.
CONCLUSION
This project helps learners understand how to combine multiple components with Arduino to create more complex interactive systems and automation solutions.





