Password Based Door Lock System Using 8051 Microcontroller Final Report
Password Based Door Lock System Using 8051 Microcontroller Final Report
LIST OF FIGURES:
A. BLOCK DIAGRAM
D. PCB FBRICATION
E. FLOW CHART
The system will allow the person who knows the password and it will not
allow who don’t know the password and the system will also show the
persons who try to break the protection barrier.
BLOCK DIAGRAM AND CIRCUIT DIAGRAM
INTEL 805 1 Arc hitecture
The generic 8051 architecture sports a Harvard architecture, which contains
two separate buses for both program and data. So, it has two distinctive
memory
spaces of 64K X 8 size for both program and data. It is based on an 8-bit
central processing unit with an 8-bit Accumulator and another 8-bit B register
as main processing blocks. Other portions of the architecture include few 8 bit
and 16-bit registers and 8-bit memory locations. Each 8031 device has some
amount of
data RAM built in the device for internal processing. This area is used for
stack operations and temporary storage of data. This base architecture is
supported with on chip peripheral functions like I/O ports, timers/counters,
versatile serial communication port. So, it is clear that these 8051 architectures
were designed to cater many real time embedded needs.
The following list gives the features of the 8051 architecture:
Timers/Counters
-Bit Timer/Counters
-Chip Analog Comparator
5. ALGORITM
1. START
2. initialize LCD, keypad
3. clear LCD
4. print “Enter lock code” on LCD
5. get 5 char long password using matrix key pad
6. if input = “12345” then
6.1 print “Enter master code”
6.2 get 10 char long password using matrix key pad
6.3 if input = master lock then
6.3.1 change user password
6.3.2 go to step 4
6.4 else
6.4.1 print “wrong code” on LCD
6.4.2 go to step 4
7. else
7.1 if input = user lock or input = default lock then
7.1.1 unlock the lock
7.1.2 retry count = 3
8. STOP
PROGRAM
Delay program:
#include "delay.h"
void delayus(unsigned char
delay)
{
while(delay--);
}
void delayms(unsigned char delay)
{
while(delay--)
delayus(149);
}
Keypad program:
#include "keypad.h"
#include "delay.h"
bit keystatus = FALSE;
void keypad_init()
{
keyport &=0x0F;
return keyval+'
else if(keyval==10)
return 'x';
else if(keyval==11)
return '0';
else if(keyval==12)
return 'e';
}
LCD program:
#include "lcd.h"
#include "delay.h"
#include <REG2051.H>
unsigned char code lockicon[]={0xe, 0xa, 0x1f, 0x1f, 0x1b, 0x1b, 0xe, 0x0};
unsigned char code unlockicon[]={0xe, 0x2, 0x1f, 0x1f, 0x1b, 0x1b, 0xe,
0x0}; unsigned char code ex[]={0x1f, 0x1b, 0x1b, 0x1b, 0x1b, 0x1f, 0x1b,
0x1f}; unsigned char code ok[]={0x0, 0x1, 0x3, 0x16, 0x1c, 0x8, 0x0, 0x0};
void lcd_reset()
{ lcd_port = 0xFF;
delayms(20);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
delayms(10);
lcd_port = 0x03+LCD_EN;
lcd_port = 0x03;
delayms(1);
lcd_port =
0x03+LCD_EN; lcd_port
= 0x03; delayms(1);
lcd_port = 0x02+LCD_EN;
lcd_port = 0x02;
delayms(1);
}
void lcd_init ()
{ unsigned char i;
lcd_reset();
lcd_cmd(LCD_SETFUNCTION); // 4-bit mode - 1 line - 5x7 font.
lcd_cmd(LCD_SETVISIBLE+0x04); // Display no cursor - no blink.
lcd_cmd(LCD_SETMODE+0x02); // Automatic Increment - No Display
shift. lcd_cmd(LCD_SETCGADDR);
for(i=0;i<8;i++)
lcd_data(lockicon[i]); 27
for(i=0;i<8;i++)
lcd_data(unlockicon[i]);
for(i=0;i<8;i++)
lcd_data(ex[i]);
for(i=0;i<8;i++)
lcd_data(for(i=0;i<8;i+
+)
lcd_data(unlockicon[i]);
for(i=0;i<8;i++)
lcd_data(ex[i]);
for(i=0;i<8;i++)
lcd_data(ok[i]);
lcd_cmd(LCD_SETDDADDR); // Address DDRAM with 0 offset 80h.
}
void lcd_cmd (char cmd)
{ lcd_port = ((cmd >> 4) & 0x0F)|LCD_EN;
lcd_port = ((cmd >> 4) & 0x0F);
lcd_port = (cmd & 0x0F)|LCD_EN;
lcd_port = (cmd &
0x0F); delayus(200);
delayus(200);
}
void lcd_data (unsigned char dat)
{ lcd_port = (((dat >> 4) & 0x0F)|LCD_EN|LCD_RS);
lcd_port = (((dat >> 4) & 0x0F)|LCD_RS);
lcd_port = ((dat & 0x0F)|LCD_EN|LCD_RS); lcd_port = ((dat &
0x0F)|LCD_RS);
delayus(200);
delayus(200);
}
void lcd_str (unsigned char *str)
{ while(*str){
lcd_data(*str++);
}
}
Lock program:
#include "keypad.h"
#include "lcd.h"
#include "delay.h"
#include "lock.h"
unsigned char code masterlock[10]="1234567890",
defaultulock[5]="54321";
unsigned char userlock[5], input[10];
extern bit newlock;
bit check(unsigned char *first, unsigned char *second, unsigned char len)
{
unsigned char i=0; lcd_str("Enter new code");
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(5);
if(status == TRUE){
lcd_cmd(LCD_CLS);
lcd_data(OK);
lcd_str("lock code saved!");
newlock =
TRUE;
store_code();
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
}
else if(status == RETRY)
goto retry1;
goto exit;
} else{
lcd_cmd(LCD_CLS);
lcd_str("WRONG CODE!");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
}
}
else if(status == RETRY)
goto retry;
else if(status == EXIT)
goto exit;
exit:;
}
char getinput(unsigned char max)
{ unsigned char i,key; i=0;
while(1){ while(!
(key=getkey())); key =
translate(key);
input[i]=key;
if(key=='x'){
if(i==0)
return EXIT; i--;
lcd_cmd(0xC2+i)
; lcd_data(' ');
lcd_cmd(0xC2+i)
;
}
else if(key=='e')
{ return TRUE;
}
else{
i++;
if(i>max){
lcd_cmd(LCD_CLS); lcd_data(EX);
lcd_str(" Code too Long...");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
return RETRY;
}
lcd_data('*');
}}}
void store_code(){
unsigned char i;
for(i=0;i<5;i++)
userlock[i]=input[i];
}
Main program:
#include "lcd.h"
#include "keypad.h"
#include "lock.h"
#include "delay.h"extern unsigned char input[10], userlock[5];
extern unsigned char code defaultulock[5],masterlock[10];
bit newlock=FALSE;
unsigned char retrycount=3;
void main(){
unsigned char status,i=0;
bit lockstatus;
lcd_init();
keypad_init();
while(1){
lcd_cmd(LCD_CLS);
lcd_str("Enter lock code");
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(5);
if(check(input,"12345",5)){
setulock();if(check(input,masterlock,10))
{ retrycount=3;
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_str("UNBLOCKED")
; lcd_data(EX);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
} else{
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_str("WRONG CODE");
lcd_data(EX);
delayms(250);
delayms(250);
delayms(250);
delayms(goto
blocked;
}
}
}
}
done:;
}
}
R e s i s to r :
Resistor is a component that resists the flow of direct or alternating electric
circuit. Resistors can limit or divide the current, reduce the voltage, protect an
electric circuit, or provide large amounts of heat or light. An electric current
is the movement of charged particles called electrons from one region to
another. Resistors are usually placed in electric circuits. Physicists explain
the flow of current through a material, such as a resistor, by comparing it to
water flowing through a pipe. Resistors are designed to have a specific value
of resistance. Resistors used in electric circuits are cylindrical. They are often
color coded by three- or four-color bands that indicate the specific value of
resistance.
Resistors obey ohm’s law, which states that the current density is
directly proportional to the electric field when the temperature is
constant.
Capacitor:
Capacitor or electric condenser is a device for storing an electric charge. The
simplest form of capacitor consists of two metal plates separated by a non-
touching layer called the dielectric. When one plate is charged with
electricity from a direct current or electrostatic source, the other plate has
induced in it a charge of the opposite sign; that is, positive if the original
charge is negative
and negative if the original charge is positive. The electrical size of the
capacitor
is its capacitance. Capacitors are limited in the amount of electric charge
they can absorb; they can conduct direct current for only instances but
function well as conductors in alternating current circuits. Fixed capacity
and variable capacity capacitors are used in conjunction with coils as
resonant circuits in radios and other electronic equipment. Capacitors are
produced in a wide variety of forms. Air, Mica, Ceramics, Paper, Oil, and
Vacuums are used as dielectrics depending on the purpose for which the
device is intended.
Transistor:
Transistor is a device which transforms current flow from low resistance path
to high resistance path. It is capable of performing many functions of the
vacuum tube in electronic circuits, the transistor is the solid-state device
consisting of a tiny piece of semi conducting material, usually germanium or
silicon, to which three or more electrical connections are made.
N-type and P-type Transistor:
A germanium or silicon crystal, containing donor impurity atoms is called a
negative or n-type semiconductor to indicate the presence of excess
negatively charged electrons. The use of an acceptor impurity produces a
positive, or p- type semiconductor so called because of the presence of
positively charged holes. When an electrical voltage is applied, the n-p
junction acts as a rectifier,
permitting current to flow in only one direction. If the p-type region is
connected to the positive terminal of the battery and the n-type to the negative
terminal, a large current flow through the material across the junction.
7.4 Diode:
Diode is an electronic device that allows the passage of current in only one
direction. The first such devices were vacuum-tube diodes, consisting of an
evacuated glass or steel envelope containing two electrodes – a cathode and
an anode. The diodes commonly used in electronic circuits are
semiconductor diodes. There are different diodes used in electronic circuits
such as Junction diode, Zener diode, Photo diodes, and tunnel diode.
Junction diodes consist of junction of two different kinds of semiconductor
material. The Zener diode is a special junction type diode, using silicon, in
which the voltage across the junction is independent of the current through
the junction.
thermal -
Output transistor safe area protection
Relay Driver (BC547):
The BC547 transistor is an NPN Epitaxial Silicon Transistor. The BC547
transistor is a general-purpose transistor in small plastic packages. It is used
in general-purpose switching and amplification BC847/BC547 series 45 V,
100 mA NPN general-purpose transistors.
The BC547 transistor is an NPN bipolar transistor, in which the letters "N"
and
"P" refers to the majority charge carriers inside the different regions of the
transistor. Most bipolar transistors used today are NPN, because electron
mobility is higher than whole mobility in semiconductors, allowing greater
currents and faster operation. NPN transistors consist of a layer of P - doped
semiconductor (the "base") between two N-doped layers. A small current
entering the base in common-emitter mode is amplified in the collector
output. In other terms, an NPN transistor is "on" when its base is pulled high
relative to the emitter. The arrow in the NPN transistor symbol is on the
emitter leg and points in the direction of the conventional current flow when
the device is in forward active mode. One mnemonic device for identifying
the symbol for the NPN transistor is "not pointing in." An NPN transistor can
be considered as two diodes with a shared anode region. In typical operation,
the emitter base
junction is forward biased and the base collector junction is reverse biased. In
an NPN transistor, for example, when a positive voltage is applied to the
base emitter junction, the equilibrium between thermally generated carriers
and the repelling electric field of the depletion region becomes unbalanced,
allowing thermally excited electrons to inject into the base region. These
electrons wander (or "diffuse") through the base from the region of high
concentration near the emitter towards the region of low concentration n near
the collector. The electrons in the base are called minority carriers because
the base is doped p - type which would make holes the majority carrier in the
base
P CB F AB RICATION
Another screen, which contains component side layout, is prepared and the
same is printed on the component side of the board. A paper epoxy laminate
is used as the board. Both the component and the track layout of the
peripheral PCB is given at the end of this report.
APPLICATIONS
Our electronic door lock performed as expected. We were able to
implement all the functions specified in our proposal. The biggest hurdle
we had to overcome with this project was interfacing the micro
controller with the hardware components. We feel that this electronic
door lock is very marketable because it is easy to use, comparatively
inexpensive due to low power consumption, and highly reliable. This
door lock is therefore particularly useful in applications such as hotel
room door locks, residential housing, and even office buildings.
F UTURE ENHANCEMEN TS
separate passwords.
e system can be easily connected to the personal computer for
further
control.
Other than the speaker sounds, all the lights are made to turned on if password
entered is wrong for three times and also a hidden camera is used to record
the faces who trespassed.
We can use this system as an attendance register for the students to enter a
class room with their respective password.
CONCLUSION
This project is meant for security systems whose access is only for
respected authorities. Using a microcontroller, the password entered is
checked with the stored password and then does the corresponding
operations. Here we use a 5-digit password for better secrecy.
12. REFERENCES
Electronic circuits and devices: J.B. Gupta.
Op-amps and linear integrated circuits: Ramakanth A. Gayakward
Integrated circuits: K.R. Botkar
The 8051 microcontrollers: Muhammed Ali Mazidi