Professional Documents
Culture Documents
Course: BETE-55 D
Submitted To: Lab.Engr Sir Hammad
INTRODUCTION :
Password based door security system using microcontroller is used in the places
where we need more security , Security is a major concern in our day to day life,
and digital locks have become an important part of these security systems. There
are many types technologies available to secure our place, like PIR Based security
systems, RFID based Security system, Laser security alarms, bio-matrix systems
etc. Even now, there are Digital locks which can be operated using our smart
phones, means no more need to keep different keys, just one smart phone can
operate all the locks, this concept is based on Internet of Things.
Explanation:
This system mainly contains AT89C51 microcontroller, keypad module, buzzer and
LCD. AT89C51 microcontroller controls the complete processes like taking
password form keypad module, comparing passwords predefined password,
driving buzzer and send status to LCD display. Keypad is used for inserting
password into the microcontroller. Buzzer is used for indication of wrong
password and LCD is used for displaying status or messages on it. Buzzer has
inbuilt driver by using an NPN transistor.
BLOCK DIAGRAM :
Components:
8051 Microcontroller (AT89S52)
4X4 Keypad Module
Buzzer
16x2 LCD
Resistor (1k,10k)
Pullup resistor (10K)
Capacitor(10uf)
Red led
Bread board
IC 7805
11.0592 MHz Crystal
Power Supply
Connecting wires
7-segment display
Keypad Module
In this project, we have interfaced 4X4 keypad to the 8051 microcontroller using
multiplexing techniques for entering the digital code in the system. Here this 4×4
keypad has 16 keys. If we want to use 16 keys on the keypad, then we need 16-
pin for connecting the microcontroller, but in this technique, we require to use
only 8-pins for interfacing 16-keys. So that it can interface the keypad module.
LCD:
The LCD screen is an electronic display module, it can be used in a wide range of
applications. The basic module of the LCD is 16×2 LCD display and is very
frequently used in various electronic circuits and well as devices.
AT89C51 Microcontroller
The AT89C51 is an 8-bit microcontroller which belongs to Atmel’s 8051
families.
First, we have to define 8 pins for keypad module. In which first 4 pins are column
and last 4 pins are rows.
For row scanning we need to give data or signal to column pins and read that data
or signal from row pin. Now suppose we give below data to column pins:
C1=0;
C2=1;
C3=1;
C4=1;
And we read this data at row pins (by default row pins are HIGH due to pull-up
resistor).
If user presses key number ‘1’ then R1 changes HIGH to LOW means R1=0; and
controller understands that user has pressed key ‘1’. And it will print ‘1’ on the
LCD and store ‘1’ in array. So, this HIGH to LOW change at R1, is the main thing
by which controller understands that some key, corresponding to Column 1, has
been pressed.
Now if user presses key number ‘2’ then R1 remains at HIGH as C1 and R1 both
are already at HIGH. Hence there will be no change, it means microcontroller
understands that nothing has been pressed in column one. And likewise, this
principal goes for all another pins. So, in this step controller only waits for keys in
column one: ‘1’, ‘4’, ‘7’ and ‘*’.
Now if we want to track the keys in other columns (like in col 2), then we need to
change the data at columns pins:
C1=1;
C2=0;
C3=1;
C4=1;
This time controller only waits for keys in column two: ‘2’, ’5’, ’8’and ‘0’, because
change (HIGH to LOW) only occurs when column two keys will be pressed. If we
press any key in col 1, 3 or 4 then no change will occur, because these columns are
at HIGH, and Rows are already at HIGH.
So likewise, keys in column C3 and C4 can also be tracked by making them 0, at a
time.
Hardware Circuit Explanation:
Circuit diagram for this Digital lock using 8051 has been shown below and can
easily be understood. Keypad module’s Column pins are directly connected to pin
P0.0, P0.1, P0.2, P0.3 and Row pins are connected to P0.4, P0.5, P0.6, P0.7 of
89s52 microcontroller’s port 0. A 16x2 LCD is connected with 89c51
microcontroller in 4-bit mode. Control pin RS, RW and En are directly connected
to pin P1.0, GND and P1.2. And data pin D4-D7 is connected to pins P1.4, P1.5,
P1.6 and P1.7 of 89c51. And one buzzer is connected at pin P2.6 through a
resistor.
Code Explanation:
We have used a predefined password in the program, this password can be
defined by the user in the code below. When user enters a password to the
system, then system compares the user entered password with stored or
predefined password in Code of Program. If a match occurs, then LCD will show
“Access Granted” and if the password doesn’t match then LCD will show “Access
Denied” and buzzer will continuously beep for some time. Here we have used
string.h library. By using this library, we can compare or match two strings, by
using “strncmp” function.
In the program, first of all, we include header file and defines variable and input &
output pins for keypad and LCD.
Function for creating the delay of 1 second has been created, along with some
LCD functions like for LCD initialization, printing the string, for commands etc.
After this, in main program we have initialize LCD and then we read the input
from Keypad using the keypad () function and stores input keys into an array and
then compare it from predefined array data using strncmp.
The delee () function has been associated with the 7-segment display. The 7-
segment gets its value incremented for the wrong approach and resets for the right
approach.
Code:
#include<reg51.h>
#include<string.h>
#define lcdport P1
sbit col1=P0^0;
sbit col2=P0^1;
sbit col3=P0^2;
sbit col4=P0^3;
sbit row1=P0^4;
sbit row2=P0^5;
sbit row3=P0^6;
sbit row4=P0^7;
sbit rs=P1^0;
sbit en=P1^2;
sbit buzzer=P2^6;
char pass[4],i=0;
int i,j;
for(i=0;i<itime;i++)
for(j=0;j<1275;j++);
}
void daten()
rs=1;
en=1;
delay(5);
en=0;
daten();
daten();
void cmden(void)
rs=0;
en=1;
delay(5);
en=0;
void delee(int k)
int i,j;
for(i=0;i<k;i++)
for(j=0;j<1275;j++);
cmden();
cmden();
while(*str)
lcddata(*str);
str++;
void lcd_init(void)
lcdcmd(0x02);
lcdcmd(0x28);
lcdcmd(0x0e);
lcdcmd(0x01);
void keypad()
{
int cursor=192,flag=0;
lcdcmd(1);
lcdstring("Enter Ur Passkey");
lcdcmd(0xc0);
i=0;
while(i<4)
flag=cursor;
col1=0;
col2=col3=col4=1;
if(!row1)
lcddata('1');
pass[i++]='1';
cursor++;
while(!row1);
else if(!row2)
lcddata('4');
pass[i++]='4';
cursor++;
while(!row2);
else if(!row3)
{
lcddata('7');
pass[i++]='7';
cursor++;
while(!row3);
else if(!row4)
lcddata('*');
pass[i++]='*';
cursor++;
while(!row4);
col2=0;
col1=col3=col4=1;
if(!row1)
lcddata('2');
pass[i++]='2';
cursor++;
while(!row1);
else if(!row2)
lcddata('5');
pass[i++]='5';
cursor++;
while(!row2);
else if(!row3)
lcddata('8');
pass[i++]='8';
cursor++;
while(!row3);
else if(!row4)
lcddata('0');
pass[i++]='0';
cursor++;
while(!row4);
col3=0;
col1=col2=col4=1;
if(!row1)
lcddata('3');
pass[i++]='3';
cursor++;
while(!row1);
else if(!row2)
lcddata('6');
pass[i++]='6';
cursor++;
while(!row2);
else if(!row3)
lcddata('9');
pass[i++]='9';
cursor++;
while(!row3);
else if(!row4)
lcddata('#');
pass[i++]='#';
cursor++;
while(!row4);
col4=0;
col1=col3=col2=1;
if(!row1)
lcddata('A');
pass[i++]='A';
cursor++;
while(!row1);
else if(!row2)
lcddata('B');
pass[i++]='B';
cursor++;
while(!row2);
else if(!row3)
lcddata('C');
pass[i++]='C';
cursor++;
while(!row3);
else if(!row4)
lcddata('D');
pass[i++]='D';
cursor++;
while(!row4);
if(i>0)
if(flag!=cursor)
delay(100);
lcdcmd(cursor-1);
lcddata('*');
unsigned i,j ;
for(i=0;i<time;i++)
for(j=0;j<1275;j++);
void accept()
lcdcmd(1);
lcdstring("Welcome");
lcdcmd(192);
lcdstring("Password Accept");
delay(200);
void wrong()
buzzer=0;
lcdcmd(1);
lcdstring("Wrong Passkey");
lcdcmd(192);
delay(200);
buzzer=1;
void main()
unsigned char t;
P3=0x00;
buzzer=1;
lcd_init();
lcdstring("Electronic Code");
lcdcmd(0xc0);
delay(400);
lcdcmd(1);
lcdstring("*OEL Project*");
delay(400);
while(1)
n++;
i=0;
for(t=0;t<n;t++)
{
P3=arr[t];
delee(100);
keypad();
if(strncmp(pass,"1122",4)==0)
accept();
lcdcmd(1);
n=0;
delay(300);
else
lcdcmd(1);
lcdstring("Access Denied");
wrong();
delay(300);
}
Proteus Simulation: