The password based lock for any access control systems is very common now a day. If there is a password lock for any gate/door, then the gate or door only opens when correct password is entered. Mostly in such system numeric keypad is given to enter password. Sequential code lock differs here with normal password lock system. It does not have full numeric keypad with 10 to 12 switches. Instead it has 2 to 3 switches only. The user has to enter correct sequence of numeric digits just like sequential locks available in briefcases. When the numeric digits are arranged in correct sequence it unlocks.
In this project, the user has to first set the correct sequence of digits by scrolling them from 0 to 9 pressing only 1 button only, similar to scrolling and setting digit in briefcase lock. User has to set all digits one by one to complete the sequential code. The project is build using micro controller AT89C52. It uses LCD to display various messages. The stepper motor is used to give illustration of opening and closing gate.
Circuit description
Fig. 1: Circuit Diagram of 8051 Microcontroller based Sequential Code Lock System
·Port P1 is configured as input and 3 push buttons are connected to pins P1.0 to P1.2 as such when button is pressed that pin gets 0 as an input
· Port P0 is an output port and it drives data pins of LCD D0 – D7. Further two pins of port P2 P2.7 and P2.6 are connected to control pins of LCD Rs and E. The third control pin RW is permanently connected to ground to make LCD always write enable
· A 1 K pot is connected to brightness control pin Vee of LCD to vary its brightness
· Port P3 pins P3.4 – P3.7 drives stepper motor through motor driver chip ULN2003A. The motor opens or closes the gate
· A 12 MHz crystal is connected between XTAL pins along with two biasing capacitors of 33 pf. It provides clock signal to micro controller
Circuit operation:
· When the system is powered ON, the gate is closed and the message is displayed on LCD as “To open gate Enter code”
· To enter code the user has to press digit key. He has to keep pressing digit key again to scroll all the digits from 1 to 0. Like pressing key once will display digit 1, pressing key twice displays digit 2, likewise 3, 4, 5,….. up to 0 and again starts from 1
· Once he reaches to desire digit, to set the digit he has to press second button to set the digit as 1st digit of code. After setting first digit the cursor shifts to second digit position
· Again user has to scroll digits starting from 1 and reach to desire digit using 1st button. Set the second digit of code by pressing 2nd button
· Similarly user has to set 4 digit code. Once 4 digit code is set, user will press enter button
· When enter button is pressed, the micro controller will compare the entered code with programmed code
· If they match the motor rotates clockwise to open the gate and message is displayed on LCD as “gate open”. After 5 seconds again motor rotates anticlockwise to close the gate and LCD displays “gate close” and then again the default message “To open gate Enter code” is displayed
· But if the code does not match then motor stands still and warning message displayed as “wrong code”. Also if wrong code is entered for 3 times, the system enters into infinite loop (that means it hangs). It can come out of the loop only when reset button is pressed to reset the system again.
You may also like:
Project Source Code
###
#include#include
#define ON 0
#define OFF 1
sbit rs = P2^7;
sbit en = P2^6;
sbit unlock_led = P2^0;
sbit lock_led = P2^1;
unsigned int number_count=0,code_num[4],code_digit=0,set_count=0,gate_flag=0;
unsigned int code_lock_num = 1122,attempt=0,reset_flag=0;
void dly()
{
int y,z;
for(z=0;z<100;z++)
for(y=0;y<1000;y++);
}
void motor_delay()
{
int p;
for(p=0;p<2000;p++);
}
void wait_for_5_sec()
{
int r,s;
for(r=0;r<100;r++)
for(s=0;s<10000;s++);
}
void lcd_delay()
{
int y;
for(y=0;y<2000;y++);
}
void writecmd(unsigned char a)
{
lcd_delay();
rs = 0;
P0 = a;
en = 1;
en = 0;
}
void writedat(unsigned char b)
{
lcd_delay();
rs = 1;
P0 = b;
en = 1;
en = 0;
}
void writestr(unsigned char *s)
{
unsigned char l,i;
l = strlen(s);
for(i=0;i
{
writedat(*s);
s++;
}
}
void lcd_init()
{
writecmd(0x3C);
writecmd(0x0E);
writecmd(0x01);
writestr("To open gate");
writecmd(0xC0);
writestr("Enter code:");
}
void initialize()
{
P1=0xFF;
P0=0x00;
P2 = 0x00;
P3 = 0x00;
}
void open_gate()
{
unsigned int i;
writecmd(0x01);
writestr("Gate open");
for(i=0;i<128;i++)
{
P3 = 0x8F;
motor_delay();
P3 = 0x4F;
motor_delay();
P3 = 0x2F;
motor_delay();
P3 = 0x1F;
motor_delay();
}
wait_for_5_sec();
writecmd(0x01);
writestr("Gate closed");
for(i=0;i<128;i++)
{
P3 = 0x1F;
motor_delay();
P3 = 0x2F;
motor_delay();
P3 = 0x4F;
motor_delay();
P3 = 0x8F;
motor_delay();
}
}
void number()
{
if(set_count==0) writecmd(0xCB);
else if (set_count==1) writecmd(0xCC);
else if(set_count==2) writecmd(0xCD);
else if(set_count==3) writecmd(0xCE);
number_count++;
if(number_count==1) {writedat(0x31);}
else if(number_count==2) {writedat(0x32);}
else if(number_count==3) {writedat(0x33);}
else if(number_count==4) {writedat(0x34);}
else if(number_count==5) {writedat(0x35);}
else if(number_count==6) {writedat(0x36);}
else if(number_count==7) {writedat(0x37);}
else if(number_count==8) {writedat(0x38);}
else if(number_count==9) {writedat(0x39);}
else if(number_count==10){writedat(0x30);number_count=0;}
}
void set_number()
{
set_count++;
code_num[code_digit]=number_count;
number_count=0;
code_digit++;
}
void enter_number()
{
unsigned int tmp;
tmp= code_num[0]*1000+code_num[1]*100+code_num[2]*10+code_num[3];
if(tmp == code_lock_num)
{
unlock_led = ON;
lock_led = OFF;
open_gate();
gate_flag=1;
set_count=0;
code_digit=0;
attempt=0;
}
else
{
writecmd(0x01);
writestr("wrong code");
attempt++;
if(attempt==3)
{
writecmd(0x01);
writestr("attempts over");
writecmd(0xC0);
writestr("System Hang");
reset_flag=1;
}
else
{
writecmd(0xC0);
writestr("try again");
gate_flag=1;
set_count=0;
code_digit=0;
}
}
}
void main()
{
initialize();
again: lcd_init();
gate_flag=0;
unlock_led = OFF;
lock_led = ON;
back: P1=0xFF;
while(P1==0xFF);
switch(P1)
{
case 0xFE:
number();
dly();
break;
case 0xFD:
set_number();
dly();
break;
case 0xFB:
enter_number();
dly();
break;
}
if(reset_flag==1) goto infinit;
else if(gate_flag==0) goto back;
else goto again;
infinit:while(1);
}
###
Circuit Diagrams
Project Video
Filed Under: Circuit Design, Electronic Projects
Filed Under: Circuit Design, Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.