Post on 03-Apr-2015
description
0
Pag
e0
HITEC University Taxila Department of Electrical Engineering
Project Report
Anti Theft Lock
Participants Nisar Ahmed Rana
Shekh M. Arshad
Digital Security Lock
HITEC University Taxila 1
TABLE OF CONTENTS
Abstract 2 1 Introduction 3 1.1 Scope 3 2 Technical Background 4 3 Technical Approach 5
3.1 Preliminary Design 5 3.2 Programming the Microcontroller 5 3.3 Pseudo-Code & Flow Chart 6 3.4 Testing 7 3.4 Circuit Designing and Simulation 7 3.5 Practical Implementation 8 3.6 Troubleshooting 9
4 Circuit Explanation 10 4.1 Microcontroller Module 10 4.2 Power Board 11 4.3 LCD Board 12
5 Results and Conclusions 13 6 Future work 13 7 Appendix A 0
Appendix B 1 7.1 ATMEL AT89S52 Datasheet 1 7.2 ULN2003A Datasheet [2] 3 7.3 ABSOLUTE MAXIMUM RATINGS 4
8 Bibliography 5 8.1 References 5 8.2 Books 5
Digital Security Lock
HITEC University Taxila 2
ABSTRACT
This project is a digital security lock made by using AT89S52 microcontroller. It is
designed for automobiles (i.e. SUZUKI MEHRAN). It will be attached on its dashboard
the user has a keypad for interaction and an LCD for instruction. The user will enter the
code when the instruction “Enter the Code” will appear on the LCD. In case of right code
it will grant the access to the user otherwise it will ask again three times. Failing to do
this the user have to enter the master code which is six digit if it is right then the user
have access to start the car otherwise the car will be locked and a security alarm start to
ring.
Digital Security Lock
HITEC University Taxila 3
INTRODUCTION TO THIEF LOCK
Thief Lock contains a Keypad and an LCD screen. When the user wants to start the car
he will enter the six digit code the Microcontroller Unit will check the code for match; If
the code is verified then the car will start otherwise it will show an error message. The
user can enter wrong code for 3 times after that it will require the master code to start the
car.
SCOPE
This project has huge industrial applications. It can be used as automobiles Thief Lock
and can also be used as a code lock at many places. This code lock can be made more
secure by introducing finger print sensor with code.
Digital Security Lock
HITEC University Taxila 4
TECHNICAL BACKGROUND
Security is a major concern in today world. The automobiles need new technologies for
their security. Different industries are working on automobiles security project such as
car tracker or digital locks. These code locks contains different techniques. Many of the
code lock are quite expensive which can‟t be used everywhere. We have also designed a
digital security lock for a car which contains a keypad to enter the code and an LCD to
display instructions on it. It consists on a microcontroller to control its operation. It is
simple but secure code lock which cost much less than the code locks manufactured by
different industries. It can be mounted on a car or can be attached separately with any
automobile. The same code lock can be used as a door lock the user has to interface the
motor and alarm with it.
Digital Security Lock
HITEC University Taxila 5
Technical Approach
The design process of digital security lock consists on four steps.
1. Preliminary Design
2. Programming the Microcontroller
3. Circuit Designing and Simulation
4. Practical Implementation
5. Troubleshooting
PRELIMINARY DESIGN
Due to knowledge, gained till now, it has decided by our team that the design should be
as simple and secure as possible. Our motto was to design a simple and secure security
lock which can be usable for common person. Other factors for this consideration are cost
effect and limitation to embedded system design.
PROGRAMMING THE MICROCONTROLLER
After preliminary design our next job is to programme the microcontroller. We have used
C language to program the MCU (Microcontroller unit) in Keil. Keypad is interfaced
with port 1 and port 2 of MCU. LCD data pins are interfaced with port 3. Relays and
control pins of LCD are connected with port 0.
Programming of MCU consists on three different stages:
I. Writing a pseudo-code (Flow Chart)
II. Programming the LCD, Keypad and main circuit
III. Testing
Digital Security Lock
HITEC University Taxila 6
PSEUDO-CODE & FLOW CHART
Flow chart of the program explains the logic of whole program. The flow chart is given
in figure-3.1
Pseudo Code for Keypad input:
Pins of Port 1 & Port 2 connected to row wires
Ro to R3 are set as input and the pins
connected to column wires C0 to C3 should be
set as outputs. (That is, pins 0–3 are inputs,
and 4–7 are outputs).
The outputs (bits 4–7) should be set to 0.
Whichever input (bits 0–3) reads in as 0
indicates the row of the pressed key.
Port 1 & Port 2 should then be reconfigured
to have the pins connected to row wires R0 to
R3 set as outputs, and the pins connected to
column wires C0 to C3 should be set as inputs.
(That is, bits 0–3 are outputs, and 4–7 are
inputs).
The outputs (bits 0–3) should be set to 0.
Whichever input (bits 4–7) reads in as 0 indicates the column of the pressed key.
Now that the row and column of the pressed key are known, the key can be located by
checking column and row position.
Pseudo-Code for LCD:
Check the D7 pin for busy condition of LCD (if D7=1 then wait until D7=0).
Send the data to D0-D7 (0x38) to initialize 5X7 matrix, (0x01) to clear screen, (0x02) to
go to home, (0x80) to go to the beginning of 1st line, (0xC0) to move to the beginning of
2nd line or (0x0F) to set the cursor blinking.
Set Rs & Rw ‘0’ and apply a 20ms high to low pulse to use it as a command.
Send the char as a data on D0-D7.
Set Rs=1 & Rw=0 and apply a 20ms high to low pulse to use it for printing data.
Digital Security Lock
HITEC University Taxila 7
TESTING
After completing the whole code the program was debugged using KEIL debug tool. The
errors were corrected easily. We have created the object file in KEIL in INTEL *.hex file
format. The clock speed used was 11.0592MHz.
CIRCUIT DESIGNING AND SIMULATION
We have used Proteus 7.1 to simulate the circuit. After the placement of components and
connecting the wires we started the simulation. The AT89S52 Microcontroller was used
as a MCU. The INTEL *.hex generated by KEIL was selected as a source file. Clock
frequency was set to 11.0592MHz.
The schematic diagram of the circuit is given in Figure 4.1
Figure 3.1 Schematic Diagram During Simulation
Digital Security Lock
HITEC University Taxila 8
PRACTICAL IMPLEMENTATION
After completing the simulation we have generated its PCBs using ARES a package of
Proteus. We placed the PCB packages of all the components we have used in schematic
diagram. After completing the PCB layout we have implemented it through the following
processes:-
Figure 4.1 PCB Layout of Power Board
PCB layout of power board is shown in the figure 4.1. This layout was printed on the
paper and then converted to printed circuit board.
PCB layout of microcontroller module is shown in figure 4.2. There was no PCB for
LCD board we made its circuit on zero board because it was a simple circuit and we have
to connect the wires parallel to the LCD.
Digital Security Lock
HITEC University Taxila 9
Figure 4.2 PCB layout of Microcontroller Module.
TROUBLESHOOTING
Troubleshooting is one of the difficult task in designing a prototype of a project. After
completing all the circuits and making necessary connections we have faced some
problems in LCD display. The keypad and other circuits were working properly.
LCD does not display text: The whole port 3 and 3 pins of port 0 were checked. The pin
P0^0 was damaged so pin P0^1 was used in its place.
Text doesn’t hold on the LCD: Pins RS and E were interchanged so they were
corrected.
LCD didn’t show complete words: LCD didn‟t show complete words. Some of the
characters in a word were replaced with unwanted symbols. The reason for it is that we
haven‟t initialized the LCD before use but it work properly during simulation because it
doesn‟t need initialization.
Digital Security Lock
HITEC University Taxila 10
Circuit Explanation
The complete circuit consists on the following three portions.
Microcontroller Module
Power Board
LCD Board
Figure 6.1 Schematic capture of Thief Lock. (Proteus 7.1)
MICROCONTROLLER MODULE
A microcontroller module has been used as a main circuit. It has parallel as well as serial
port communication circuits in it.
Digital Security Lock
HITEC University Taxila 11
Figure 6.2 Circuit diagram of microcontroller module.
We have used parallel port communication. It has four IDC connectors connected to its
four ports. Clock and reset circuit are also on it.
POWER BOARD
Figure 6.3: 3D circuit layout of Power board
Digital Security Lock
HITEC University Taxila 12
The four output ports are connected on the power board through IDC connectors. Port 1
and Port 2 are used for keypad. We have used four pins of each port for keypad. An eight
bit connector was used to connect the eight pins of two ports (4 pins per port). The
keypad is connected to this eight bit connector.
Port 3 is connected with eight bit data bus of LCD. Rs, R/W and E (enable) pins are used
from port 0. VCC, VEE & VDD are provided externally from the power board. These 14
pins are connected to another IDC connector which connects these 14 pins with LCD on
another board.
Two outputs from Port 0 are connected to ULN2003A which act as a current buffer. First
output is applied at pin 1A (pin # 1) and its output from pin 1C (pin # 14) is again
connected to pin 6A (pin # 6) and final output is taken at pin 6C (pin # 11). Second
output is applied at pin 2A (pin # 2) and its output from pin 2C (pin # 13) is again
connected to pin 7A (pin # 7) and final output is taken at pin 7C (pin # 10). This is done
due to two reasons. 1st is that the ULN2003 act as a logic inverter. It converts a „1‟ into
„0‟ and second time it is again inverted from „0‟ to „1‟. So we finally get the same output
which we have applied as an input with a current amplification. 2nd is that we need more
current to turn the relay on so due to double buffer we get enough current to derive a
relay.
The output of 1st relay is connected to the ignition coil of a car. The car will not start till
then relay is on (conducting). When the relay is off (cut) the signal will not reach to the
ignition coil so it will not start. When logic „1‟ came it gets amplified from ULN2003 and
turns the relay on so the car will start. The output of second relay is connected to a ringer.
When the user enter the Master (Administrator) password wrong for three attempts the
ringer will start ringing.
LCD BOARD
A small circuit is made using zero board. The 8 pin IDC connector take the LCD data
inputs from power board (Port 3) and connect them with this board. Here these pins are
connected with pin 7 to pin 14 of LCD. Pin 4, 5 & 6 are connected to port „0‟. A 5V
power is also provided on LCD board. Pin 1, 3 and 16 are connected to ground. Pin 2 and
15 are connected to +5V VCC.
Digital Security Lock
HITEC University Taxila 13
Results and Conclusions
We were exposed to high levels of difficulty while we were working with the project. It
was a very good learning experience and at times we had to work with circuits and
concepts which were very new to us. We have tested it many times and also attached it
with a motor bike for practical testing. It worked well and was proved as a good digital
lock.
FUTURE WORK
This project can be used as a door lock at secure places by addition of finger prints sensor
module. The person has to enter the code and then finger print sensor will scan its finger
prints and then it will grant access.
Also it can be used as a wireless digital lock for automobiles. The person has to enter the
code from handheld module which will transmit then signal after verification to open the
car then he can start it. I am also working on it if a person breaks the whole system and
directly start the car then the handheld module or through mobile communication the user
can stop the car. It will send a signal to another module which directly cut the ignition
coil from batteries and it will stop. The car can also be tracked later on.
Digital Security Lock
HITEC University Taxila 14
Appendix A
The whole programming code is given below.
#include <REGX51.H> #include<string.h> #define COL P2 #define ROW P1 void lcdcmd(unsigned char); void lcddata(unsigned char); void lcdprint(unsigned char *, unsigned char len); void lcdready(void); void msdelay(unsigned int); unsigned char getkey(void); bit check(unsigned char *,unsigned char *, unsigned char); void master_code(void); sfr ldata=0xB0; sbit rs=P0^0; sbit rw=P0^1; sbit en=P0^2; sbit busy=P3^7; sbit rel1=P0^3; sbit rel2=P0^4; unsigned char colloc, rowloc; unsigned char a[]="00077"; unsigned char master[6]="143143"; void main() { unsigned char ch[5]; unsigned char count; bit n; rel1=rel2=0; lcdcmd(0x38); lcdcmd(0x0E); lcdcmd(0x01); lcdcmd(0x85); lcdprint("Welcome",7); lcdcmd(0xC4); lcdprint("Theif Lock",10); msdelay(1000); lcdcmd(0x01); lcdcmd(0x80); count=0;
Digital Security Lock
HITEC University Taxila 1
for(count=0;count<3;count++) { lcdprint("Enter The Code",14); lcdcmd(0xC0); lcdcmd(0x0F); ch[0]=getkey(); lcddata(ch[0]); ch[1]=getkey(); lcddata(ch[1]); ch[2]=getkey(); lcddata(ch[2]); ch[3]=getkey(); lcddata(ch[3]); ch[4]=getkey(); lcddata(ch[4]); msdelay(500); n=check(a,ch,5); if(n==1) { count=10; lcdcmd(0x01); lcdcmd(0x02); lcdprint("Access Granted",14); rel1=1; rel2=1; msdelay(500); } else { lcdcmd(0x01); lcdcmd(0x02); lcdprint("Access Denied",13); rel1=rel2=0; msdelay(500); } lcdcmd(0x01); lcdcmd(0x02); } if(count>5) { lcdcmd(0x01); lcdcmd(0x80); lcdprint("Thanx 4 Using",13); msdelay(50); lcdcmd(0xC0); lcdprint("Thief Lock",10); while(1); }
Digital Security Lock
HITEC University Taxila 2
master_code(); lcdcmd(0x01); lcdcmd(0x02); lcdprint("Thanx 4 using",13); msdelay(25); lcdcmd(0xC0); lcdprint("Thief Lock",10); while(1); } void lcdcmd(unsigned char value) { lcdready(); ldata=value; rs=0; rw=0; en=1; msdelay(1); en=0; return; } void lcddata(unsigned char value) { lcdready(); ldata=value; rs=1; rw=0; en=1; msdelay(1); en=0; return; } void lcdprint(unsigned char *msg, unsigned char len) { int i; for(i=0;i<len;i++) { lcddata(msg[i]); } } void lcdready() { busy=1; rs=0; rw=1;
Digital Security Lock
HITEC University Taxila 3
while(busy==1) { en=0; msdelay(1); en=1; } return; } unsigned char getkey() { while(1) { do { ROW=0x00; colloc=COL; colloc&=0x0F; } while(colloc!=0x0F); do { do { msdelay(20); colloc=COL; colloc&=0x0F; } while(colloc==0x0F); msdelay(20); colloc=COL; colloc&=0x0F; } while(colloc==0x0F); while(1) { ROW=0xFE; colloc=COL; colloc&=0x0F; if(colloc!=0x0F) { rowloc=0; break; } ROW=0xFD;
Digital Security Lock
HITEC University Taxila 4
colloc=COL; colloc&=0x0F; if(colloc!=0x0F) { rowloc=1; break; } ROW=0xFB; colloc=COL; colloc&=0x0F; if(colloc!=0x0F) { rowloc=2; break; } ROW=0xF7; colloc=COL; colloc&=0x0F; rowloc=3; break; } if(colloc==0x0E&&rowloc==0) return('1'); else if(colloc==0x0E&&rowloc==1) return('4'); else if(colloc==0x0E&&rowloc==2) return('7'); else if(colloc==0x0E&&rowloc==3) return('*'); else if(colloc==0x0D&&rowloc==0) return('2'); else if(colloc==0x0D&&rowloc==1) return('5'); else if(colloc==0x0D&&rowloc==2) return('8'); else if(colloc==0x0D&&rowloc==3) return('0'); else if(colloc==0x0B&&rowloc==0) return('3'); else if(colloc==0x0B&&rowloc==1) return('6'); else if(colloc==0x0B&&rowloc==2) return('9'); else if(colloc==0x0B&&rowloc==3) return('#'); else if(colloc==0x07&&rowloc==0) return('A'); else if(colloc==0x07&&rowloc==1)
Digital Security Lock
HITEC University Taxila 5
return('B'); else if(colloc==0x07&&rowloc==2) return('C'); else if(colloc==0x07&&rowloc==3) return('D'); } } bit check(unsigned char *b1,unsigned char *b2, unsigned char len) { int k=0; for(k=0;k<=len;k++) { if(b1[k]!=b2[k]) return(0); } return(1); } void master_code() { bit n; unsigned char count; unsigned char m[6]="362481"; while(1) { lcdprint("Enter Mastr Code",16); lcdcmd(0xC0); lcdcmd(0x0F); m[0]=getkey(); lcddata(m[0]); m[1]=getkey(); lcddata(m[1]); m[2]=getkey(); lcddata(m[2]); m[3]=getkey(); lcddata(m[3]); m[4]=getkey(); lcddata(m[4]); m[5]=getkey(); lcddata(m[5]); msdelay(500); n=check(master,m,6); count=0; if(n==1) { count=10; lcdcmd(0x01);
Digital Security Lock
HITEC University Taxila 6
lcdcmd(0x02); lcdprint("Access Granted",14); rel1=1; rel2=0; msdelay(500); return; } else { lcdcmd(0x01); lcdcmd(0x02); lcdprint("Access Denied",13); rel1=rel2=0; msdelay(500);
lcdcmd(0x01); lcdcmd(0x02); if(count>=3) { rel1=0; rel2=1;
lcdprint("LOCKED",6); while(1);
} lcdcmd(0x01); lcdcmd(0x02); } } void msdelay(unsigned int time) { unsigned int i,j; for(i=0;i<time;i++) for(j=0;j<320;j++); }
Digital Security Lock
HITEC University Taxila 1
Appendix B[1]
ATMEL AT89S52 DATASHEET
Compatible with MCS®-51 Products
8K Bytes of In-System Programmable (ISP) Flash Memory
Endurance: 1000 Write/Erase Cycles
4.0V to 5.5V Operating Range
Fully Static Operation: 0 Hz to 33 MHz
Three-level Program Memory Lock
256 x 8-bit Internal RAM
32 Programmable I/O Lines
Three 16-bit Timer/Counters
Eight Interrupt Sources
Full Duplex UART Serial Channel
Low-power Idle and Power-down Modes
Interrupt Recovery from Power-down Mode
Watchdog Timer
Dual Data Pointer
Power-off Flag
Fast Programming Time
Flexible ISP Programming (Byte and Page Mode)
Green (Pb/Halide-free) Packaging Option
AT89C51 is available in three packages PDIP, PLCC and PQFP. We have used dual in line
package. Pin configuration of DIP with pin numbering is shown in figure A1.
Digital Security Lock
HITEC University Taxila 2
Figure A1: Pin-Configuration of ATMEL AT89S52
Figure A2: Block diagram of AT89S52
Digital Security Lock
HITEC University Taxila 3
ULN2003A DATASHEET [2]
Figure A3: Pin-Configuration of ULN2003A
Pin configuration with block diagram of ULN2003A is shown in figure A3. It has seven
input pins and seven output pins in front of the corresponding inputs for the purpose of
simplicity.
Figure A4
Digital Security Lock
HITEC University Taxila 4
Series circuit of ULN2003A for single driver is shown in figure A4.
ABSOLUTE MAXIMUM RATINGS
Symbol Value Parameter Unit
Vo Output Voltage 50 V
Vin Input Voltage 30 V
IC Continuous Collector Current
500 mA
IB Continuous Base Current
25 mA
Tamb Operating Ambient Temperature Range
-20 to 85 oC
Tstg Storage Temperature Range
-55 to 150 oC
TJ Junction Temperature 150 oC0
Table A1 for absolute maximum ratings of ULN2003Q
Digital Security Lock
HITEC University Taxila 5
BIBLIOGRAPHY
REFERENCES
[1] Datasheet, Type “ATMEL AT89S52”, Link http://www.google.com
[2] Datasheet, Type “ULN2003”, Link http://www.google.com
BOOKS
1) The 8051 Microcontroller and Embedded Systems, Edition “2nd”, Author
“Muhammad Ali Mazidi”, Publisher “Printice Hall”
2) Microcontroller 8051, Author “Hasanpur”, Company “Tehran University”