Skip to content

About

Raspberry Pi traffic-light simulation using Python and GPIO-controlled LEDs.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Traffic Light Project (Raspberry Pi)

This project simulates a basic traffic light using three LEDs connected to a Raspberry Pi.

🔧 Hardware Setup

GPIO Pin Connections

LED Color GPIO Pin
Red GPIO 22
Yellow GPIO 27
Green GPIO 18

Each LED is connected with a separate resistor (220Ω–330Ω) to GND.

Circuit

GPIO → LED → Resistor → GND


How to Run

python3 traffic_light.py


## **Development Notes**

This project was improved step-by-step using Git branches.

### Basic traffic light
- Simple sequential control using direct GPIO output

### Refactoring (traffic-light-functions)
- Introduced `set_light(red, yellow, green)` function
- Reduced code duplication
- Made logic easier to read and extend

### State machine refactor
- Created a `traffic-light-state-machine` branch
- Refactored the traffic light sequence into a simple state machine
- Added `current_state` to track the active light state
- Added `run_state()` to control each state and return the next state
- This structure makes the project easier to extend with features such as pedestrian button input

About

Raspberry Pi traffic-light simulation using Python and GPIO-controlled LEDs.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages