keypad based door lock system

keypad based lock is a digital locking system allow user to enter user id by making use of keypad. status of system at any instant would automatically be displayed on LCD. if user id whatever you have got set in code would match with user id you have entered through keypad doors (dc motor) will open, otherwise it shows the message try again with a beep(alarm gets activated for some time).

Proteus design

4x3 keypad is connected to port P1 from P1.0-P1.6 allowing user to enter user id. data pins of lcd is connected to port P2 describing the current status of system. here motor is treated as door which is connected with pin P3.0andP3.1 through L293D driver.

check(); function scan whether a key has been pressed or not all the time. if any key has got pressed corresponding value would be stored in variable which we will compare with variable having predefined id. function strcmp(); compare these two ids if id matched it would return zero otherwise give some garbage valu

code

#include<reg51.h>
#include<string.h>
#define lcdport P2
sbit rs=P3^4;
sbit rw=P3^5;
sbit en=P3^6;
sbit m1=P3^0;
sbit m2=P3^1;
sbit r1=P1^0;
sbit r2=P1^1;
sbit r3=P1^2;
sbit r4=P1^3;
sbit c1=P1^4;
sbit c2=P1^5;
sbit c3=P1^6;
sbit buzzer=P1^7;
char uid[]="54321";
char id[5];

void lcdint();
void user_id(char);
void lcdstring(char *);
void delay(int);
void lcdcmd(char);
void lcddata(char);
void check_id();
char scankey();
char check();
void door_open();
void door_close();
void sounder();

void main()
{
int n;
char key;
P2=0x00;
P1=0xff;
lcdint();
lcdstring("system is locked");
lcdcmd(0xc0);
lcdstring("enter user id");
delay(100);
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("user_id");
lcdcmd(0xc0);
n=0;
while(n<5)
{
key=check();
id[n]=key;
lcddata(key);
delay(100);
n++;
}
lcdcmd(0x01);
lcdcmd(0x02);
if(strcmp(uid,id)==0)
{
lcdstring("id matched");
delay(200);
door_open();
delay(600);
door_close();
lcdcmd(0x01);
lcdcmd(0x02);
}
else
{
lcdstring("try again");
sounder();
delay(200);
lcdcmd(0x01);
lcdcmd(0x02);
}
}
void sounder()
{
int i;
for(i=0;i<10;i++)
{
buzzer=1;
delay(100);
buzzer=0;
}
}
void door_open()
{
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("opening door...");
m1=1;
m2=0;
}
void door_close()
{
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("closing door...");
m1=1;
m2=0;
m1=0;
m2=1;
delay(400);
m1=0;
m2=0;
}
char check()
{
char b='a';
while(b=='a')
{
b=scankey();
}
return b;

}
char scankey()
{
c1=c2=c3=1;
r1=r2=r3=r4=0;
r1=0;r2=r3=r4=1;
if(c1==0)
{
delay(2);
return '1';
}
if(c2==0)
{
delay(2);
return '2';
}
if(c3==0)
{
delay(2);
return '3';
}
r2=0;r1=r3=r4=1;
if(c1==0)
{
delay(2);
return '4';
}
if(c2==0)
{
delay(2);
return '5';
}
if(c3==0)
{
delay(2);
return '6';
}
r3=0;r1=r2=r4=1;
if(c1==0)
{
delay(2);
return '7';
}
if(c2==0)
{
delay(2);
return '8';
}
if(c3==0)
{
delay(2);
return '9';
}
r4=0;r1=r2=r3=1;
if(c1==0)
{
delay(2);
return '*';
}
if(c2==0)
{
delay(2);
return '0';
}
if(c3==0)
{
delay(2);
return '#';
}
return 'a';
}
void lcdstring(char *p)
{
while(*p!='\0')
{
lcddata(*p);
delay(10);
p++;
}
}
void lcdint()
{
lcdcmd(0x38);
delay(2);
lcdcmd(0x01);
delay(2);
lcdcmd(0x80);
delay(2);
lcdcmd(0x0e);
delay(2);
}
void delay(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++);
}
void lcdcmd(char a)
{
lcdport=a;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
}
void lcddata(char value)
{
lcdport=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}

 

VIDEO

Category: 

tags: 

Share

Comments

nice
Hello sir,I require an assembly language code for 8051 password based locking system.kindly help me out.please send methe code @ [email protected] asap.would be egarly waiting for your reply .Thank you.

sorry Prathamesh our approach here is to clear your concept just go through it and built your own one in assembly.give it a try good luck

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate