Skip to content

tanishqmudaliar/Traffic-Light-Controller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Traffic Light Control System

An embedded 8051 microcontroller-based traffic light control system with pedestrian signals and automatic streetlight control using LDR.

C Keil µVision License


Table of Contents


Overview

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.


Demo

Traffic.Light.Controller.mp4

Features

Traffic Control

  • 5 traffic light sets (Red, Yellow, Green) for intersection management
  • Synchronized signal timing with smooth transitions
  • Configurable delay timings for each phase

Pedestrian Safety

  • 2 pedestrian signal sets (Red, Green)
  • Synchronized with traffic light sequence for safe crossing

Streetlight Automation

  • LDR-based ambient light detection
  • Automatic streetlight ON/OFF control
  • Energy-efficient operation

Tech Stack

Layer Technologies
Microcontroller AT89S52 (8051 family)
Language Embedded C
IDE Keil µVision
Programmer USBasp / Custom 8051 programmer

Architecture

┌─────────────────────────────────────────────────────────────────────┐
│                    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)     │    │
│   └──────────────────┘   └──────────────────┘   └──────────────┘    │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Flow Description

  1. System initializes all lights and enters main control loop
  2. Traffic lights cycle through 4 phases, each with red→green→yellow transitions
  3. Pedestrian signals synchronize with traffic phases for safe crossing
  4. LDR continuously monitors ambient light to control streetlight

Getting Started

Prerequisites

  • 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:

Hardware Setup

  1. Connect Traffic Light LEDs to Port P1 and P3 as per pin configuration
  2. Connect Pedestrian Signal LEDs to Port P3 and P0
  3. Connect LDR to P0.2 (with voltage divider circuit)
  4. Connect Streetlight LED to P0.3
  5. Refer to the schematic below for detailed connections

Schematic Diagram

SCHEMATIC.png

Software Setup

  1. Clone the repository

    git clone https://github.com/tanishqmudaliar/Traffic-Light-Controller.git
    cd Traffic-Light-Controller
  2. Open in Keil µVision

    • Launch Keil µVision
    • Open project.uvproj
  3. Build the project

    • Press F7 or go to Project → Build Target
    • Verify no compilation errors
  4. Flash to microcontroller

    • Connect your programmer
    • Use the generated Objects/project.hex file
    • Flash using your preferred programmer software

Project Structure

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

Pin Configuration

Traffic Light LEDs

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

Pedestrian Signal LEDs

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

Sensors & Output

Component Pin Function
LDR P0.2 Ambient light sensor input
LED P0.3 Streetlight output

Code Explanation

Main Functions

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

Traffic Sequence Logic

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]

Modifying the Code

Adjust Signal Timings

Modify delay values in the main loop:

delay(500);  // Green phase duration (adjust multiplier)
delay(300);  // Yellow phase duration

Change Traffic Sequence

Modify the sequence order in the while(1) loop in main().

Modify Streetlight Behavior

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
}

Troubleshooting

"Build failed" in Keil

  • Ensure C51 compiler is installed
  • Check reg51.h header path in project settings

LEDs not turning ON

  • Verify pin connections match the code definitions
  • Check LED polarity and current-limiting resistors
  • Test LEDs individually with direct power

Streetlight not responding to light changes

  • Check LDR circuit (voltage divider configuration)
  • Verify P0.2 is configured as input

HEX file won't flash

  • Check programmer connections
  • Ensure microcontroller is powered
  • Verify correct HEX file path

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/improvement)
  3. Commit your changes (git commit -m 'Add improvement')
  4. Push to the branch (git push origin feature/improvement)
  5. Open a Pull Request

License

This project is open source and available under the MIT License.


Made with ❤️ for learning embedded systems

Control traffic, save lives! 🚦

About

An embedded control system for a 4-way intersection using the 8051 microcontroller, featuring synchronized pedestrian signals and automatic LDR-based street lighting.

Topics

Resources

License

Stars

Watchers

Forks

Contributors