You are on page 1of 58

VIETNAM GENERAL CONFEDERATION OF LABOUR

TON DUC THANG UNIVERSITY


FACULTY OF ELECTRICAL AND ELECTRONIC

EMBEDDED SYSTEM PROJECT

SERVO CONTROL SYSTEM ADOPTS


THE METHOD OF OPENING THE
DOOR BY PASSWORD AND RFID
MAGNETIC CARD

Instructor: DR.LE ANH TUAN


Executor: NGUYEN HUU TRIEN
Grade : 19H40301
Course: 2019

Ho Chi Minh city, year 2022


VIETNAM GENERAL CONFEDERATION OF LABOUR
TON DUC THANG UNIVERSITY
FACULTY OF ELECTRICAL AND ELECTRONIC

EMBEDDED SYSTEM PROJECT

SERVO CONTROL SYSTEM ADOPTS


THE METHOD OF OPENING THE
DOOR BY PASSWORD AND RFID
MAGNETIC CARD

Instructor: DR.LE ANH TUAN


Executor: NGUYEN HUU TRIEN
Grade : 19H40301
Course: 2019

Ho Chi Minh city, year 2022

i
ACKNOWLEDGMENT
I would like to thank the teachers of the Faculty of Electrical and
Electronics Engineering at Ton Duc Thang University majoring in Control and
Automation Engineering for teaching and imparting valuable knowledge to me
during my study period. and practice at school. I thank lecturer Dr. Le Anh Tuan for
helping me throughout the process of making the project and giving me a lot of new
and useful knowledge, helping me to expand my knowledge.

Ho Chi Minh city, month 11 day 7 year 2022


Author
Nguyen Huu Trien

ii
WORK IS COMPLETED
AT TON DUC THONG UNIVERSITY
I hereby declare that this is my own research work and under the scientific guidance
of Le Anh Tuan; The content and research results in this topic are honest and have
not been published in any form before. The data in the analysis tables, comments
and assessments are collected by the author himself from different sources, clearly
stated in the reference section.
In addition, the thesis also uses some comments, assessments as well as data of
other authors, other agencies and organizations, all with citations and source
annotations.
If I find any fraud, I will take full responsibility for the content of my thesis.
Ton Duc Thang University is not related to copyright and copyright violations
caused by me during the implementation process (if any).

Ho Chi Minh city, month 11 day 7 year 2022


Author

NGUYEN HUU TRIEN

iii
CONTENTS

LIST OF FIGURE...........................................................................................................vii

CHAPTER 1. OVERVIEW OF TOPIC..........................................................................1

1.1 INTRODUCTION TO THE TOPIC........................................................................................1


1.2 RESEARCH PURPOSES.................................................................................................1
1.3 RESEARCH SUBJECTS..................................................................................................1
1.4 RESEARCH SCOPE.......................................................................................................1
1.5 EXPECTED RESULTS....................................................................................................1

CHAPTER 2. THEORETICAL BASIS...........................................................................3

2.1 MICROCONTROLLERS.................................................................................................3
2.2 RFID APPLICATION.............................................................................................13
2.3 KEYPAD (3X4)..........................................................................................................15
2.4 LIQUID-CRYSTAL DISPLAY (LCD)...........................................................................17
2.5 SERVO MOTOR..........................................................................................................19

CHAPTER 3. BLOCK DIAGRAM AND CONTROL ALGORITHMS....................22

3.1 BLOCK DIAGRAM..........................................................................................................22


3.2 CONTROL ALGORITHMS...............................................................................................22

CHAPTER 4. CIRCUIT DESIGN AND MODEL CONSTRUCTION......................24

4.1 CIRCUIT DESIGN......................................................................................................24


4.1.1 Principle diagram.................................................................................................24
4.1.2 PCB layout............................................................................................................25
4.1.3 Actual circuit.........................................................................................................26
4.2 MODEL CONSTRUCTION................................................................................................27
4.2.1 Model technical drawings.....................................................................................27
4.2.2 Complete model.....................................................................................................28

CHAPTER 5. EXPERIMENT........................................................................................29

iv
5.1 EXPERIMENTAL PROGRESS.......................................................................................29
5.2 EXPERIMENTAL RESULTS..........................................................................................29

CHAPTER 6. CONCLUSION........................................................................................40

6.1 ADVANTAGES...............................................................................................................40
6.2 DISADVANTAGES..........................................................................................................40
6.3 DEVELOPMENT.............................................................................................................40

APPENDIX 1....................................................................................................................41

REFERENCES.................................................................................................................50

v
LIST OF FIGURE

FIGURE 2-1: PIC 16F877A..............................................................................................4

FIGURE 2-2: PIC16F877A GENERAL STRUCTURE.................................................5

FIGURE 2-3: RC522........................................................................................................15

FIGURE 2-4: MATRIX KEYPAD.................................................................................16

FIGURE 2-5: KEYPAD DIAGRAM.............................................................................16

FIGURE 2-6: LCD 20X4.................................................................................................17

FIGURE 2-7: ASCII CODE TABLE FOR LCD..........................................................18

FIGURE 2-8: SERVO......................................................................................................19

FIGURE 2-9: PWM FOR SERVO.................................................................................20

FIGURE 2-10: TC301......................................................................................................21

FIGURE 4-1: PRINCIPLE DIAGRAM ON PROTEUS.............................................24

FIGURE 4-2: PCB LAYOUT.........................................................................................25

FIGURE 4-3: ACTUAL CIRCUIT................................................................................26

FIGURE 4-4: ACTUAL CIRCUIT................................................................................27

FIGURE 4-5: COMPLETE MOD..................................................................................28

FIGURE 5-1: HOME SCREEN.....................................................................................29

FIGURE 5-2: ENTER THE PASS.................................................................................30

FIGURE 5-3: CORRECT PASS.....................................................................................31

FIGURE 5-4: CORRECT CARD...................................................................................32

FIGURE 5-5: INCORRECT PASS................................................................................33

FIGURE 5-6: ALLOWED IS 2.......................................................................................34

FIGURE 5-7: INCORRECT CARD..............................................................................35

FIGURE 5-8: ALLOWED IS 1.......................................................................................36

FIGURE 5-9: INCORRECTLY MORE THAN 3 TIMES ALLOWED.....................37

vi
FIGURE 5-10: CHANGE PASS.....................................................................................38

FIGURE 5-11: COMPLETE PASSWORD CHANGE................................................39

vii
PROJECT OF EMPLOYED SYSTEMS
Page 1/51

CHAPTER 1. OVERVIEW OF TOPIC

1.1 Introduction to the topic

Users can choose 1 of 2 ways, enter the password and scan the card to unlock the
door. When you enter the correct password, the system will ask if you want to
change the password. The maximum allowed number of times to enter and scan the
card is 3 times, if the allowed number is exceeded, the system will automatically
alarm a thief to break into your house.

1.2 Research purposes

Apply the knowledge learned from the subject of microcontrollers. I want to create
an automatic door opening system, in order to improve the safety and security of the
door opening system, it will be through two functions that are password and
magnetic card.

1.3 Research subjects

Microcontroller PIC 16F877A, LCD, Servo SG90, RC522-RFID, matrix keypad.

1.4 Research scope

Smart magnetic door with accurate processing and good security, ensuring safety
for households, offices or factories.

1.5 Expected results

The system requires the user to enter the password or will scan the card directly,
after performing those operations, the LCD screen will display two states. If the
user enters the correct password and scans the card correctly, the LCD will show the
user that the password and card are correct, if not, the display will be incorrect and
the buzzer will sound. If the allowed number of access times is exceeded, the siren

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 2/51

will sound an alarm. In addition, the system also has a function to change the
password that the user wants to change.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 3/51

CHAPTER 2. THEORETICAL BASIS

2.1 Microcontrollers

Microcontroller is a computer integrated on a chip, it is often used to control


electronic devices. A microcontroller, in essence, is a system consisting of a
microprocessor with sufficient performance and low cost (different from general-
purpose microprocessors used in computers) combined with peripheral blocks such
as a microprocessor. memory, input/output modules, digital-to-analog and analog-
to-digital conversion modules, etc. In computers, modules are usually built by chips
and external circuits.

Microcontrollers are commonly used to build embedded systems. It is also used in


electrical and electronic equipment such as washing machines, microwave ovens,
telephones, DVD players, multimedia equipment or automated production lines, etc.

The processor in this system is 16F877A.

PIC16F877A is a 40-pin PIC Microcontroller and is used mostly in embedded


projects and applications. It has five ports starting from port A to port E. It has three
timers of which two are 8-bit timers and one is 16-bit timers. It supports many
communication protocols such as serial protocol, parallel protocol, I2C protocol.
The PIC16F877A supports both hardware pin interrupts and timer interrupts.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 4/51

Figure 2-1: PIC 16F877A

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 5/51

Figure 2-2: PIC16F877A General Structure

Table pin of pic 16F877a


Pin Name Function

- / MCLR: Active low


reset
1 /MCLR/VPP
- VPP: programmable
voltage input

– RA0: input/output

2 RA0/AN0 number

– AN0 : analog input

– RA1: output/import

3 RA1/AN1 numbers

– AN1 : analog input

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 6/51

– RA2: output/import
numbers

– AN 2: analog input
4 RA2/AN2/VREF-/CVREF
– ON-: standard (low)
voltage input of the A/D
unit

– RA3: output/import
numbers

– AN3 : analog input


5 RA3/AN3/VREF+
– VREF+ : standard
(high) voltage input of
A/D . unit

– RA4: output/import
numbers

– TOCKI : external clock


6 RA4/TOCKI/C1OUT
input for timer0

– C1 OUT : 1 .
comparator output

7 RA5/AN4//SS /C2OUT – RA5: output/import


numbers

– AN4 : 4 . analog input

– SS : auxiliary SPI
selection input

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 7/51

– C2 OUT : 2 .
comparator output

– RE0 : input and output


numbers

8 RE0//RD/AN5 – RD : control reading at


parallel branch port

– AN5 : analog input

– RE1 : output/import
numbers

9 RE1//WR/AN6 – WR : control writing at


parallel branch port

– AN6 : analog input

– RE2: export/import
numbers

– CS : Control selection
10 RE2//CS/AN7
chip at parallel branch
port

– AN7: analog input

11 VDD Power pin of PIC

12 VSS Ground pin

13 OSC1/CLKI External clock or quartz


oscillator input.

– OSC1 : quartz oscillator

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 8/51

input or external clock.


Schmit trigger input
when configured in RC
mode; another way of
CMOS.

– CLKI: external pulse


source input. Always
associated with OSC1
functionality.

Clock or quartz oscillator


input

– OSC2 : Quartz
oscillator output. Connect
to quartz or resonator.
14 OSC2/CLKO
– CLKO: in RC mode,
the output of OSC2,
equals the frequency of
OSC1 and indicates the
speed of the instruction
cycle.

15 RC0/T1 OCO/T1CKI – RC0 : input/output


number

– T1OCO : 1 . Timer
oscillator input

– T1CKI : Timer 1 .

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 9/51

external clock input

– RC1 : output/import
numbers

– T1OSI: Timer 1 .
16 RC1/T1OSI/CCP2 oscillator input

– CCP2 : Capture 2 input,


compare 2 output, PWM2
. output

– RC2: output/import
numbers

17 RC2/CCP1 – CCP1 : Capture 1 input,


compare 1 output, PWM1
. output

– RC3: output/import
numbers

– SCK : synchronous
serial clock input/output
18 RC3/SCK/SCL
of SPI . mode

– SCL: synchronous
serial clock input/output
of I2C mode

19 RD0/PSP0 – RD0: output/import


numbers

– PSP0 : parallel branch

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 10/51

port data

– RD1: output/import
numbers
20 RD1/PSP1
– PSP1 : parallel branch
port data

– RD2: output/import
numbers
21 RD2/PSP2
– PSP2 : parallel branch
port data

– RD3: output/import
numbers
22 RD3/PSP3
– PSP3: parallel branch
port data

– RC4: output/import
numbers

23 RC4/SDI/SDA – SDI: data to SPI

– SDA: export/import
data to I2C

– RC5: output/import

24 RC5/SDO numbers

– SDO: SPI output data

25 RC6/TX/CK – RC6: output/import


numbers

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 11/51

– TX: asynchronous
transmission USART

– CK : USART
synchronous pulse

– RC7: output/import
numbers

– RX : get disagreement
26 RC7/RX/DT
USART

– DT : USART
synchronous data

– RD4: output/import
numbers
27 RD4/PSP
– PSP4: parallel branch
port data

– RD5: output/import
numbers
28 RD5/PSP5
– PSP5: parallel branch
port data

– RD6: output/import
numbers
29 RD6/PSP6
– PSP6: parallel branch
port data

30 RD7/PSP7 – RD7: output/import

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 12/51

numbers

– PSP7: parallel branch


port data

31 VSS Ground pin

32 VDD Power pin of PIC

– RB0: output/import

33 RB0/INT numbers

– INT : external interrupt

34 RB1 Export/import number

35 RB2 Export/import number

– RB3: output/import
numbers
36 RB3
– ICPS . low voltage
programming enable pin

– Export/import numbers
37 RB4
– PortB interrupt

– Export/import numbers
38 RB5
– PortB interrupt

39 RB6/PGC – RB6: output/import


numbers

– PGC : ICSP
programming clock and

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 13/51

differential circuit

– PortB interrupt

– RB7: output/import
numbers

– PGD: differential
40 RB7/PGD
circuit and ICSP
programming data

– PortB interrupt

2.2 RFID APPLICATION

RFID: Radio Frequency Identification, Radio Frequency Identification) is a


technology that uses electromagnetic fields to automatically identify and track these
assistive technology tags attached to objects. . An RFID system consists of a small
transponder, a receiver and a radio transmitter. When triggered by an
electromagnetic pulse to query data from a nearby RFID reader, the RFID tag
responds with numeric data, usually a value that identifies the tag itself, to the RFID
reader. The return value from this RFID tag can be used to track objects, such as
goods, equipment, etc. Is an automatic identification method based on the data
storage of the devices. remote device, RFID is therefore an Automated
Identification and Data Collection (AIDC) method.

An RFID tag consists of 3 components: a chip to store and process information,


modulation and demodulation of radio frequency signals; an antenna to receive and
send signals; and a substrate. The information of the RFID tag is stored in the
EEPROM memory.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 14/51

RFID tags can be passive, active or passive tags with batteries. The active tag sends
data and has a pin to power it. With a passive tag, its antenna will collect energy
from radio waves to power the IC, so passive tag will be cheaper because it doesn't
need battery to power.

RFID tags can be read-only tags, with a serial number from the manufacturer for
data management, or read/write enabled tags, with special data to be written to the
tag by the user. system. Programmable tags can be written once and read many
times, blank tags can be written with an electronic product code by the user.

RFID tags receive a query request and respond with its identifier (ID) information
and more. This can be the card's unique serial number, or product-related
information, such as stock or batch numbers, manufacturing dates, or other specific
information. Since each RFID tag has its own serial number, an RFID system can
be designed to read multiple tags at once, as long as they are within range of the
RFID reader.

Figure 2-3: RC522

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 15/51

2.3 Keypad (3x4)

A key matrix is a set of buttons connected by rows and columns. The corresponding
number of buttons will be the product of the number of rows x number of columns.
To control 12 buttons, normally we have to use 16 GPIOs but if using matrix keys
we only need to use 8 GPIOs.

Figure 2-4: Matrix keypad

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 16/51

Figure 2-5: Keypad diagram

2.4 Liquid-Crystal Display (LCD)

Figure 2-6: LCD 20x4

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 17/51

Produced since 1970, LCD is a kind of material that reflects light when voltage
changes. It works on the principle of background light (Back Light). It consists of a
liquid layer between two layers of light-polarizing glasses. Normally, in the absence
of voltage, these crystals are aligned between the two layers allowing light to pass
through in a spiral. Two polarizers, two color filters, and two equalizers determine
the intensity of the light that passes through and what color is produced on a pixel.
When voltage is applied, the alignment layer will create an area of charge, aligning
those liquid crystals. It does not allow light to pass through to display the image at
that pixel location. The pixels in an LCD screen are a tiny transistor that can do one
of two things: let light through or not. Pixels consist of 3 color elements: red, green,
and blue. Previously LCD screens used to consume a lot of power, low contrast
until British scientists found "Biphenyl" - the main material of liquid crystals, then
LCD was really popular. LCD first appeared in handheld computers, handheld
video games, electronic watches, etc. Today's LCD is compact, lightweight, takes
up little space, has good image quality, and consumes less. energy and is gradually
replacing CRT monitors.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 18/51

Figure 2-7: ASCII CODE TABLE FOR LCD

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 19/51

2.5 Servo motor

Figure 2-8: Servo


A servo is a specific type of motor that is combined with a rotary encoder (encoder
or PWM) or a potentiometer to form a servo. This assembly may in turn form part
of another servomechanism. A potentiometer is intended to provide a simple analog
signal to indicate the position, while an encoder provides the position and usually
the response rate, where using a PID controller allows more precise control of the
position and thus achieving a stable position faster (for a given motor). The
potentiometers can drift when the temperature fluctuates while the encoder is more
stable and accurate.

Servo mechanisms are used for both high end and low end applications. High end
are precision industrial components using a rotary encoder. Low-end are
inexpensive radio-controlled servos (RC servos) used in radio-controlled models
that use a free-motion motor and a simple potentiometer position sensor with a
controller. embedded control. The term servo motor usually refers to a high-end
industrial component while the term servo is often used to describe inexpensive
devices that use a potentiometer. Stepper Motors Stepper motors are not considered
servomotors, although they are also used to make larger servos. Stepper motors

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 20/51

have inherent angular position, due to their construction, and this is often used in an
open-loop manner without the need for a feedback signal. They are generally used
for applications with moderate accuracy.

RC servos are used to provide drive to various mechanical systems such as the
steering system of a car, the control surfaces of an airplane, or the rudder of a boat.
Due to their affordability, reliability, and simplicity of being controlled by
microprocessors, they are often used in small-scale robotic applications. A standard
RC receiver (or a microcontroller) sends pulse width modulation (PWM) signals to
this servo. The electronics inside this servo translate this pulse width into a position
signal. When the servo is ordered to rotate, the motor is powered until the
potentiometer reaches the value corresponding to the command position.

Figure 2-9: PWM for servo

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 21/51

In order for the servo to control the rotation angle more smoothly at will, we can use
the TC301 . circuit

Figure 2-10: TC301

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 22/51

CHAPTER 3. BLOCK DIAGRAM AND CONTROL ALGORITHMS

3.1 Block diagram

KEY PAD RC522


(RFID

PIC 16F877A

TC301

BUZZER

SERVO

POWER 5V

3.2 Control Algorithms

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 23/51

START

INITIALIZATION
OF SYSTEM

CARD SCAN
PRESS A PAS

CORRECT
CHECK PASS CHECK CARD

SERVO
CONTROL

BUZZER AND
WARNING
INCORRECT

END

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 24/51

CHAPTER 4. CIRCUIT DESIGN AND MODEL CONSTRUCTION

4.1 CIRCUIT DESIGN

4.1.1 Principle diagram

Figure 4-1: Principle diagram on Proteus

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 25/51

4.1.2 PCB layout

Figure 4-2: PCB layout

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 26/51

4.1.3 Actual circuit

Figure 4-3: Actual circuit

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 27/51

Figure 4-4: Actual circuit

4.2 Model construction

4.2.1 Model technical drawings

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 28/51

4.2.2 Complete model

Figure 4-5: Complete mod

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 29/51

CHAPTER 5. EXPERIMENT

5.1 Experimental progress

Step 1: Supply power and measure power to the circuit.


Step 2: Enter password or scan card.
Step 3: If correct, then the servo motor is open.
Step 4: If incorrect, then the buzzer is active.
Step 6: After entering the correct password, the program will display a '*' character
for the user to change the password if desired.
Step 7: Enter the new password, the system will save the user's new password.

5.2 Experimental results

Figure 5-1: Home screen

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 30/51

Start the system, the system will ask us to enter the password. If we enter it wrong,
press the ‘*’ character corresponding to clear to clear it

Figure 5-2: Enter the pass

The default password will be 4 zeros.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 31/51

Figure 5-3: Correct pass

When the password is correct, the LCD will be displayed. At this time the door will
be opened and after 10 seconds will close automatically.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 32/51

Figure 5-4: Correct card

If we don't use a password to open the door, we can use a magnetic card to do it.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 33/51

Figure 5-5: Incorrect pass

When we scan wrong password and wrong card, the system will report an error and
reduce access to the system.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 34/51

Figure 5-6: Allowed is 2

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 35/51

Figure 5-7: Incorrect card

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 36/51

Figure 5-8: Allowed is 1

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 37/51

Figure 5-9: Incorrectly more than 3 times allowed

When wrong 3 times, the system will automatically lock and alert the user.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 38/51

Figure 5-10: Change pass

Next is the password change section, when we enter the correct password, the
system will display on the LCD as "Press (*)". When we click on it we will be
given a new password that we want to use.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 39/51

Figure 5-11: Complete password change

Enter the new password after entering the new password, the LCD screen will show
saved.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 40/51

CHAPTER 6. CONCLUSION

6.1 Advantages

Absolute safety.
Easy to access and use.
The processing speed of the microcontroller is very accurate.

6.2 Disadvantages

If the system loses power, it will be unusable. This is the biggest drawback of the
current system, we have to wait until there is electricity to use the system. And the
password will reset to the default level.

6.3 Development

To overcome the power failure when encountering a problem. The system will be
supplemented with backup power. This will make the system more flexible and no
longer encounter problems when there is a power outage.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 41/51

Appendix 1

Control program in C language


#include <16F877A.H>
#fuses PUT,HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20M)
#use RS232(baud=9600, xmit=pin_c6,rcv=pin_c7)
#define buzzer pin_d7
#define servo pin_d0
#define MFRC522_CS pin_d2
#define MFRC522_SCK pin_d3
#define MFRC522_SI pin_c4
#define MFRC522_SO pin_c5
#define MFRC522_RST pin_d4
#include<Built_in.h>
#include <lcd.h>
unsigned char code[13] = {' ','1','4','7','*','2','5','8','0','3','6','9','#'};
int key=13;
char num[4];
char data[5]={0X1B,0X5D,0XCA,0X37,0XBB};
int n;
int8 i=0,card_1=0,tmp=0,pass;
char UID[6];
unsigned int TagType;
void screen1()
{
lcd_putc('*');
}
void screen2()
{
lcd_putc(num[i]);
}
void save_pass()
{
for(i=1;i<=4;)
{
if(i==1)

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 42/51

{
write_eeprom(0x00 + i,num[i]);
}
if(i==2)
{
write_eeprom(0x00 + i,num[i]);
}
if(i==3)
{
write_eeprom(0x00 + i,num[i]);
}
if(i==4)
{
write_eeprom(0x00 + i,num[i]);
}
i++;
}
A: lcd_gotoxy(27,1);
lcd_putc("SAVING...");
output_high(buzzer);
delay_ms(5000);
reset_cpu();
}
void keypress()
{
key =13;
//quet cot 1
output_high(pin_b5);
output_low(pin_b6);
output_low(pin_b7);
if(input(pin_b1)==1)
{
key = 1;
}
else if(input(pin_b2)==1)
{
key = 2;
}

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 43/51

else if(input(pin_b3)==1)
{
key = 3;
}
else if(input(pin_b4)==1)
{
key = 4;
}
output_low(pin_b5);
output_high(pin_b6);
output_low(pin_b7);
if(input(pin_b1)==1)
{
key = 5;
}
else if(input(pin_b2)==1)
{
key = 6;
}
else if(input(pin_b3)==1)
{
key = 7;
}
else if(input(pin_b4)==1)
{
key = 8;
}

output_low(pin_b5);
output_low(pin_b6);
output_high(pin_b7);

if(input(pin_b1)==1)
{
key = 9;
}
else if(input(pin_b2)==1)
{

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 44/51

key = 10;
}
else if(input(pin_b3)==1)
{
key = 11;
}
else if(input(pin_b4)==1)
{
key = 12;
}
}
void keycheck()
{
unsigned int8 tam;
keypress();
if(key!=13);
{
delay_ms(10);
keypress();
if(key!=13)
{
tam=key;
while(key!=13)
{
keypress();
}
key=tam;
}
}
}
int1 quet_the(char data[],char UID[])
{
for (int j=0;j<4;j++)
{
if(UID[j]== data[j] )
{
card_1=1;
}

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 45/51

else
{
card_1=0;
break;
}
}
return card_1;
}
void scan_card()
{
if(MFRC522_isCard (&TagType))
{
if(MFRC522_ReadCardSerial (&UID))
{
card_1 = quet_the(data,UID);
if(card_1==1)
{
if(tmp==0)
{
lcd_putc('\f');
lcd_gotoxy(5,1);
lcd_putc("WELLCOME HOME!");
lcd_gotoxy(7,3);
lcd_putc("DOOR OPEN!");
output_high(servo);
delay_ms(20000);
output_low(servo);
n=0;
reset_cpu();
}
}
else
{
lcd_putc('\f');
lcd_gotoxy(4,1);
lcd_putc("Incorrect Card!");
lcd_gotoxy(6,3);
lcd_putc("DOOR CLOCK!");

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 46/51

lcd_gotoxy(3,4);
lcd_putc("PLEASE TRY AGAIN!");
n++;
output_high(buzzer);
delay_ms(5000);
reset_cpu();
}
}
}
}

void setpass() //ham dat mat khau moi


{
output_low(pin_c0);
A: lcd_putc('\f');
lcd_gotoxy(3,1);
lcd_putc("Enter New Password");
lcd_gotoxy(21,2);
lcd_putc("(*):Clear");
lcd_gotoxy(8,2);
for(i=1;i<=4;)
{
keypress();
keycheck();
if(key==4)
{
i=1;
goto A;
}
if(key!=13)
{
num[i]=code[key];
screen1();
i++;
}

}
save_pass();

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 47/51

}
void test()
{
lcd_putc('\f');
if((num[1]==48)&&(num[2]==48)&&(num[3]==48)&&(num[4]==48)&&pass==0)
{
goto A;
}
if((num[1]==read_eeprom(0x00+1))&&(num[2]==read_eeprom(0x00+2))&&(num[3]==read_eeprom(0x00
+3))&&(num[4]==read_eeprom(0x00+4))&&pass==1)
{
goto A;
}
else
{
lcd_putc('\f');
lcd_gotoxy(4,1);
lcd_putc("Incorrect Pass!");
lcd_gotoxy(6,3);
lcd_putc("DOOR CLOCK!");
lcd_gotoxy(3,4);
lcd_putc("PLEASE TRY AGAIN!");
n++;
output_high(buzzer);
delay_ms(5000);
goto B;
}

A: lcd_gotoxy(5,1);
lcd_putc("WELLCOME HOME!");
lcd_gotoxy(7,3);
lcd_putc("DOOR OPEN!");
output_high(servo);
delay_ms(20000);
output_low(servo);
n=0;
lcd_gotoxy(21,2);
lcd_putc("PRESS(*) BACK(#)");

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 48/51

for(i=0;i<=1;)
{
keypress();
keycheck();
if(key==4)
{
pass=1;
setpass();
i++;
}
if(key==12)
{
reset_cpu();
i++;
}
}

B: i=0;
reset_cpu();
}
void mode1()
{
A: lcd_putc('\f');
lcd_gotoxy(4,1);
lcd_putc("Enter the pass");
lcd_gotoxy(21,1);
printf(lcd_putc,"ALLOWED: %d", 3-n);
lcd_gotoxy(21,2);
lcd_putc("(*):Clear ");
lcd_gotoxy(8,2);
for(i=1;i<5;)
{
keypress();
keycheck();
scan_card();
if(key==4)
{
i=1;

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 49/51

goto A;
}

if(key!=13)
{
num[i]=code[key];
screen1();
i++;
}
if(n==3)
{
lcd_putc('\f');
lcd_gotoxy(7,3);
lcd_putc("WARNING!!!");
output_high(buzzer);
delay_ms(1000);
}
}
test();
}
void main()
{
set_tris_b(0x00);
set_tris_c(0x00);
set_tris_d(0x00);
set_tris_e(0x00);
output_low(buzzer);
lcd_init();
MFRC522_Init();
while(true)
{
mode1();
}
}

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 50/51

REFERENCES

[1] Textbook of PIC Microcontroller Engineering, authored by Dr. Dang Phuoc


Vinh (editor), co author Dr. Vo Nhu Thanh, Construction Publisher 2019.

Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien

You might also like