To book the project Click Here

Introduction

In our fast-paced world, road safety remains a paramount concern. Highway speed checking is an important task for traffic police to ensure the safety of Drivers and the people on road side walking. It is also used to collect data on traffic flow and to enforce speed limits. Highways, where vehicles tend to travel at higher speeds, pose an increased risk of accidents. Monitoring and controlling vehicle speeds on highways is essential to ensure the safety of all road users. In this article, we’ll explore how to build a simple highway speed checker using an 8051 microcontroller, an IR sensor, and a 16×2 LCD display. This project not only demonstrates the application of microcontrollers in traffic management but also promotes road safety.

Components Required

Before we delve into the project’s details, let’s gather the components we’ll need:

  • 8051 microcontroller (AT89S52 or similar)
  • 16×2 LCD display
  • Infrared (IR) sensor module
  • Motor (to simulate vehicle movement)
  • Connecting wires
  • Breadboard or PCB (Printed Circuit Board)
  • 5V power supply
  • Resistors (10k ohms and 330-470 ohms)
  • LED (for indicator)
  • Crystal oscillator (12 MHz)
  • Capacitors (22pF)
  • Pushbuttons (for user input, optional)
  • Voltage regulator (7805, if not using a regulated power supply)
  • Transistor (BC547 or similar)
  • Relay (12V )

Project Overview

The project aims to create a speed checker system that can measure the speed of a moving vehicle on a highway using an IR sensor. The system calculates the speed based on the time taken by the vehicle to cross two defined points, usually a known distance apart. The 8051 microcontroller processes this information and displays the vehicle’s speed on a 16×2 LCD display. Here’s a step-by-step guide on how to build this system:

Video Demonstration of the Project:-

Simple Highway Speed Checker with 8051 Microcontroller, IR Sensor, and 16×2 LCD

Step 1: Hardware Connections

Before we start coding, let’s make the necessary hardware connections:

  1. Connect the 8051 microcontroller to the power supply (5V). Make sure to connect the Vcc and GND pins correctly.
  2. Connect a 12 MHz crystal oscillator and two 22pF capacitors to the microcontroller’s oscillator pins (XTAL1 and XTAL2).
  3. Connect the IR sensor module to one of the microcontroller’s digital pins (P1.0). Ensure that you connect the sensor’s Vcc and GND pins appropriately.
  4. Connect the 16×2 LCD display to the microcontroller. You will need to connect power, ground, and data pins accordingly.
  5. Connect an LED through a current-limiting resistor to another digital pin (P1.1) for indicating the presence of a vehicle.
  6. Optionally, you can connect pushbuttons for user input (e.g., resetting the system).
  7. If you’re using a motor to simulate vehicle movement, connect it to another digital pin (P1.2).
  8. Connect the transistor (BC547) to control the motor, as the microcontroller pins might not provide enough current to drive it.
  9. Relay i have provided to connect for extra output after speed threshold crossed.

PCB & Circuits Diagram:

Step 2: Coding the Microcontroller

Now that the hardware is set up, it’s time to write the code for the 8051 microcontroller. We will use an embedded C language and an Integrated Development Environment (IDE) like Keil .

The code will involve:

  1. Initializing the microcontroller’s ports and peripherals.
  2. Configuring the IR sensor and defining the logic for detecting vehicle passage.
  3. Calculating the vehicle’s speed based on the time taken to cross the IR sensor.
  4. Displaying the speed on the 16×2 LCD display.
  5. Optionally, handling user input through pushbuttons.

Here’s a simplified code outline:

#include<reg51.h>
#define dataport P0
#define key P3

sbit rs = P2^7;
sbit rw = P2^6;
sbit en = P2^5;	

		

sbit start = P1^0 ;	// First IR Sensor 
sbit cross = P1^1 ;	// Second IR Sensor
sbit reset = P1^2 ;	


sbit green = P3^0 ;
sbit red = P3^1 ;	
sbit buzzer = P3^2 ;	


		

sbit relay = P2^0 ;	





void delay(unsigned int msec) //Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0;j<112;j++);
}

void lcd_cmd(unsigned char item) //Function to send command to LCD
{
dataport = item;
rs= 0;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data(unsigned char item) // Function to send data to LCD
{
dataport = item;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;
return;
}

void lcd_data_string(unsigned char *str)  // Function to send string to LCD
{
int i=0;
while(str[i]!='\0')
{
  lcd_data(str[i]);
  i++;
  //delay(10);
}
return;
}

void lcd(unsigned char str[10])  // Function to send string to LCD
{
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_data_string(str);
}
			 
  unsigned long int second =0;
  float speed  =0.0;






void main()
{
unsigned char p=0;

unsigned int d1=0,d2=0,d3=0,d=0, counter =0;

 relay =1;
 buzzer =1;
 red =0;
 green =0;


lcd_cmd(0x38);
lcd_cmd(0x0C);
 lcd_cmd(0x01);

 /*

lcd_cmd(0x82);
lcd("    WELCOME");
lcd_cmd(0xC0);
lcd("       TO");
delay(1000);


 lcd_cmd(0x01);
lcd_cmd(0x80);
lcd(" Highway Speed");
lcd_cmd(0xC0);
lcd("     Cheker");
delay(1500);

*/

while(1)
{

  relay =1;
 buzzer =1;
 red =0;
 green =0;
lcd_cmd(0x01);
lcd_cmd(0x80);
lcd("  Waiting For");
lcd_cmd(0xC0);
lcd("Vehicle Detection");

 while(start==0);
 delay(10);
 if(start==1)
 {
 
 lcd_cmd(0x01);
lcd_cmd(0x80);
lcd("  Vehicle");
lcd_cmd(0xC0);
lcd("  Detected");


 while(cross==0)
 {
 delay(10);
 second++;
 }

 second = second / 100 ;

  // counter = second / 3 ;
 //  second = second + counter ;
   lcd_cmd(0x01);
   lcd_cmd(0x80);


  d = second ;  // 275	
  d1 =  d % 10; //5
  d= d / 10; //27 
  d2= d%10;	   // 7
  d	= d / 10 ; // 2
  d3= d% 10; // 2

  dataport = 0x30+d3;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);

dataport = 0x30+d2;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);


dataport = 0x30+d1;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);

lcd("   seconds");



d1=d2=d3=d=0;

speed = (100 * 3.6 ) / second  ;	  // 100 meter here is distance			//  4 is added conversion of m/s to Km/s ;

 //speed =( speed * 4 );	


  d = speed ;  // 275

  d1 =  d % 10; //5
  d= d / 10; //27 
  d2= d%10;	   // 7
  d	= d / 10 ; // 2
  d3= d% 10; // 2

 
   lcd_cmd(0xC0);

dataport = 0x30+d3;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);

dataport = 0x30+d2;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);


dataport = 0x30+d1;
rs= 1;
rw=0;
en=1;
delay(1);
en=0;  
delay(10);

lcd("   km/hr");


 if(speed >= 90)
 {

 buzzer=0;
 red=1;
 green=0;
 relay = 0;
 while(reset==1);
 relay = 1;
  buzzer=relay=1; 
   
 }

 else 
 {	  
 buzzer=relay=1;
 red=0;
 green=1;  
 }

delay(2500);


  }	 

  
  }



}   

This code serves as a template. You’ll need to fill in the details based on your microcontroller and LCD specifications. Ensure that you configure the timer(s) for accurate speed measurement.

Step 3: Testing and Calibration

After coding the microcontroller, it’s time to test the system. Place the IR sensor at a suitable location where it can detect passing vehicles. The system will detect vehicles, calculate their speed, and display it on the LCD.

To calibrate the system:

  1. Measure a known distance between two points on your highway (e.g., 100 meters).
  2. Time how long it takes for a vehicle to cross this distance.
  3. Adjust the code to calculate the speed correctly based on the time measured.

Conclusion

Building a simple highway speed checker using an 8051 microcontroller, an IR sensor, and a 16×2 LCD display is an educational and practical project that demonstrates the application of embedded systems in traffic management and road safety. By accurately measuring and displaying vehicle speeds, such systems contribute to safer highways and better traffic management.

Remember to adapt the code and hardware connections to your specific components and requirements. With the right setup and calibration, your speed checker can be a valuable tool for promoting road safety in your community.

To book the project Click Here

Categorized in: