It has many applications:
1) Home automation : Automatically switching on light / fan only if there is a person or a group of persons. This can save a lot of power consumed otherwise.
2) In a situation where a premises is on fire and everyone needs to be out of the building, this counter can show if all have safely exited the premises or not. If there are still people inside, then they can be rescued. This is needed as the situation can result into chaos and keeping track of everyone is not possible.
3) In today's pandemic time, It is good to keep track of the number of people in a particular area.
If it has reached the mark, then it can display that no more persons can enter that area, so that safe distance is maintained. (This limit also can be just added to the code).
1) Visitor_counter.c
#include<stdio.h>
#include"lcd.h"
sbit entry=P1^0;
sbit exit=P1^1;
sbit entryled=P1^2;
sbit exitled=P1^3;
void main()
{
int count=0; int i;
char str[10];
lcd_init();
lcd_disp("Visitor Counter..");
lcd_command(0xC0);
while(1)
{
entry=exit=1;
entryled=exitled=1;
if(entry==0)
{
for(i=0;i<7;i++){
lcd_command(0X38); // used as a NOP
if(exit==0) {
delay(5);
count++;
entryled=0;
exitled=1;}
}
}
if(exit==0)
{
i=0;
for(i=0;i<7;i++){
lcd_command(0X38); // used as a NOP
if(entry==0) {
delay(5);
count--;
entryled=1;
exitled=0;}
}
}
sprintf(str,"%d",count);
lcd_command(0xC0);
lcd_disp("Count : ");
lcd_command(0xC9);
lcd_disp(str);
}
}
#include<reg51.h>
sbit rs=P1^4;
sbit rw=P1^5;
sbit en=P1^6;
void delay(int n)
{
int i=0;
for(;i<n*1000;i++);
}
void lcd_command(char c)
{
P2=c;
rs=0;
rw=0;// write
en=1;
delay(1);
en=0;
delay(1);
}
void lcd_data(char d)
{
P2=d;
rs=1;
rw=0;// write
en=1;
delay(1);
en=0;
delay(1);
}
void lcd_init()
{
lcd_command(0x01);
lcd_command(0x38);
lcd_command(0x06);
lcd_command(0x0C);
lcd_command(0x80);
}
void lcd_disp(char c[])
{
int i=0;
while(c[i]!='\0')
{
lcd_data(c[i]);
i++;
}
}
No comments:
Post a Comment