This project implements a smart traffic signal system using Arduino UNO, ultrasonic distance sensors, and LED signals. The system controls traffic signals at a junction by dynamically adjusting the signal timing based on the presence of vehicles detected by the ultrasonic sensors.
- 2 x Arduino UNO R3
- 4 x Red LEDs
- 4 x Yellow LEDs
- 4 x Green LEDs
- 1 x 1 kΩ Resistor
- 4 x Ultrasonic Distance Sensors (HC-SR04)
- Jumper wires
- Breadboard
- Arduino UNO
- Ultrasonic Distance Sensors (4x HC-SR04)
- SoftwareSerial Library
-
Initialization:
- Initializes ultrasonic sensor pins, serial communication, and other required variables.
-
Ultrasonic Sensor Readings:
- Reads distance values from four ultrasonic sensors placed on each road.
- Calculates distance in centimeters and adjusts for sensor offset.
-
Vehicle Detection and Signal Transmission:
- If a vehicle is detected within 80 cm range on a road, the Arduino sends a corresponding signal (1 to 4) to the receiver.
- If no vehicle is detected on any road, it sends a signal (5) indicating no vehicles.
-
Serial Communication:
- Prints distance values and transmits signals to the Serial Monitor for debugging.
- Utilizes SoftwareSerial library for communication on custom RX and TX pins.
- Arduino UNO
- LEDs (12x: 4 Red, 4 Yellow, 4 Green)
- SoftwareSerial Library
-
Initialization:
- Initializes LED pins, serial communication, and other required variables.
-
Signal Reception:
- Listens for signals received from the transmitter via SoftwareSerial.
- Determines the state of the traffic signal based on the received signal.
-
Traffic Signal Control:
- Dynamically adjusts traffic signals based on the received signal:
- Signals 1 and 4 activate the first set of signals.
- Signals 2 and 3 activate the second set of signals.
- Signal 5 turns off all signals, indicating no vehicles.
- Dynamically adjusts traffic signals based on the received signal:
-
Signal Timing Simulation:
- Simulates the passage of time with a seconds counter to control the signal transition.
-
Serial Communication:
- Prints received signals and corresponding actions to the Serial Monitor for debugging.
-
Clone the repository:
git clone https://github.com/your-username/traffic-signal-system.git
-
Download and upload the code to an Arduino Uno if you have a physical microcontroller. Otherwise, you can use an online simulation tool such as Tinkercad.
# For physical Arduino boards open Arduino IDE
# For Tinkercad simulation open Tinkercad and import the Arduino code.
- Upload the
transmitter_vehicle_detector.ino
code to one Arduino UNO board. - Upload the
receiver_traffic_signal_output.ino
code to the other Arduino UNO board. - Power on both Arduino boards.
- Monitor the Serial Monitor for debugging information.
Feel free to contribute to the project by opening issues or submitting pull requests. Your feedback and contributions are highly appreciated.
For support, discord me - #_wikkie_
.
This project is licensed under the MIT License - see the LICENSE file for details.