top of page
Writer's pictureSanskruti Ashtikar

Vehicle Over Speed Detection System Using PIC Microcontroller

Introduction


Road safety is a critical concern worldwide, and speeding is one of the leading causes of road accidents. Monitoring vehicle speed and enforcing speed limits can significantly reduce the number of accidents. In this article, we will discuss the development of a Vehicle Over Speed Detection System using a PIC microcontroller. This system can be implemented on roads to automatically detect vehicles exceeding the speed limit and trigger an alert or take necessary actions.


Overview of the Project


The Vehicle Over Speed Detection System uses sensors to measure the speed of a vehicle. The system compares this speed with a predefined speed limit, and if the vehicle is found to be overspeeding, it triggers an alert. The heart of this system is a PIC microcontroller, which processes the data from the sensors and controls the alert mechanism.


Components Required


  • PIC Microcontroller (PIC16F877A): The central processing unit that controls the entire system.

  • IR Sensors: Used to detect the presence of a vehicle at specific points on the road.

  • LCD Display: To display the speed of the vehicle and any alerts.

  • Buzzer/LED: To provide a visual or audible alert when a vehicle is overspeeding.

  • Oscillator (Crystal and Capacitors): Provides the necessary clock signal to the microcontroller.

  • Power Supply: To power the microcontroller and other components.

  • Resistors, Capacitors, and Diodes: Additional components for circuit stability and protection.

  • Connecting Wires: For making connections between different components.

  • Breadboard/PCB: For assembling the circuit.


Circuit Diagram


Below is a basic circuit diagram for the vehicle over speed detection system:


IR Sensor 1  -->  PIC16F877A  -->  LCD Display
IR Sensor 2  -->              -->  Buzzer/LED
              |                |
        Oscillator          Power Supply
  1. IR Sensors to PIC Microcontroller:

  2. Two IR sensors are placed at a known distance apart on the road. The outputs of these sensors are connected to input pins on the PIC microcontroller.

  3. The sensors' Vcc and GND are connected to the power supply.

  4. PIC Microcontroller to LCD Display and Buzzer/LED:

  5. The output pins of the PIC16F877A are connected to the LCD display for speed indication and to a buzzer/LED for alerting when the speed exceeds the limit.

  6. Power Supply:

  7. The PIC microcontroller, sensors, and other components are powered by a suitable DC power supply, typically 5V.


Working Principle


  1. Vehicle Detection:

  2. The system uses two IR sensors placed a known distance apart. When a vehicle passes the first sensor, the microcontroller starts a timer.

  3. When the vehicle passes the second sensor, the microcontroller stops the timer.

  4. Speed Calculation:

  5. The microcontroller calculates the speed of the vehicle using the formula: Speed (km/h)=(Distance (meters)Time (seconds))×3.6\text{Speed (km/h)} = \left(\frac{\text{Distance (meters)}}{\text{Time (seconds)}}\right) \times 3.6Speed (km/h)=(Time (seconds)Distance (meters)​)×3.6

  6. The calculated speed is displayed on the LCD.

  7. Speed Comparison:

  8. The calculated speed is compared with a predefined speed limit stored in the microcontroller.

  9. If the vehicle's speed exceeds the limit, the microcontroller triggers the buzzer/LED to alert authorities or the driver.


Programming the PIC Microcontroller


The microcontroller is programmed using Embedded C or Assembly language. Below is an example of a basic code snippet in Embedded C for this project:


#include <pic16f877a.h>
#include <lcd.h> // Assumed LCD library for easy interfacing
#define IR_Sensor1 RB0
#define IR_Sensor2 RB1
#define Buzzer RB2
// Function prototypes
void init_system();
void delay(unsigned int ms);
float calculate_speed(float distance, float time);
void main() {
    float time_taken = 0;
    float speed = 0;
    float distance = 2.0; // Distance between sensors in meters
    unsigned int timer_value = 0;
    
    init_system();
    
    while(1) {
        if (IR_Sensor1 == 1) { // Vehicle passed first sensor
            TMR1 = 0; // Reset Timer1
            TMR1ON = 1; // Start Timer1
            while(IR_Sensor2 == 0); // Wait for vehicle to reach second sensor
            TMR1ON = 0; // Stop Timer1
            timer_value = TMR1; // Capture Timer1 value
            time_taken = (float)timer_value / 1000; // Convert to seconds
            speed = calculate_speed(distance, time_taken);
            lcd_clear();
            lcd_set_cursor(1,1);
            lcd_print("Speed:");
            lcd_print_float(speed);
            lcd_print("km/h");
            
            if (speed > 60.0) { // Speed limit check
                Buzzer = 1; // Turn on buzzer
                lcd_set_cursor(2,1);
                lcd_print("Over Speed!");
                delay(5000);
                Buzzer = 0; // Turn off buzzer
            }
            delay(2000);
        }
    }
}
void init_system() {
    TRISB = 0x03; // Set RB0, RB1 as input, RB2 as output
    PORTB = 0x00; // Initialize PORTB
    lcd_init(); // Initialize LCD
    T1CON = 0x10; // Set up Timer1
    Buzzer = 0; // Turn off buzzer
}
float calculate_speed(float distance, float time) {
    return (distance / time) * 3.6; // Speed in km/h
}
void delay(unsigned int ms) {
    unsigned int i, j;
    for(i = 0; i < ms; i++)
        for(j = 0; j < 1275; j++);
}

Explanation of the Code


  • TRISB: Configures PORTB pins as input or output.

  • IR_Sensor1, IR_Sensor2: Represent the IR sensor input pins.

  • Buzzer: Represents the output pin connected to the buzzer.

  • TMR1: A timer used to measure the time taken by the vehicle to travel between the two sensors.

  • calculate_speed(): A function to calculate the vehicle’s speed based on the time taken and distance between the sensors.

  • The main loop continuously checks for vehicles passing the first IR sensor. When detected, the system measures the time taken to reach the second sensor, calculates the speed, and checks it against the speed limit.


Advantages of the System


  • Real-time Monitoring: Provides real-time speed monitoring and alerts, helping in enforcing speed limits.

  • Accident Prevention: By detecting and alerting about over-speeding vehicles, the system can contribute to accident prevention.

  • Scalability: The system can be easily scaled or modified to include features like data logging or integration with traffic cameras.


Conclusion


A Vehicle Over Speed Detection System using a PIC microcontroller is a valuable tool for enhancing road safety. By following the steps outlined in this article, you can build your own over-speed detection system, which can be deployed in various environments to monitor and control vehicle speeds effectively. This project not only demonstrates the practical application of microcontrollers in real-world problems but also offers a foundation for more advanced traffic management systems.


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 


3 views0 comments

Related Posts

See All

Comments


bottom of page