As shown in Figure IR transceiver is connected to the port pin P0.0 (sensor) through which the number of cars are counted as they pass through the passage and interrupt the IR link. The count is displayed on the LCD connected to port P1. The system is able to count the cars maximum up to 9999.This range can be increased using some modification of programming and circuit diagram connection.The modification is very easy if you understand the whole programming.So try it.This is a good project and application is huge cost is less.Again this can be used to count the people or visitor in a room or shopping complex or any company,industry….

Circuit diagram of the system for counting cars

Circuit diagram of the system for counting cars

Program Source Code
*********************************************************
#include <REG52.H>/*header file include*/
#include <stdio.h>
sbit sensor= P0∧0;
sbit RS = P2∧0;
sbit RW = P2∧1;
sbit EL = P2∧2;
unsigned int unit, ten, hundred, tenth, count;

void delay(int);
void INIT(void);
void ENABLE(void);
void LINE(int);
int updatecount(void); /∗ Function for update the count after passing
the car through the passage∗/
int updatecount()
{if (sensor==1) /∗ When the input pin detects the pulse increment
the count by one otherwise keep it as it
was∗/
{count=count+1; // increment count by 1
}else
{count=count+0; // keep count unchanged
}return(count); // returns the updated count value for next reference
}void LINE(int i) /∗ function to define the display characters on LCD
on specified line ∗/
{ if (i==1)
{RS=0;
RW=0;
P1=0x80; // Force cursor to beginning of the first line
ENABLE(); // Enable LCD
RS=1; // Reset the LCD
}else
{RS=0;
RW=0;
P1=0xC0; // Force cursor to beginning of the second line
ENABLE();
RS=1;
}
}

void delay(int k) // Delay function
{int i,j;
for (j=0;j<k+1;j++) // Delay loop
{for (i=0;i<10000;i++);
}}
void ENABLE(void) // Function to Enable the LCD
{EL=1; // Give high to low pulse to enable pin of
the LCD
delay(1);
EL=0;
delay(1);
}
void INIT(void) // Function to Initialize the LCD
{ RS=0;
RW=0;
EL=0;
P1 = 0x38; // LCD of 2 lines and 5×7 matrix
ENABLE();
ENABLE();
ENABLE();
ENABLE();
P1 = 0x06; // Shift cursor to right
ENABLE();
P1 = 0x0E; // Display on, cursor blinking
ENABLE();
P1 = 0x01;
ENABLE();
}
void main (void)
{int count=0;

int k;
char ∗p;
char array[ ]=“No of Cars=”; /∗ Array to display the characters “No
of Cars=” on the LCD ∗/
INIT();
while(1)
{count= updatecount(); /∗ Assign the returned new value to update the
count ∗/
p=&array; /∗ Points the next location on the LCD to
display the character∗/
for (k=0;k<17;k++)
{if (k==0)
LINE(1);
P1= ∗p++; // Increment the pointer
ENABLE();
LINE(2);
unit =(count%10);
ten=(count/10)%10; /∗ Display no of cars and the count on LCD
on respective decimal position. The character
to display should be in ASCII form.∗/
hundred=(count/100)%10;
tenth=(count/1000);
P1= (tenth+0x30); // Send the ASCII data to LCD
ENABLE();
P1= (hundred+0x30);
ENABLE();
P1= (ten+0x30);
ENABLE();
P1= (unit+0x30);
ENABLE();
}}
}

*********************************************************

Leave a comment