This project implements a Traffic Light Control System on STM32 which controls 4 traffic lights at an intersection. The system dynamically adapts to vehicle presence and count.
🔹 Finite-State Machine (FSM): Manages traffic light states and transitions for real-time control.
🔹 Dynamic Signal Timing: Adjusts signal timing based on vehicle presence and count.
🔹 GPIO Interrupts: Utilizes interrupt-driven button presses for vehicle counting.
🔹 RGB LED Control: Drives traffic light simulating LEDs using GPIO outputs.
🔹 Bare-Metal Firmware: Implemented in C using direct register access for efficiency.
🔹 Event-Driven Architecture: Low-power idle until vehicle detection enables real-time processing.
| | │ | |
south-bound| | │ | |
traffic | |⬇️│ |⬆️|
| | │ | |
|⬇️| │⬆️| |
── ── ── ── ─
🚥
_ _ _ _ _ _ _ . Light 2 ._ _ _ _ _ _ _ _ _ west-bound
_ _ _ ⬅️ _ _ | 🚦|_⬅️ _ _ _ _ _ _ _ traffic
___________⬅️_| Light 3 |_______⬅️________
east-bound _ _ _➡️ _ _ _ |🚦 |_➡️ _ _ _ _ _ _ _
traffic _ _ _ _ _➡️ _ |Light 1 |_ _ _ _ ➡️_ _ _ _
🚥 Light 4
── ── ── ── ─
|⬇️| │ |⬆️|
| | │ | | north-bound
| |⬇️│⬆️| | traffic
| | │ | |
| | │ | |
Light 1
and Light 3
are synchronized, operating in tandem to manage east-west traffic flow.
Light 2
and Light 4
are synchronized, controlling north-south traffic flow.
other outputs above...
Light 1-3: RED (east-west traffic stopped)
Light 2-4: GREEN (north-south traffic allowed)
Light 1 car detected: 1
Light 1 car detected: 2
Light 1 car detected: 3
Light 2-4: YELLOW (caution, changing soon)
Light 2-4: RED (north-south traffic stopped)
Light 1-3: GREEN (east-west traffic allowed)
... continues with other outputs
🕹️ Microcontroller Development
⎔ VS Code - Primary code editor for STM32 firmware development
⎔ OpenOCD - Used for flashing and debugging over SWD
⎔ Makefile - Handles compilation, linking, and build automation
⚙️ Hardware
⎔ STM32 MCU - Microcontroller used to control the traffic light system
⎔ RGB LEDs - Simulate the traffic lights
• Used Red and Green LEDs; combined them to create Yellow
⎔ Resistors - Used to limit current and protect components
⎔ Breadboards - Used for prototyping and testing the traffic light system
RGB LED Connections:
• Common anode pins connected to ground (active-low configuration)
• Red and green channels driven by dedicated GPIO outputs
• Yellow state achieved by simultaneously activating both red and green channels
Button Connections:
• Tactile switches connected to GPIO input pins with internal pull-up resistors
• Pressing a button pulls the input low, triggering a vehicle detection interrupt
LIGHT | RED | GREEN | BUTTON |
---|---|---|---|
Light 1 | PB10 | PB4 | PC10 |
Light 2 | PB5 | PB3 | PC11 |
Light 3 | PB2 | PB1 | PC12 |
Light 4 | PB14 | PB13 | PC13 |