One Time Programmable Password Lock

0
2929
How to Add Sound to Raspberry Pi Game Pad

One Time Programmable Password Lock

[nextpage title=”Description” ]Locking and unlocking any device (or system) like locker, cupboard, automatic door, suitcase etc with the help of password is most widely used technique for providing secured access. Only the authorized person – who knows the password, can lock or unlock the system. Once device is locked, if any other person tries to unlock it and enters wrong password then system gives ALERT message or warning (or something like that).

The general operation for password lock system is

·         The system is locked by entering correct password

·         It can be unlocked by entering correct password

·         If wrong password is entered then system will not be locked or unlocked and system shows warning

·         If anyone tries to enter wrong password again and again, system becomes inactive (HANG) so that further attempts to enter password can be prohibited

 

There are two different varients in this system

  1. Factory programmed passward: The password is default – factory programmed. It can not be set or changed. To lock or unlock system user has to enter that default password everytime. He/she can not set his own password
  2. User Programmable password: the password can be set or changed. User can set his own password. In this type also there are two different varients. In one type password can be set or changed many times and in other type password can be set by user only once – that is called  one time programmable password system

Here the given project demonstrates one time programmable password system using micro controller AT89C51. The system has default password initially that can be changed only once. User can set his own 5 digit password once. Afterword password set button is disabled. User has to enter correct password to lock or unlock the system. Also user gets only three attempts to enter correct password. If he enters wrong password thrice, the complete system hangs. No furthur operation is possible. The only way is to press master reset

Circuit description

(Check the circuit diagram tab for complete circuit for one time programmable Password Lock)

·         The 4×3 keypad is connected to PORT3. 4 rows are connected to P3.4 – P3.7 and 3 columns are connected to P3.0 – P3.2. the keypress event is detected using row-column scanning

·         Four LEDs – two red and two green are connected to PORT2 pins P2.0 – P2.3 such that LED turns ON when pin is high

·         One buzzer is connected to pin P2.5 through npn transistor connected in switch configuration. It generates beep sound when pin is high for moment

·         Pin P2.4 drives single change over type relay through another npn type transistor. Setting pin high/low will switch ON/OFF the relay

·         Data pins D0-D7 of LCD are connected with PORT0. Control pins Rs and En are connected with pins P2.7 and P2.6 respectively. RW pin is connected to ground. One 1K pot is connected to VEE pin (3) to control LCD brightness

·         A 12 MHz crystal with two 22 pF capacitors is connected with crystal terminals as shown

·         One reset pushbutton in parallel with 0.1 uF capacitor is connected to reset pin (9) as shown to provide manual reset to the micro controller

Circuit operation:

·         When circuit is switched ON all the LEDs are OFF, relay is OFF and the message is displayed on LCD as “to lock system enter password

·         After 2 second in place of word password the blank spaces are displayed to enter user password

·         And the circuit waits for user input through keypad

·         User enters password digit by digit. It is displayed as * on LCD. After entering all digits user has to press enter key

·         When enter key is pressed, the circuit compares entered password with set password

·         If they match the system is locked. The correct LED (green) blinks, locked LED (green) turns ON, short beep sound is generated and relay switched ON

·         LCD shows message “system locked” for 2 seconds and after that again it shows message “to unlock system enter password

·         If entered password does not match, wrong LED (red) blinks, beep sound is generated twice and message is displayed on LCD as “wrong password

·         If user enters wrong password 3 times then the system HANGs and starts generating continuous beep sound till reset button is pressed. The message is displayed on LCD as “system HANG press reset

·         To set new password user presses set new password button. Immediately the message displayed on LCD as “set new password(5 digit)

·         Then by entering digits one by one user can set new password. The digits are displayed on LCD. At the end user presses enter button. This sets new password and LCD shows message as “new password is xxxxx

·         If again user presses set new password button then message is displayed as “password can be set only once

Software program:

The complete circuit operation is due to the software program embedded inside micro controller. All the functionalities are implemented using software logic and the program. The program performs all the functionalities like

·      Takes user inputs through keypad

·      Displays different messages on LCD

·      Give indications on 4 LEDs of password correct or incorrect system locked or unlocked

·      Switch ON or OFF relay to turn ON or OFF any device connected with relay

·      Give audio notification for different events

The program is written in C language. It is compiled using KEIL (IDE) cross compiler tool. It is compiled for generic 8051 micro controller platforms so it can be used for all different micro controllers of MCS51 family like 89C51 / 89C52 / 89S52 etc. after compiling the program the HEX file is generated. That HEX file is loaded into the internal FLASH (EEPROM) of micro controller using any suitable EEPROM programmer.

[/nextpage][nextpage title=”Circuit Diagram” ]

One Time Programmable Password Lock

[/nextpage][nextpage title=”Code” ]#include <reg51.h>

#include <string.h>

sbit rs = P2^7;                   // rs pin of LCD

sbit en = P2^6;                   // en pin of LCD

sbit led1 = P2^0;

sbit led2 = P2^1;

sbit led3 = P2^2;

sbit rely = P2^4;

sbit led4 = P2^3;

sbit buz = P2^5;

char str1[5] = “12345”;           // default password

char str2[5];

int j;

 

void writecmd(unsigned char a);   // function initializations

void writedata(unsigned char b);

void busy(void);

void writestr(unsigned char *s);

void wait_for_2sec()

{

int y,z;

for(y=0;y<50;y++)

for(z=0;z<10000;z++);

}

void writecmd(unsigned char a)

{

busy();

rs = 0;

P0 = a;

en = 1;

en = 0;

}

void writedata(unsigned char b)

{

busy();

rs = 1;

P0 = b;

en = 1;

en = 0;

}

void busy()

{

int k;

for(k=0;k<1500;k++);

}

void writestr(unsigned char *s)

{

unsigned char l,z;

l = strlen(s);

for(z=0;z<l;z++)

{

writedata(*s);

s++;

}

}

void keydly()

{

int x,y;

for(x=0;x<100;x++)

for(y=0;y<1000;y++);

}

void sound_buzzer(unsigned int t) // produce beep sound

{

unsigned int p;

for(p=0;p<t;p++)                 // beep sound once or twice

{

buz = 1;

keydly();

buz=0;

keydly();

}

}

void main()

{

int t=0,i,p=0,f=0,r,y,c=0,l=0,s=0,a=0;

P3=0x00;                                 // ports P3 and P2 output ports

P2=0x00;

writecmd(0x3C);                          // configure LCD

writecmd(0x0E);

next:  r=0;i=0;

writecmd(0x01);

if(l==0) writestr(“To Lock System”);     // display message

else writestr(“To UnLock System”);

writecmd(0xC0);

writestr(“Enter Password”);

wait_for_2sec();                         // after 2 second

writecmd(0xC6);

writestr(“________”);                    // show space to enter password

writecmd(0xC6);

loop:  P1=0xF0;

while(P1==0xF0);

while(P1!=0xF0)

{

P1=0xFE;

if(P1==0xEE)

{

if(f==0)

{

writedata(0x2A);

str2[i]=0x31;

}

else

{

writedata(0x31);

str1[i]=0x31;

}

t=1;

}

else if(P1==0xDE)

{

if(f==0)

{

writedata(0x2A);

str2[i]=0x34;

}

else

{

writedata(0x34);

str1[i]=0x34;

}

t=1;

}

else if(P1==0xBE)

{

if(f==0)

{

writedata(0x2A);

str2[i]=0x37;

}

else

{

writedata(0x37);

str1[i]=0x37;

}

t=1;

}

else if(P1==0x7E)

{

writecmd(0x01);

if(f==1)

{

writestr(“new password is”);

writecmd(0xC0);

for(y=0;y<5;y++) writedata(str1[y]);

f=0;

}

else

{

if(i==5)

{

for(j=0;j<5;j++)

{

if(str1[j]==str2[j]) p++;

else

{

led1=0;

led4=1;

writestr(“wrong password”);

sound_buzzer(2);

a++;

break;

}

}

if(p==5)

{

c++;

if((c%2)==1)

{

l=1;

rely=1;

led2=0;

led3=1;

writestr(“System Locked”);

}

else

{

l=0;

rely=0;

led3=0;

led2=1;

writestr(“System Unlocked”);

}

led1=1;

led4=0;

sound_buzzer(1);

}

}

else

{

led1=0;

led4=1;

writestr(“wrong password”);

sound_buzzer(2);

a++;

}

}

if(a==3)

{

writecmd(0x80);

writestr(“System HANG!!..”);

writecmd(0xC0);

writestr(” * Press RESET *”);

sound_buzzer(1);

}

r=1;

t=1;

p=0;

}

if(t==1) break;

P1=0xFD;

if(P1==0xED)

{

if(f==0) {writedata(0x2A);str2[i]=0x32;}

else {writedata(0x32);str1[i]=0x32;}

t=1;

}

else if(P1==0xDD)

{

if(f==0) {writedata(0x2A);str2[i]=0x35;}

else {writedata(0x35);str1[i]=0x35;}

t=1;

}

else if(P1==0xBD)

{

if(f==0) {writedata(0x2A);str2[i]=0x38;}

else {writedata(0x38);str1[i]=0x38;}

t=1;

}

else if(P1==0x7D)

{

if(f==0) {writedata(0x2A);str2[i]=0x30;}

else {writedata(0x30);str1[i]=0x30;}

t=1;

}

 

if(t==1) break;

P1=0xFB;

if(P1==0xEB)

{

if(f==0) {writedata(0x2A);str2[i]=0x33;}

else {writedata(0x33);str1[i]=0x33;}

t=1;

}

else if(P1==0xDB)

{

if(f==0) {writedata(0x2A);str2[i]=0x36;}

else {writedata(0x36);str1[i]=0x36;}

t=1;

}

else if(P1==0xBB)

{

if(f==0) {writedata(0x2A);str2[i]=0x39;}

else {writedata(0x39);str1[i]=0x39;}

t=1;

}

else if(P1==0x7B)

{

writecmd(0x01);

if(s==0)

{

writestr(“set new password”);

writecmd(0xC0);

writestr(“(5 digit):”);

f=1;

i=-1;

s++;

}

else

{

writestr(“password can be set”);

writecmd(0xC3);

writestr(“only once”);

r=1;

}

t=1;

}

if(t==1) break;

}

keydly();

i++;

t=0;

if(a==3) while(1);

if (r==0) goto loop;

else goto next;

}[/nextpage]