top of page
Writer's pictureSanskruti Ashtikar

Smart Traffic Control System using PIC Microcontroller

Traffic management is a crucial aspect of modern urban planning. With the increase in the number of vehicles on roads, efficient traffic control systems are needed to manage the flow and reduce congestion. A smart traffic control system using a PIC microcontroller can optimize traffic flow, reduce waiting times, and improve overall road safety. This article will guide you through the design and implementation of a smart traffic control system using a PIC microcontroller.


Introduction


A smart traffic control system is an automated system that controls the traffic lights at intersections based on real-time traffic conditions. Traditional traffic control systems operate on fixed time intervals, which can lead to inefficiencies. In contrast, a smart system uses sensors and microcontrollers to dynamically adjust traffic signals.


Components Required


  1. PIC Microcontroller (e.g., PIC16F877A)

  2. IR Sensors

  3. LEDs (Red, Yellow, Green)

  4. Resistors

  5. Capacitors

  6. Crystal Oscillator

  7. Connecting Wires

  8. Breadboard or PCB

  9. Power Supply


Circuit Design


  1. Microcontroller:

  2. The PIC16F877A microcontroller will be the brain of the system. It will process inputs from the sensors and control the traffic lights.

  3. Sensors:

  4. IR sensors will be placed on each road leading to the intersection. These sensors detect the presence and volume of vehicles.

  5. LEDs:

  6. LEDs will represent the traffic lights. Each road will have three LEDs: Red, Yellow, and Green.

  7. Connections:

  8. Connect the IR sensors to the input pins of the PIC microcontroller.

  9. Connect the LEDs to the output pins of the PIC microcontroller.

  10. Ensure proper grounding and power connections.


Software Design


  1. Programming Environment:

  2. Use MPLAB IDE and XC8 Compiler for programming the PIC microcontroller.

  3. Code Implementation:


#include <xc.h>
#define _XTAL_FREQ 20000000  // Define crystal oscillator frequency
// Configuration bits
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF
// Define sensor input pins
#define SENSOR1 PORTBbits.RB0
#define SENSOR2 PORTBbits.RB1
#define SENSOR3 PORTBbits.RB2
#define SENSOR4 PORTBbits.RB3
// Define LED output pins
#define RED1 PORTDbits.RD0
#define YELLOW1 PORTDbits.RD1
#define GREEN1 PORTDbits.RD2
#define RED2 PORTDbits.RD3
#define YELLOW2 PORTDbits.RD4
#define GREEN2 PORTDbits.RD5
#define RED3 PORTDbits.RD6
#define YELLOW3 PORTDbits.RD7
#define GREEN3 PORTDbits.RE0
#define RED4 PORTDbits.RE1
#define YELLOW4 PORTDbits.RE2
#define GREEN4 PORTDbits.RE3
void initialize() {
    // Set sensor pins as input
    TRISB = 0x0F; // RB0-RB3 as input
    
    // Set LED pins as output
    TRISD = 0x00; // RD0-RD7 as output
    TRISE = 0x00; // RE0-RE3 as output
    
    // Initialize all LEDs to off
    PORTD = 0x00;
    PORTE = 0x00;
}
void delay(int time) {
    // Delay function
    for (int i = 0; i < time; i++) {
        __delay_ms(1);
    }
}
void traffic_light_control() {
    if (SENSOR1) {
        GREEN1 = 1; RED2 = RED3 = RED4 = 1;
        delay(5000); // Keep green for 5 seconds
        GREEN1 = 0; YELLOW1 = 1;
        delay(2000); // Yellow for 2 seconds
        YELLOW1 = 0; RED1 = 1;
    } else if (SENSOR2) {
        GREEN2 = 1; RED1 = RED3 = RED4 = 1;
        delay(5000); // Keep green for 5 seconds
        GREEN2 = 0; YELLOW2 = 1;
        delay(2000); // Yellow for 2 seconds
        YELLOW2 = 0; RED2 = 1;
    } else if (SENSOR3) {
        GREEN3 = 1; RED1 = RED2 = RED4 = 1;
        delay(5000); // Keep green for 5 seconds
        GREEN3 = 0; YELLOW3 = 1;
        delay(2000); // Yellow for 2 seconds
        YELLOW3 = 0; RED3 = 1;
    } else if (SENSOR4) {
        GREEN4 = 1; RED1 = RED2 = RED3 = 1;
        delay(5000); // Keep green for 5 seconds
        GREEN4 = 0; YELLOW4 = 1;
        delay(2000); // Yellow for 2 seconds
        YELLOW4 = 0; RED4 = 1;
    }
}
void main() {
    initialize();
    while (1) {
        traffic_light_control();
    }
}

Working


  1. Initialization:

  2. The microcontroller is initialized by setting the sensor pins as inputs and the LED pins as outputs. All LEDs are initially turned off.

  3. Traffic Light Control Logic:

  4. The system continuously monitors the inputs from the IR sensors.

  5. When a sensor detects vehicles, the corresponding traffic light turns green, and all others turn red.

  6. The green light is maintained for a fixed duration (e.g., 5 seconds), followed by a yellow light (e.g., 2 seconds), and then red.

  7. This cycle repeats for each sensor in sequence based on vehicle detection.

  8. Dynamic Adjustment:

  9. The system dynamically adjusts the traffic light duration based on real-time traffic conditions, ensuring smooth traffic flow.


Advantages


  1. Reduced Congestion:

  2. By dynamically adjusting traffic lights, the system reduces congestion and waiting times at intersections.

  3. Improved Safety:

  4. The system improves road safety by preventing traffic jams and reducing the likelihood of accidents.

  5. Energy Efficient:

  6. The system is energy-efficient as it optimizes the operation of traffic lights based on actual traffic conditions.


Conclusion


A smart traffic control system using a PIC microcontroller offers an efficient solution to manage urban traffic. By leveraging real-time data from sensors, the system can dynamically adjust traffic lights, reducing congestion and improving safety. The implementation of such systems can significantly enhance the efficiency of urban traffic management and contribute to the development of smart cities.

This article provides a comprehensive overview of the design and implementation of a smart traffic control system using a PIC microcontroller. With proper planning and execution, such systems can be deployed to create a more efficient and safer traffic environment.


Want us to guide you through your project or make the project for you ?






Create Various Projects

Check out our Free Arduino Projects Playlist - Arduino Projects 

Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects 

Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects 

Check out our Free IoT Projects Playlist - IoT Projects 

Check out our Free Home Automation Projects Playlist - Home Automation Projects 

Check out our Free NodeMCu Projects Playlist - NodeMCu Projects 


0 views0 comments

Related Posts

See All

Comentarios


bottom of page