Smart Street Lighting with Ultrasonic Sensor
Project Overview:
In this project, I used an Arduino UNO, four LEDs, and an ultrasonic sensor.
The ultrasonic sensor works as the input component, while the LEDs are the output components.
How it works:
When an object (like a car or a person) passes in front of the sensor at a distance less than 20 cm, the Arduino turns on the LEDs one by one in sequence, just like smart street lights that respond to movement.
If no object is detected, all the LEDs remain off.
Why I Care About This Project:
I’m very excited to work with the ultrasonic sensor because it’s simple yet very useful.
It works by sending pulses through the trigger pin and receiving them through the echo pin to measure distance.
What’s interesting here is programming the lights to respond only when an object is detected, which saves energy and creates a realistic smart street lighting effect.
Inspiration:
The idea is inspired by real-life smart street lighting systems that turn on only when cars or people are nearby.
It’s also related to obstacle-avoiding robots that use the same kind of sensors.
Software
I used Tinkercad to simulate the circuit and make sure it works correctly, without errors or damage to components 🙂.
I used Arduino IDE to write the code and upload it directly to the Arduino UNO.
Materials
1- I opened Tinkercad in my browser.
2- Logged in using my email.
3- Started by creating a new circuit for testing
Second: Creating the Circuit
1- I searched for the components I needed:
a- Arduino UNO R3
b- Small Breadboard
c- 4 LEDs
d- 4 resistors (220 Ω each)
e- Ultrasonic Distance Sensor (4 Pins: VCC, Trig, Echo, GND)
2- I placed the 4 LEDs on the breadboard.
3- Since each LED requires only ~2V but Arduino pins provide 5V, I added a 220 Ω resistor in series with the cathode (negative leg) of each LED.
4- The other side of the resistor was connected to the ground rail with a black wire.
5- I connected the positive legs of the LEDs to the Arduino pins:
LED1 → Pin 11
LED2 → Pin 10
LED3 → Pin 9
LED4 → Pin 8
6- For the Ultrasonic Sensor:
VCC → 5V on Arduino
GND → Arduino Ground
Trigger → Pin 6
Echo → Pin 5
A- Setting the Input
1- Defined Trigger and Echo pins in the code.
2- The ultrasonic sensor sends a pulse through Trigger and receives it on Echo to measure distance.
3- Used a function readUltrasonicDistance to calculate the distance.
B- Setting the Output with Conditions
4- I used an if condition to control the LEDs.
5- If the measured distance is less than 20 cm → LEDs turn on sequentially (one after another).
C- LED Sequence
6- LED1 turns ON for 1 second, then OFF → LED2 ON, and so on until LED4.
7- If no object is detected within range, all LEDs remain OFF.
After completing the wiring and coding:
1- I connected my Arduino UNO to my laptop using a USB cable.
2- Opened the Arduino IDE and wrote my code.
3- From the Tools menu, I selected the correct board (Arduino UNO) and the right port.
4- Before uploading, I clicked the Verify button to check for any errors.
5- Then, I clicked the Upload button to send the code to the Arduino.
6- Within a few seconds, the circuit came to life: the ultrasonic sensor started measuring distance, and the LEDs turned on one by one according to the programmed conditions.
I prepared an Arduino UNO, a medium breadboard, 4 LEDs (with 220Ω resistors), and an HC-SR04 ultrasonic sensor.
I also prepared a set of jumper wires for the connections.
I connected the 5V pin from the Arduino to the positive rail (+) on the breadboard.
I connected the GND pin from the Arduino to the ground rail (–) on the breadboard.
I made sure that all grounds in the circuit were unified on the same rail.
I placed the four LEDs on the breadboard in a row.
For each LED:
The negative leg (cathode) was connected to a 220Ω resistor, then to the ground rail.
The positive leg (anode) was connected to the Arduino pins as follows:
LED 1 → Pin D11
LED 2 → Pin D10
LED 3 → Pin D9
LED 4 → Pin D8
I placed the ultrasonic sensor on the breadboard with its pins facing the Arduino.
The connections were:
VCC → 5V on the Arduino
GND → Ground rail on the breadboard
Trig → Pin D6 on the Arduino
Echo → Pin D5 on the Arduino
I checked that each LED had a resistor in series.
I made sure all grounds were connected properly.
I used different wire colors (just like in the Tinkercad diagram) to avoid confusion.
I connected the Arduino UNO to the laptop using a USB cable.
I opened the Arduino IDE software.
I selected the correct board (Arduino UNO) and the right port.
I verified the code and then uploaded it to the board.
Once the code was uploaded, the ultrasonic sensor started measuring distance.
When an object (like my hand or a small car toy) came closer to the sensor:
The LEDs turned on one by one, depending on the distance.
When the object moved away, the LEDs turned off again.
Problem: The first LED did not work during testing.
Solution: After checking all the connections and trying several times, I discovered that the problem was with the jumper wire itself, as it was not conducting electricity properly. Once I replaced the wire, the LED worked normally.
Other than this issue, I did not face any problems while building or running the circuit.