Microcontroller Based Digital Code Lock: Bachelor of Technology
Microcontroller Based Digital Code Lock: Bachelor of Technology
Microcontroller Based Digital Code Lock: Bachelor of Technology
LOCK
PROJECT REPORT
SUBMITTED BY
KABIL DAS K
KRISHNA PRIYA VINOD M
KURIAN MATHEW
of
BACHELOR OF TECHNOLOGY
In
ELECTRONICS AND COMMUNICATION
MG UNIVERSITY: KOTTAYAM
APRIL 2011
1
MG UNIVERSITY- KOTTAYAM
BONAFIDE CERTIFICATE
Certified that this project report “MICROCONTROLLER BASED
DIGITAL CODE LOCK” is the bonafide work of “KABIL DAS K,
KRISHNA PRIYA VINOD M and KURIAN MATHEW ” who carried
out the project work under my supervision.
SIGNATURE SIGNATURE
KADAYIRUPPU S.N.G.C.E
KOLENCHERY KADAYIRUPPU
2
ACKNOWLEDGEMENT
I also extend my sincere thanks to all other faculty members of Electronics and
Communication Department and my friends for their support and
encouragement.
3
ABSTRACT
4
TABLE OF CONTENTS
CHAPTER NO. TITLE PAGE NO.
1. INTRODUCTION 7
2. PROJECT DESCRIPTION 8
3. CIRCUIT DIAGRAM 17
4. FLOW CHART 19
5. ALGORITHM 20
6. PROGRAM 22
7. COMPONENTS DETAILS 40
7.1. RESISTOR 40
7.2 CAPACITOR 40
7.3 TRANSISTOR 41
7.4 DIODE 42
8. PCB FABRICATION 46
9. APPLICATIONS 48
11. CONCLUSION 49
12. REFERENCES 49
13. APPENDICES 50
5
LIST OF TABLES:
LIST OF FIGURES:
A. BLOCK DIAGRAM
D. PCB FBRICATION
E. FLOW CHART
6
1. INTRODUCTION
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.
7
2. PROJECT DESCRIPTION
Figure: A
8
communication port. So it is clear that this 8051 architecture was designed to
cater many real time embedded needs.
9
regular EPROM, this memory can be re programmed many times.
Later on I n te l s ta r te d ma n u fa c t u r in g t he s e 8 0 3 1 d e v i c e s w it ho u t
a n y o n c h ip P ro g r a m Memory.
10
Timers/Counters
Features of AT89C2051:
11
Programmable Serial UART Channel
DESCRIPTION
12
PIN CONFIGURATIONS OF 8051:
Figure : B
13
BLOCK DIAGRAM
Figure: C
14
PIN DESCRIPTION OF AT89C2051:
Port 3 Po rt 3 p in s P3 . 0 to P3 . 5 , P3 . 7 a re s e v e n
b id ir e c t io n a l I /O p ins w it h internal pull-ups. P3.6 is
hard-wired as an input to the output of the on-chip
comparator and is not accessible as a general purpose I/O pin.
The Port 3 output buffers can sink 20 mA. When 1s are
written to Port 3p in s t h e y a re p u l le d h ig h b y t h e
in te r n a l p u l l - u p s a n d c a n b e us e d a s inputs. As
inputs, Port 3 pins that are externally being pulled low
will s o u r c e c u rr e nt ( II L) b e c a u s e o f t h e p u ll - u p s .
Po rt 3 a ls o s e r ve s t he functions of various special
features of the AT89C2051 as listed below. Port 3 also
receives some control signals for Flash programming
and programming verification.
RST R e s e t in p u t. A ll I /O p in s a re r e s e t to 1 s a s s o o n
a s R S T go e s h ig h . Holding the RST pin high for two
machine cycles while the oscillator is running resets the
device. Each machine cycle takes 12 oscillator or clock
cycles
15
XTAL1 Input to the inverting oscillator amplifier and input to the
internal clock operating circuit.
Table:1
TABLE: 2
16
3. CIRCUIT DIAGRAM
17
3.2 POWER SUPPLY DIAGRAM
FIGURE: D
The Password was stored in the EEPROM and the password can be changed at
anytime using the same keypad. To change the password dial 12345
Old password - New Password. The power supply section is the
important one. It should deliver constant output regulated power supply
18
for successful working of the project. A 0-12V/500 mA transformer is used
for our purpose the primary of this transformer is connected in to main
supply through on/off switch& fuse for protecting from overload and short
circuit protection. The secondary is connected to the diodes convert from 12V
AC to 12V DC voltage. Which is further regulated to +5v, by using IC 7805
4. FLOWCHART
Figure: E
19
5. ALGORITM
1. START
3. clear lcd
6.3.2 go to step 4
6.4 else
6.4.2 go to step 4
7. else
20
7.1.4 accept input using matrix key pad
7.2 else
7.2.4 go to step 4
8. STOP
21
6. PROGRAM
Delay program:
#include "delay.h"
while(delay--);
while(delay--)
delayus(149);
Keypad program:
#include "keypad.h"
#include "delay.h"
void keypad_init()
keyport &=0x0F;
22
unsigned char getkey ()
k=1;
for(i=0;i<4;i++)
keyport &=~(0x80>>i);
temp = keyport;
if(7-temp)
if(!col1)
key = k+0;
while(!col1);
return key;
if(!col2)
key = k+1;
23
while(!col2);
return key;
if(!col3)
key = k+2;
while(!col3);
return key;
j++;
k+=3;
keyport |= 0x80>>i;
delayms(10);
return FALSE;
{ if(keyval<10)
return keyval+'0';
24
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;
25
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_SETCGADDR);
for(i=0;i<8;i++)
lcd_data(lockicon[i]);
26
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]);
delayus(200);
delayus(200);
27
lcd_port = ((dat & 0x0F)|LCD_RS);
delayus(200);
delayus(200);
{ while(*str){
lcd_data(*str++);
Lock program:
#include "keypad.h"
#include "lcd.h"
#include "delay.h"
#include "lock.h"
bit check(unsigned char *first, unsigned char *second, unsigned char len)
28
for(i=0;i<len;i++){
if(first[i]!=second[i])
return FALSE;
return TRUE;
void setulock(){
char status;
retry:
lcd_cmd(LCD_CLS);
lcd_cmd(LCD_SETDDADDR);
lcd_str("Enter Mastercode");
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(10);
if(status == TRUE){
if(check(input,masterlock,10)){
retry1:
lcd_cmd(LCD_CLS);
29
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);
newlock = TRUE;
store_code();
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
goto retry1;
30
goto exit;
else{
lcd_cmd(LCD_CLS);
lcd_str("WRONG CODE!");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
goto exit;
goto retry;
goto exit;
exit:;
31
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);
32
lcd_data(EX);
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"
33
extern unsigned char input[10], userlock[5];
bit newlock=FALSE;
void main(){
bit lockstatus;
lcd_init();
keypad_init();
while(1){
lcd_cmd(LCD_CLS);
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(5);
if(check(input,"12345",5)){
setulock();
34
goto done;
if(status == TRUE){
if(newlock)
lockstatus = check(input,userlock,5);
else
lockstatus = check(input,defaultulock,5);
if(lockstatus){
retrycount = 3;
lockpin = 0;
lcd_cmd(LCD_CLS);
lcd_data(OK);
lcd_cmd(0xC0);
lcd_str("deactivated!");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
lcd_cmd(LCD_CLS);
35
lcd_str("Press '#' key to");
lcd_cmd(0xC0);
lcd_str("lock again!");
while(getkey()!=12);
lockpin = 1;
lcd_cmd(LCD_CLS);
lcd_data(OK);
lcd_str("Lock is active!");
delayms(250);
delayms(250);
delayms(250);
delayms(250);
else{
retrycount--;
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_cmd(0xC0);
36
lcd_data('0'+retrycount);
delayms(250);
delayms(250);
delayms(250);
delayms(250);
if(retrycount==0){
blocked:
lcd_cmd(LCD_CLS);
lcd_data(EX);
lcd_str("BLOCKED");
for(i=0;i<150;i++)
bus=~bus;
delayms(250);
lcd_data(EX);
lcd_cmd(0xC0);
lcd_data(LOCK);
lcd_data(':');
status = getinput(10);
37
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(250);
38
goto blocked;
done:;
39
7. COMPONENTS DETAILS
7.1. Resistor:
7.2 Capacitor:
40
positive. The electrical size of the capacitor is its capacitance.
Capacitors are limited in the amount of electric charge they can
absorb; they can c o n d u c t d i r e c t c u r r e n t f o r o n l y i n s t a n c e s
b u t f u n c t i o n w e l l a s c o n d u c t o r s i n alternating current circuits.
Fixed capacity and variable capacity capacitors are used i n c o n j u n c t i o n
with coils as resonant circuits in radios and other
e lec tronic equip me nt. Capac itors a re produc e d in a wide
va rie ty of for ms. Air, M ic a, C e ra mic s , Pa p e r, O il, a nd
V a c u u ms a re us e d a s d ie le c tr ic s d e p e n d in g o n t he purpose for
which the device is intended.
7.3 Transistor:
41
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 flows
through the material across the junction.
7.4 Diode:
42
current. They are intended as fixed voltage regulators in a wide range of
applications including local (on-card) regulation for elimination
of noise and distribution problems associated with single-point regulation. In
addition t o u s e a s f i x e d v o l t a g e r e g u l a t o r s , t h e s e d e v i c e s
c a n b e u s e d w i t h e x t e r n a l components to obtain adjustable
output voltages and currents. Considerable effort was expended to
make the entire series of regulators easy to use and minimize the
number of external components. It is not necessary to bypass the
output, although this does improve transient response. Input bypassing is
needed only if the regulator is located far from the filter capacitor of the power
supply.
Features:
Complete specifications at 1A load
Output voltage tolerances of ±2% at Tj = 25°
Line regulation of 0.01% of VOUT/V of VIN at 1A load
Load regulation of 0.3% of VOUT/A
Internal thermal overload protection
Internal short-circuit current limit
Output transistor safe area protection
43
FIGURE: F
FIGURE: G
The BC547 transistor is an NPN bipolar transistor, in which the letters "N" and
"P" refer 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
44
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 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
Figure: H
45
8. PCB FABRICATION
The first step of assembling is to produce a printed circuit board. The
fabrication of the program counter plays a crucial role in the electronic field.
The success of the circuit is also dependent on the PCB. As far as the cost is
concerned, more than 25% of the total cost is for the PCB design and
fabrication.
46
PCB LAYOUT
47
COMPONENT LAYOUT
9. 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 f e e l t h a t t h i s e l e c t r o n i c d o o r l o c k i s v e r y
ma rketa ble becaus e 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.
48
10. FUTURE ENHANCEMENTS
E le c t r ic a l d e v ic e s s uc h a s L i g h ts , C o mp u te r e tc c a n b e
c o nt ro lle d b y u s in g separate passwords.
The 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.
11. 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
49
13. APPENDICES
50