Introduction
Traffic lights are essential components of modern urban infrastructure that regulate vehicular flow at intersections by assigning right-of-way to specific directions. This project demonstrates how to simulate a basic traffic light system using the STM32F401RETx microcontroller and Proteus software.
The goal is to validate the control logic and hardware configuration in a virtual environment before physical deployment, ensuring cost-effective and error-free testing.
Hardware and Software Requirements
Hardware
- 📦 STM32F401RETx microcontroller
- 💡 Six LEDs (for simulation in Proteus)
- 🔌 Resistors (330Ω) for each LED
Software
- 💻 STM32CubeIDE for code development and configuration
- 🔧 Proteus Professional 8 for circuit design and simulation
Development Process
-
STM32CubeIDE Configuration
Configure the microcontroller's clock speed, memory, and GPIO pins for traffic light control.
-
Program Development
Develop the C program in
main.c
to cycle through traffic light states (red, yellow, green) using HAL library functions.void update_traffic_light( GPIO_PinState Red1, GPIO_PinState Yellow1, GPIO_PinState Green1, GPIO_PinState Red2, GPIO_PinState Yellow2, GPIO_PinState Green2, uint32_t delay ) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, Red1); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_1, Yellow1); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_2, Green1); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, Red2); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, Yellow2); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, Green2); HAL_Delay(delay); }
-
Building and Downloading
Compile the program into a HEX file for Proteus simulation using STM32CubeIDE's build function.
-
Proteus Schematic Design
Design a schematic with the STM32F401RE microcontroller and virtual LEDs in Proteus.
-
Importing HEX File
Load the compiled HEX file into the Proteus microcontroller model.
-
Simulation
Run the simulation to verify that virtual LEDs illuminate according to the programmed sequence.
Implementation Details
GPIO Pin Configuration
- PA0 → Red Light (Intersection 1)
- PA1 → Yellow Light (Intersection 1)
- PA2 → Green Light (Intersection 1)
- PB3 → Red Light (Intersection 2)
- PB4 → Yellow Light (Intersection 2)
- PB5 → Green Light (Intersection 2)
Traffic Light Sequence
while (1) {
// Phase 1: Red1 ON, Green2 ON
update_traffic_light(
GPIO_PIN_SET, GPIO_PIN_RESET, GPIO_PIN_RESET,
GPIO_PIN_RESET, GPIO_PIN_RESET, GPIO_PIN_SET,
5000
);
// Phase 2: Yellow1 ON
update_traffic_light(
GPIO_PIN_RESET, GPIO_PIN_SET, GPIO_PIN_RESET,
GPIO_PIN_RESET, GPIO_PIN_RESET, GPIO_PIN_SET,
2000
);
// Phase 3: Green1 ON, Red2 ON
update_traffic_light(
GPIO_PIN_RESET, GPIO_PIN_RESET, GPIO_PIN_SET,
GPIO_PIN_SET, GPIO_PIN_RESET, GPIO_PIN_RESET,
5000
);
// Phase 4: Yellow2 ON
update_traffic_light(
GPIO_PIN_RESET, GPIO_PIN_RESET, GPIO_PIN_SET,
GPIO_PIN_RESET, GPIO_PIN_SET, GPIO_PIN_RESET,
2000
);
}
Results and Conclusion
The project successfully simulated a traffic light system using STM32CubeIDE and Proteus. The virtual LEDs illuminated according to the programmed sequence, confirming that the control logic worked as expected.
Key achievements:
- ✅ Successfully configured STM32F401RETx microcontroller for traffic light control
- ✅ Developed optimized code using function-based approach to reduce redundancy
- ✅ Verified functionality through Proteus simulation before physical implementation
- ✅ Demonstrated effective hardware-software integration for embedded systems
Future Enhancements
This project can be extended with additional features, such as:
- 🚦 Integration of real-time traffic data for adaptive timing
- 🚶 Addition of pedestrian crossing signals
- 🚑 Implementation of emergency vehicle detection and priority
- 📡 Wireless communication for coordinating multiple intersections
- 📊 Data logging and traffic pattern analysis capabilities