Professional Documents
Culture Documents
LeAnhTuan DAHTN NguyenHuuTrien 419H0182
LeAnhTuan DAHTN NguyenHuuTrien 419H0182
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.
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).
iii
CONTENTS
LIST OF FIGURE...........................................................................................................vii
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 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
vi
FIGURE 5-10: CHANGE PASS.....................................................................................38
vii
PROJECT OF EMPLOYED SYSTEMS
Page 1/51
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.
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.
Smart magnetic door with accurate processing and good security, ensuring safety
for households, offices or factories.
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
2.1 Microcontrollers
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 4/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 5/51
– RA0: input/output
2 RA0/AN0 number
– RA1: output/import
3 RA1/AN1 numbers
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
– RA4: output/import
numbers
– C1 OUT : 1 .
comparator output
– 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
– RE1 : output/import
numbers
– RE2: export/import
numbers
– CS : Control selection
10 RE2//CS/AN7
chip at parallel branch
port
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 8/51
– 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.
– 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
– RC1 : output/import
numbers
– T1OSI: Timer 1 .
16 RC1/T1OSI/CCP2 oscillator input
– RC2: output/import
numbers
– 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
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
– SDA: export/import
data to I2C
– RC5: output/import
24 RC5/SDO 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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 12/51
numbers
– RB0: output/import
33 RB0/INT numbers
– 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
– 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
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.
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 15/51
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.
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 16/51
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 19/51
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.
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 22/51
PIC 16F877A
TC301
BUZZER
SERVO
POWER 5V
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 25/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 26/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 27/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 28/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 29/51
CHAPTER 5. EXPERIMENT
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 31/51
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
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
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 35/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 36/51
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien
PROJECT OF EMPLOYED SYSTEMS
Page 37/51
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
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
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
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();
}
}
}
}
}
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
Automatic door using magnetic card and key pad Executor: Nguyen Huu Trien