https://github.com/maklonfr/iot-traffic-light
Traffic Light Controller with MicroPython
https://github.com/maklonfr/iot-traffic-light
iot-application micropython python rasberry-pi trafic-light
Last synced: 6 months ago
JSON representation
Traffic Light Controller with MicroPython
- Host: GitHub
- URL: https://github.com/maklonfr/iot-traffic-light
- Owner: MaklonFR
- Created: 2025-04-03T17:59:20.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2025-04-03T18:03:55.000Z (6 months ago)
- Last Synced: 2025-04-09T16:17:57.607Z (6 months ago)
- Topics: iot-application, micropython, python, rasberry-pi, trafic-light
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Traffic Light Controller with MicroPython
Youtube Link:
https://www.youtube.com/shorts/b71Qk9Rgh4Y## Overview
This project is a simple traffic light controller implemented using MicroPython. It controls LEDs to simulate traffic signals for four different lanes.## Hardware Requirements
- A microcontroller that supports MicroPython (e.g., Raspberry Pi Pico, ESP32)
- LEDs (Red, Yellow, Green) for each lane
- Resistors (220Ω recommended)
- Breadboard and jumper wires## Wiring Configuration
Each lane has three LEDs (Red, Yellow, Green) connected to specific GPIO pins:| Lane | Red Pin | Yellow Pin | Green Pin |
|--------|--------|------------|-----------|
| Jalur 1 | 1 | 2 | 3 |
| Jalur 2 | 5 | 8 | 9 |
| Jalur 3 | 10 | 11 | 12 |
| Jalur 4 | 13 | 14 | 15 |## Code Explanation
- The `traffic_lights` dictionary stores the GPIO pin configuration for each lane.
- The `all_red()` function ensures that all lanes start with a red signal.
- The `traffic_cycle(jalur)` function controls the signal timing:
- Sets all lights to red
- Turns green for the selected lane for 5 seconds
- Changes to yellow for 2 seconds before switching back to red
- The `while True` loop cycles through all four lanes in sequence.## Usage
1. Load the script onto your MicroPython-compatible board.
2. Connect the LEDs and power up the board.
3. The traffic lights will cycle automatically.## Future Improvements
- Add pedestrian crossing functionality
- Implement sensors for traffic density detection
- Integrate with IoT for remote monitoring## License
This project is open-source and free to use for educational and personal projects.