An embedded 8051 microcontroller-based traffic light control system with pedestrian signals and automatic streetlight control using LDR.
- Overview
- Features
- Tech Stack
- Architecture
- Getting Started
- Project Structure
- Pin Configuration
- Code Explanation
- Modifying the Code
- Troubleshooting
- Contributing
- License
This project implements a Traffic Light Control System using an 8051 microcontroller (AT89S52). The system manages traffic lights at a 4-way intersection, controls pedestrian signals, and automatically adjusts streetlight intensity based on ambient light using an LDR sensor.
Traffic.Light.Controller.mp4
- 5 traffic light sets (Red, Yellow, Green) for intersection management
- Synchronized signal timing with smooth transitions
- Configurable delay timings for each phase
- 2 pedestrian signal sets (Red, Green)
- Synchronized with traffic light sequence for safe crossing
- LDR-based ambient light detection
- Automatic streetlight ON/OFF control
- Energy-efficient operation
| Layer | Technologies |
|---|---|
| Microcontroller | AT89S52 (8051 family) |
| Language | Embedded C |
| IDE | Keil µVision |
| Programmer | USBasp / Custom 8051 programmer |
┌─────────────────────────────────────────────────────────────────────┐
│ TRAFFIC LIGHT CONTROL SYSTEM │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────────────────────────────────┐ │
│ │ LDR │───>│ │ │
│ │ (Sensor) │ │ AT89S52 MICROCONTROLLER │ │
│ └──────────────┘ │ │ │
│ │ P1: Traffic Lights 1-3 (T1, T2, T3) │ │
│ │ P3: Traffic Lights 4-5 + Pedestrian 1 │ │
│ │ P0: Pedestrian 2 + LDR + Streetlight │ │
│ │ │ │
│ └──────────────────────────────────────────┘ │
│ │ │
│ ┌───────────────────────┼──────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ ┌──────────────┐ │
│ │ Traffic Lights │ │ Pedestrian Lights│ │ Streetlight │ │
│ │ (T1-T5: RGB) │ │ (P1, P2: RG) │ │ (LED) │ │
│ └──────────────────┘ └──────────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────┘
- System initializes all lights and enters main control loop
- Traffic lights cycle through 4 phases, each with red→green→yellow transitions
- Pedestrian signals synchronize with traffic phases for safe crossing
- LDR continuously monitors ambient light to control streetlight
-
Hardware:
- 8051 Development Board with AT89S52 microcontroller
- 10mm LEDs (Red, Yellow, Green)
- Light Dependent Resistor (LDR)
- Resistors (current limiting)
- Jumper cables
- Power supply (5V)
-
Software:
- Keil µVision (C51 Compiler)
- 8051 programmer software
- Connect Traffic Light LEDs to Port P1 and P3 as per pin configuration
- Connect Pedestrian Signal LEDs to Port P3 and P0
- Connect LDR to P0.2 (with voltage divider circuit)
- Connect Streetlight LED to P0.3
- Refer to the schematic below for detailed connections
-
Clone the repository
git clone https://github.com/tanishqmudaliar/Traffic-Light-Controller.git cd Traffic-Light-Controller -
Open in Keil µVision
- Launch Keil µVision
- Open
project.uvproj
-
Build the project
- Press
F7or go toProject → Build Target - Verify no compilation errors
- Press
-
Flash to microcontroller
- Connect your programmer
- Use the generated
Objects/project.hexfile - Flash using your preferred programmer software
Traffic-Light-Controller/
├── Listings/
│ ├── project.lst # Listing file
│ └── project.m51 # Map file
├── Objects/
│ ├── project.hex # Compiled HEX (flash this!)
│ ├── project.obj # Object file
│ └── project.build_log.htm # Build log
├── project.c # Main source code
├── project.uvproj # Keil project file
├── project.uvopt # Keil options
├── SCHEMATIC.png # Circuit schematic
├── LICENSE # MIT License
└── README.md # Documentation
| Signal | Pin | Function |
|---|---|---|
| T1_R | P1.2 | Traffic Light 1 - Red |
| T1_Y | P1.1 | Traffic Light 1 - Yellow |
| T1_G | P1.0 | Traffic Light 1 - Green |
| T2_R | P1.5 | Traffic Light 2 - Red |
| T2_Y | P1.4 | Traffic Light 2 - Yellow |
| T2_G | P1.3 | Traffic Light 2 - Green |
| T3_R | P3.0 | Traffic Light 3 - Red |
| T3_Y | P1.7 | Traffic Light 3 - Yellow |
| T3_G | P1.6 | Traffic Light 3 - Green |
| T4_R | P3.3 | Traffic Light 4 - Red |
| T4_Y | P3.2 | Traffic Light 4 - Yellow |
| T4_G | P3.1 | Traffic Light 4 - Green |
| T5_R | P3.5 | Traffic Light 5 - Red |
| T5_G | P3.4 | Traffic Light 5 - Green |
| Signal | Pin | Function |
|---|---|---|
| P1_R | P3.6 | Pedestrian 1 - Red |
| P1_G | P3.7 | Pedestrian 1 - Green |
| P2_R | P0.0 | Pedestrian 2 - Red |
| P2_G | P0.1 | Pedestrian 2 - Green |
| Component | Pin | Function |
|---|---|---|
| LDR | P0.2 | Ambient light sensor input |
| LED | P0.3 | Streetlight output |
| Function | Description |
|---|---|
main() |
Initializes system, runs infinite control loop cycling through traffic phases |
delay(unsigned int) |
Generates software delay while continuously checking LDR |
streetlight() |
Reads LDR and controls streetlight LED based on ambient light |
Phase 1: T1 & T5 GREEN (Pedestrian 1 GREEN) → 5s → Yellow → 3s
Phase 2: T2 GREEN → 5s → Yellow → 3s
Phase 3: T3 GREEN → 5s → Yellow → 3s
Phase 4: T4 GREEN (Pedestrian 2 GREEN) → 5s → Yellow → 3s
[Repeat]
Modify delay values in the main loop:
delay(500); // Green phase duration (adjust multiplier)
delay(300); // Yellow phase durationModify the sequence order in the while(1) loop in main().
Edit the streetlight() function logic:
void streetlight()
{
if (LDR == 0) // Bright (LDR low resistance)
LED = 0; // Streetlight OFF
else // Dark (LDR high resistance)
LED = 1; // Streetlight ON
}- Ensure C51 compiler is installed
- Check
reg51.hheader path in project settings
- Verify pin connections match the code definitions
- Check LED polarity and current-limiting resistors
- Test LEDs individually with direct power
- Check LDR circuit (voltage divider configuration)
- Verify P0.2 is configured as input
- Check programmer connections
- Ensure microcontroller is powered
- Verify correct HEX file path
Contributions are welcome! Please feel free to submit pull requests or open issues.
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -m 'Add improvement') - Push to the branch (
git push origin feature/improvement) - Open a Pull Request
This project is open source and available under the MIT License.
Made with ❤️ for learning embedded systems
Control traffic, save lives! 🚦
