Professional Documents
Culture Documents
Individual Assignment
Page 1 of 32
1. Introduction
1.1 Objective
The objective of this project is to implement a password based door locking system by using the
microcontroller 68hc11/8051/8086 and to integrate the hardware and software in order to
simulate the functions of the above system. The microcontroller based Door locking system is an
access control system that allows only authorized persons to access a restricted area. The
password is stored in the EEPROM so that we can change it any time. The system has a 43
keypad which is used to enter the Password. A 162 LCD is also used to display the password
entered. If the entered password is correct then the system opens the door by rotating the door
motor. If the password is wrong then the door will remain closed and an alarm will be generated
to detect an unauthorized entry of a person.
Level 2
2015
Individual Assignment
Page 2 of 32
Moreover it can be implemented in homes. We often forget to carry door key. It is really difficult
to get inside the house. In offices security personnel checks the I-card of the employees to
restrict unauthorized entry or the employees sign a register before entrance. But if there are
multiple entry points it is not feasible to arrange security personnel at each gate as wells as it
would not be cost effective. This project solves these problems and is a substitute for bar code
recognition system, punch card system (Reddy,2011).
Level 2
2015
Individual Assignment
Page 3 of 32
ii.
iii.
iv.
Rotate the motor if password matches else send logic to complete buzzer circuit for
an alarming sound
Level 2
2015
Individual Assignment
Page 4 of 32
AT89C51 (Microcontroller)
This module comprises 8051 microcontroller (AT89C51). It belongs to Atmel family. Atmel
89C51 have flash programmable and erasable read only memory (PEROM). Flash memory is a
non volatile memory, which can be electrically erased read for lines and blocks. The mechanism
for erasing the memory is easier and faster than that needed for EEPROM. Typically, 1000
write/erase cycles are possible, which are more than sufficient for any application development.
The operating frequency of 89C51 could be from 0Hz to 24Hz.
Architectural overview of ATMEL89C51
Atmel AT89C51 is a powerful microcontroller which provides a highly flexible and cost
effective solution to many embedded control applications. Since AT89C51 architecture provides
32 bidirectional port pins along with two timers and 4Kbytes of flash memory, it makes the
choice ideal for the system is an RTC chip DS1307 from Dallas semiconductors, which
continuously updates the time and calendar information in its scratch pad RAM, considering leap
year compensation. Stability and accuracy of the clock is dependent on the accuracy of the clock
as well as matching of the capacitance between crystal oscillator and clock pins. There are two
16-bit timer/counters, one full duplex serial port, 128 bytes of on chip RAM, 32I/O lines, on chip
oscillator and clock circuitry. It support six interrupt sources. It consists of precision analog
comparator. It must be noted that pin P3.6 is not available externally; however it can be read in
software. P3.6 is the output of precision analog comparator
Atmel series AT89C51 is based on Harvard architecture. This processor includes internal
separated data memory (internal RAM) and program memory (internal Flash). It is possible to
connect external data memory and external program memory as well through I/O ports P0 and
P2 and control signals (detailed connection will be discussed later). Internal data memory and
program memory are separated into two different areas and are accessed at the same time via
data transfer instruction (like MOV A, 20H). External data and program memory shares the same
address and data bus, thus advantage of Harvard Design of Electronic Instruments Embedded
systems for industrial control 23 architecture is not utilized. But external data access instruction
(like MOVX A, @DPTR) and external program access instruction (MOVC A, @DPTR) still
differs (Soni,2010).
Level 2
2015
Individual Assignment
Page 5 of 32
Level 2
2015
Individual Assignment
Page 6 of 32
P3.7
WR
P3.7
T1
T0
P3.5
P3.4
INT1
P3.3
INT0
P3.2
TXD
P3.1
RXD
P3.0
Transmit data pin for serial port in UART mode. Clock output in shift
register mode.
Receive data pin for serial port in UART mode. Data I/O pin in shift
register mode.
Power supply pins VCC (Pin 40) and VSS (Pin 20)
8051 operates on d.c. power supply of +5V with respect to ground. The +5V is to be connected
to pins VCC and ground to pin VCC with rated power supply current of 125mA.
Oscillator pins XTAL (Pins 18 and 19)
For generating an internal clock signal, the external oscillator is connected at these two pins.
ALE (Address Latch Enable, Pin 30)
AD0 to AD7 lines are multiplexed. To demultiplex these lines and for obtaining lower half of an
address, an external latch and ALE signal of 8051 is used.
Level 2
2015
Individual Assignment
Page 7 of 32
RESET (Pin 9)
This pin is used to reset 8051. For proper reset operation, reset signal must be held high at least
for two machine cycles, while oscillator is running.
PSEN (Program Store Enable, Pin 29)
It is the active low output control signal used to activate the enable signal of the external
ROM/EPROM. It is activated every six oscillator periods while reading the external memory.
Thus, this signal acts as the read strobe to external program memory.
EA (External Access, Pin 31)
When the EA pin is high (connected to VCC), program fetches to address 0000H through 0FFFh
are directed to the internal ROM and program fetches to address 1000H through FFFFH are
directed to external ROM/EPROM. When EA is low (grounded), all addresses (0000H to
FFFFH) fetched by program are directed to the external ROM/EPROM.
2.1.2 LCD
A 162 LCD (Liquid Crystal display) is used to display the password entered. It is an electronics
display module and find a wide range of applications. The module is preferred over seven
segment display and other multi segment display LEDs. The reason being: LCDs are
economical, easily programmable, have no limitation of displaying special and even custom
characters (unlike in seven segments).
A 162 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD
each character is displayed in 57 pixel matrix. This LCD has the registers namely command and
data.
The command register stores the command instructions given to the LCD. A command is an
instruction given to LCD to do a predefined task like initializing it, clearing screen, setting the
cursor position, controlling display etc. the data register stores the data to be displayed on the
LCD. The data is the ASCII value of the character to be displayed on the LCD. PIN description
of 162 LCD is shown in table below:
Level 2
2015
Individual Assignment
Page 8 of 32
Function
Name
Ground (0V)
Supply voltage; 5V (4.7V 5.3V)
Contrast adjustment; through a variable resistor
Ground
Vcc
VEE
Selects command register when low; and data register when high
Register Select
5
6
7
8
9
10
11
12
13
14
15
16
Read/write
Enable
DB0
DB1
DB2
DB3
DB4
DB5
DB6
DB7
Led+
Led-
Level 2
2015
Individual Assignment
Page 9 of 32
2.1.3 Keypad
The 43 keypad contains push buttons that are arranged in four rows and three columns produce
twelve characters as shown in the figure below. It is made of thin, flexible membrane material
with an adhesive backing. The keys are connected into a matrix, so that we need 7
microcontroller pins (3columns and 4 rows) to scan through the pad. It is used to enter the
password in this project.
2.1.4 Motor Driver IC
Microcontroller operates at low voltages and require small amount of current to operate while the
motor requires a relatively higher voltages and current. This current cannot be supplied to the
motors from the microcontroller. That is why motor driver IC is used in this system.
The IC L293D is a dual H bridge IC which also provides sufficient current to drive a small
motor. Its Pin configuration is shown below. With one such IC DC motors can be driven which
can be controlled in both clockwise and counter clockwise directions. For the applications that
dont need reversal of direction, the four output pins can be used for driving four separate
motors. This IC is rated for an output current of 600mA and peak output current of 1.2A per
channel. Moreover for protection of this circuit against back EMF, snubber/flywheel diodes are
included within the IC (Das,1995).
Figure 4: L293D IC
Level 2
2015
Individual Assignment
Page 10 of 32
2.1.5 DC motor
A DC motor is used so that it can be further connected to solenoid to open the door.
A DC motor in simple words is a device that converts direct current (electrical energy) into
mechanical energy.
2.1.6 Buzzer
We are using a buzzer as an alarm to indicate the wrong password to open the door.
2.1.7 LM7805 (Voltage regulator)
The LM7805 monolithic 3-terminal positive voltage regulator employ internal current limiting,
thermal shutdown and safe area compensation, making them essentially indestructible. If
adequate heat sinking is provided, they can deliver over 1.0A output current. They are intended
as fixed voltage regulators in a wide range of applications including local regulation for
elimination of noise and distribution problems associated with single point regulation. In
addition to use as fixed voltage regulators, these devices can be used with external 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 power supply
(Mathew,2011).
Figure 5: LM7805 IC
Level 2
2015
Individual Assignment
Page 11 of 32
3. Circuit design
3.1 Working Principle
The circuit operates on the principle of microcontroller interfacing. A keypad interfaced to the
microcontroller is used to enter the password and store it. A LCD is interfaced to the
microcontroller to display the status and a motor is interfaced to the microcontroller via the
motor driver. The motor is first rotated forward to open the gate and then backward to close the
gate.
Level 2
2015
Individual Assignment
Page 12 of 32
and if it is equal then the Microcontroller will switch on the motor for the door and if we enter
the wrong password then an alarm will be switched on.
The password is stored in the EEPROM and the password can be changed by making changes in
program. The power supply section is the important one. It should deliver constant output
regulated power supply for successful working of the project. A 9V transistor battery is used as
power supply, which is further regulated to 5V, by using IC 7805.
Reset circuit design: The reset pin of the microcontroller is kept active till the power supply is in
specified range and minimum oscillation level is maintained. In other words to ensure the supply
voltage doesnt falls below the threshold level of 1.2V and the reset pulse width is greater than
100ms (for AT89C51), we select the values of resistor and capacitor such that RC100ms. Here
we select 8.2K ohm resistor and a 10F electrolyte capacitor.
Oscillator circuit design: A crystal oscillator is used to provide external clock signal of 24MHz
to the microcontroller. To forward the clock cycle in only one direction, we connect two ceramic
capacitors each of 33F. this crystal oscillator is connected between pin 18 and 19 of the
microcontroller.
Microcontroller interfacing design: A 43 keypad is interfaced to the microcontroller Port1
and a motor driver IC (L293D) is interfaced to microcontroller port pins P3.0 and P3.1. An LCD
is interfaced to the microcontroller such that the register select, read/write and enable pins are
connected to port pins P3.6, P3.7 and P3.8 respectively whereas the data pins are connected to
Port2.
Circuit design in Proteus: Circuit is designed and then simulated in Proteus.
Compilation of Microcontroller code: Once the circuit is designed and drawn on a piece of
paper, the next step is to write and compile the code. Here we select the keil vision software to
write the program in C language.
Prior to writing the code, the general steps needed to be followed like creating a new project and
selecting the target device or the required microcontroller. Once the code is written, we saved it
with .c extension and then added it to the source file group under the target folder. The code is
then compiled by pressing F7key.
Once the code is compiled, a hex file is created. In the next step, we use Proteus software to draw
the circuit. The code is dumped into the microcontroller by tight click on the same and then
Level 2
2015
Individual Assignment
Page 13 of 32
adding the hex file. The microcontroller oscillating frequency is selected here to be
11.0592MHz.
Once the circuit is powered, microcontroller sends commands to the LCD such that it is ready to
accept the data. This data is entered using the keypad. Once the data is entered, it is displayed on
the LCD. This data denotes the password. The password is entered using the keypad and it is
checked with the set password. If the passwords match, the microcontroller sends signals to the
motor driver such that pin P3.0 is at high level and pin P3.1 is at low level and the motor rotates
in forward direction. After a certain delay, the enable pin is grounded by sending a low logic
signal from the microcontroller and the motor stops. Again after some time delay, the
microcontroller sends signals to the motor driver such that P3.0 is at low logic level, P3.1 is ate
logic high level. The motor now rotates in backward direction. Now if the passwords do not
match, the microcontroller sends a logic low signal to the enable pin of the microcontroller, thus
disabling the motor driver and the motor does not rotates at all. The buzzer connected to the
pin1.7 gets logic high level and an alarming sound is heard that indicates wrong password.
3.3 Program
/*Password protected door locking system by Pankaj kumar*/
/*default password is 12345*/
#include<reg51.h>
#include<string.h>
#define lcdport P2
/*variable declaration of port pins using sbit*/
sbit rs=P3^4;
sbit rw=P3^5;
sbit en=P3^6;
sbit m1=P3^0;
sbit m2=P3^1;
sbit r1=P1^0;
sbit r2=P1^1;
sbit r3=P1^2;
sbit r4=P1^3;
Level 2
2015
Individual Assignment
Page 14 of 32
sbit c1=P1^4;
sbit c2=P1^5;
sbit c3=P1^6;
sbit buzzer=P1^7;
/*Function declaration with data type*/
char uid[]="12345";
char id[5];
void lcdint();
void user_id(char);
void lcdstring(char *);
void delay(int);
void lcdcmd(char);
void lcddata(char);
void check_id();
char scankey();
char check();
void door_open();
void door_close();
void sounder();
/*Main Program*/
void main()
{
int n;
char key;
P2=0x00;
P1=0xff;
buzzer=1;
lcdint();
lcdstring("system is locked");
lcdcmd(0xc0);
lcdstring("enter user id");
Level 2
2015
delay(100);
Individual Assignment
Page 15 of 32
//delay of 100ms
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("user_id");
lcdcmd(0xc0);
n=0;
while(n<5)
{
key=check();
id[n]=key;
lcddata(key);
delay(100);
n++;
}
lcdcmd(0x01);
lcdcmd(0x02);
/*If-else loop to check authenticity of password*/
if(strcmp(uid,id)==0)
{
lcdstring("id matched");
delay(200);
door_open();
door_close();
lcdcmd(0x01);
lcdcmd(0x02);
}
else
{
lcdstring("try again");
sounder();
delay(200);
Level 2
2015
Individual Assignment
Page 16 of 32
lcdcmd(0x01);
lcdcmd(0x02);
}
}
/*Function definition for buzzer*/
void sounder()
{
int i;
for(i=0;i<10;i++)
{
buzzer=0;
delay(100);
buzzer=1;
}
}
/*Function definition for opening door*/
void door_open()
{
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("opening door...");
m1=1;
m2=0;
delay(400);
}
/*Function definition for closing the door*/
void door_close()
{
lcdcmd(0x01);
lcdcmd(0x02);
lcdstring("closing door...");
Level 2
2015
Individual Assignment
Page 17 of 32
m1=1;
m2=0;
m1=0;
m2=1;
delay(400);
m1=0;
m2=0;
}
/*Function definition to check authenticity of pre programmed password*/
char check()
{
char b='a';
while(b=='a')
{
b=scankey();
}
return b;
}
char scankey()
{
c1=c2=c3=1;
r1=r2=r3=r4=0;
r1=0;r2=r3=r4=1;
if(c1==0)
{
delay(2);
return '1';
}
if(c2==0)
{
delay(2);
Level 2
2015
Individual Assignment
Page 18 of 32
return '2';
}
if(c3==0)
{
delay(2);
return '3';
}
r2=0;r1=r3=r4=1;
if(c1==0)
{
delay(2);
return '4';
}
if(c2==0)
{
delay(2);
return '5';
}
if(c3==0)
{
delay(2);
return '6';
}
r3=0;r1=r2=r4=1;
if(c1==0)
{
delay(2);
return '7';
}
if(c2==0)
{
Level 2
2015
Individual Assignment
Page 19 of 32
delay(2);
return '8';
}
if(c3==0)
{
delay(2);
return '9';
}
r4=0;r1=r2=r3=1;
if(c1==0)
{
delay(2);
return '*';
}
if(c2==0)
{
delay(2);
return '0';
}
if(c3==0)
{
delay(2);
return '#';
}
return 'a';
}
void lcdstring(char *p)
{
while(*p!='\0')
{
lcddata(*p);
Level 2
2015
Individual Assignment
Page 20 of 32
delay(10);
p++;
}
}
void lcdint()
{
lcdcmd(0x38);
delay(2);
lcdcmd(0x01);
delay(2);
lcdcmd(0x80);
delay(2);
lcdcmd(0x0e);
delay(2);
}
/*Function definition of delay*/
void delay(int x)
{
int i,j;
for(i=0;i<x;i++)
for(j=0;j<1275;j++);
}
/*Function definition to initialize LCD*/
void lcdcmd(char a)
{
lcdport=a;
rs=0;
rw=0;
en=1;
delay(1);
en=0;
Level 2
2015
Individual Assignment
Page 21 of 32
}
void lcddata(char value)
{
lcdport=value;
rs=1;
rw=0;
en=1;
delay(1);
en=0;
}
Level 2
2015
Individual Assignment
Page 22 of 32
4. Results
4.1 Screen shots of keil and Proteus window
Level 2
2015
Individual Assignment
Page 23 of 32
Level 2
2015
Individual Assignment
Page 24 of 32
The circuit is simulated in Proteus. The LCD displays user_id text indicates the user to enter
password. The two red dots on Pin 2 & 7 of Motor driver IC (L293D) in the figure below shows
that motor is not rotating. The two pins of buzzer having red dots indicating both are at high
signal (Buzzer not working as both terminals are getting high signal logic).
Level 2
2015
Individual Assignment
Page 25 of 32
The pre-programmed password i.e. 12345 is entered through keypad. The LCD displays the
message id matched.
Level 2
2015
Individual Assignment
Page 26 of 32
Here we can notice the color of dots of pins of IC changes indicating that one pin is getting high
voltage and second is getting low voltage. This shows that motor is rotating but still the buzzer is
off.
Level 2
2015
Individual Assignment
Page 27 of 32
Again user enters the password, but this time the password is unmatched. This time the pins of
Buzzer get both high and low voltage which results in an alarming sound. The LCD displays the
message try again to reenter the password.
Level 2
2015
Individual Assignment
Page 28 of 32
Level 2
2015
Individual Assignment
Page 29 of 32
Level 2
2015
Individual Assignment
Page 30 of 32
5. Conclusion
The goal of this project was to build a password protected door locking system. The goal was
successfully achieved. The circuit was designed in Proteus. The program for this system was
written in c language. Then this program was compiled in Keil vision. After compilation, hex
file was created. This hex file was dumped to microcontroller in Proteus and the circuit was
simulated. The pre-programmed password was entered using keypad. If the password matches
the pre programmed password the motor rotates else it gives an alarming sound. The default
password is 12345. The same circuit was build on a copper PCB.
5.1 Limitations
It is battery operated circuit and can easily run out of power once the battery life time
ends.
It is a low range circuit, i.e. it is not possible to operate the circuit remotely.
5.2 Applications
The term access control refers to the practice of restricting entrance to a property, a building or a
room to authorized persons. Integrated and controller based access control numeric and
alphabetic keyless entry keypads with programmable features for the access control of single
openings. The various applications are as follows:
Industrial facilities
Commercial building
Research centre
Airports
Military base
Electrical device such as lights, computers etc. can be controlled by using separate
passwords.
Level 2
2015
Individual Assignment
Page 31 of 32
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 and also 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 classroom
with their respective password. We can send this data to a remote location using mobile
or internet.
Level 2
2015
Individual Assignment
Page 32 of 32
6. References
1. Electronics Hub (2014) Password Based Door Lock System using 8051 Microcontroller.
[Online]
Available
from:
http://www.electronicshub.org/password-based-door-lock-
[Online]
Delhi:
Universal
Publishers.
Available
from:
https://
books.google.co.in/books?id=dJ3EqEZslGQC&pg=PA133&dq=Atmel+AT89C51+is+a+
powerful+microcontroller+which+provides+a+highly+flexible+and+cost+effective+solut
ion+to+many+embedded+control+applications.&hl=en&sa=X&ei=ZwkyVeaBNcm5uA
TgnICABg&ved=0CCYQ6AEwAA#v=onepage&q=Atmel%20AT89C51%20is%20a%2
0powerful%20microcontroller%20which%20provides%20a%20highly%20flexible%20a
nd%20cost%20effective%20solution%20to%20many%20embedded%20control%20appli
cations.&f=false . [Accessed: 28/03/2015]
Level 2
2015