You are on page 1of 36

Figure 4.

4 Door Exterior Components


As for the interior, an acrylic case is also attached to the door surface using

epoxy glue with five panels in total, each with dimensions of 300 x 200 x 5 mm, similar

to the exterior case. The purpose of this case differs from the outer as it is used to house

the components required for circuitry of the project.

Figure 4.5 Door Interior Acrylic Casing


Most of the wiring and other components such as LEDs and resistors are

completed and installed onto a breadboard. The entire system of the project is controlled

by an Arduino Uno board in which the pins used by the system are detailed as in the tale

below:

Table 4.1 Configurations of Pins on Arduino Uno and Respective Functions

Pin Number Function

A0 Piezoelectric sensor signal

A1 Green LED

A2 Red LED

A3 Lock push button

A4-A5 LCD

D2-D3, D8-D13 4x4 matrix membrane keypad

Stacked atop the Arduino Uno board is a motor driver shield, specifically a DC

Motor Driver Shield for Arduino with a product code of SHIELD-2AMOTOR. This

shield is capable of operating two DC motors at the same time and through Arduino,

1
only the CytronMotorDriver library is required for its use. It uses four pins in total

which are D4 till D7 on the Arduino Uno.

Figure 4.6 2A Motor Driver Shield on top of Arduino Uno

This shield will then control a brushed DC geared motor, specifically the 12V

45RPM 9kgfcm Brushed DC Geared Motor with a product code of SPG50-100K. This

particular motor was selected due to its high power and consecutively, high torque

which is capable of turning the door lock mechanism. The motor shaft is directly

connected to lock mechanism after drilling a hole to fit it in.

Figure 4.7 Brushed DC Geared Motor attached to Door Lock

A locking function is added into this project as part of making this system more

realistic. For this purpose, a panel mount pushbutton with red button is used. It attached

on an inner wall of the acrylic case using double-sided tape.

Figure 4.8 Red Mounted Push Button as Lock Button

The prototype door is constructed from wood panels and includes a lever door

handle as well as a solid wooden door frame. Extruding wooden legs are made and

2
attached to the bottoms of the door at each side for stability of the overall structure. The

dimensions of the door prototype are roughly 1000 x 800 x 50 mm.

A Graphical User Interface (GUI) is created and programmed in MATLAB

software for knock pattern and pin registration purposes. Among its main components

are three push buttons labelled as Pin Code, Knock Pattern and Stop Knock.

Figure 4.9 MATLAB-Based Graphical User Interface (GUI)

4.1.2 System Operation Flow

This prototype functions on laptop power supply, seeing as there is direct cable

connection from laptop to the Arduino Uno for the operation of the GUI. Once

connected, the system will start. The green LED will light up to show that the system is

ready to read inputs from the piezoelectric sensor and the 4x4 keypad. The LCD will

first display

“Enter Knock” on its first line. The default knock of the system is four regular knocks

while the default pin code is “0000”.

Figure 4.10 LCD Display "Enter Knock"

3
In order to start the verification and unlocking process, the user will have to

enter the knock pattern, which is the default if no new knock pattern has been registered

through the GUI yet. While the knock pattern is being entered, the green LED

positioned on the breadboard on the interior side of the door will blink according to the

knock pattern entered. If the knock pattern entered is incorrect, then the LCD will

display “Incorrect” on the second line to indicate that the knock pattern is wrong and the

user should try again. At the same time, the red LED on the breadboard will blink thrice

to show that the knock pattern is wrong, although this will not be observed by the user

as it is on the interior of the door. Should the knock pattern entered be correct, then the

system will move onto the next verification method which is the pin code on the keypad

as displayed on the LCD “Enter Code:” on the first line and “Press *” on the second

line.

Figure 4.11 LCD Display "Enter Code Press *"

To start entering the code, the user will have to press the asterisk sign “*” before

any entering of numbers or alphabets are permitted. Then, the user will have to enter the

correct pin code, which will be the default of four zeroes if there has been no

modification of the pin code yet. The pins entered will be displayed as asterisks and not

as their relative letters for security purposes. If the pin entered is inaccurate, then the

LCD will display “Wrong” and the verification cycle will repeat again starting from the

4
knock pattern verification. On the other hand, if it is accurate, then the LCD will display

“Correct” and consequently, the door will be unlocked through clockwise rotation of the

DC motor shaft for a duration of 3.5 seconds approximately.

Figure 4.12 LCD Display "Correct"

A MATLAB-based Graphical User Interface (GUI) has been designed for the

purpose of registration of new knock patterns and pin codes. For changing the pin code,

users will have to select the button labelled as Pin Code. Once it has been pressed, the

LCD attached to the front surface of the door will display “Changing Code” for one

second before the display changes to “Enter Old Code” instead. Users will be required

to enter the initial pin code accurately before being allowed to register a new code

within the system. Once the old code entered is verified to be correct, then the

instruction “Enter new code and press #” is displayed. The user will have to enter their

new code twice and if the two codes entered do not match, then the LCD will display

“Codes are not matching!” and the preceding pin code will be maintained. Otherwise,

“Code changed” will be displayed instead to show that the pin code has been updated.

As for changing the knock pattern, users will first have to select the Knock

Pattern push button in the MATLAB GUI. Once pressed, it can be observed that both

the red and green LEDs will light up simultaneously. The user can then enter a new

knock pattern while both LEDs are lit. Should the knock pattern be completely entered

5
and the user wishes to save it, then they will only have to select the push button labelled

Stop Knock. The red LED will turn off and consequently, both LEDs will blink

according to the rhythm of the new knock pattern as a visual indicator for the user to

reconfirm their knock pattern.

Should the lock button, which is represented by the red mounted push button

attached on the inside surface of the interior acrylic casing, is pressed, then the locking

process will start to lock the door back through anticlockwise rotation of the motor shaft

for a duration of 3.5 seconds approximately.

4.1.3 Testing Accuracy of Piezoelectric Sensor

The accuracy of the piezoelectric sensor utilised in this project is tested

thoroughly for its detection and checking purposes. Different rhythms according to

varying tempos, in beats per minute (BPM) are tested on the system. This test is carried

out by registering the specified rhythms using the MATLAB-based GUI into the system

and consequently, verified to unlock the door. Four rates of speed are tested for five

different rhythms, as shown in the table given below.

Table 4.2 Complete Rhythms and BPM Compilation for Testing Piezoelectric
Sensor
Rhythm Name Tempo / Beats Per Minute (BPM)

80 BPM 100 BPM 120 BPM 140 BPM

Semangat UniMAP (Chorus) Accurate Accurate Accurate Accurate

Wawasanku (First Verse) Accurate Accurate Accurate Accurate

Happy Birthday (First 2 Verses) Accurate Accurate Accurate Accurate

Can (First 4 Verses) Accurate Accurate Accurate Accurate

Morse Code for “F Y P” Accurate Accurate Accurate Accurate

6
Thus, it can be observed that there is a remarkably high accuracy rate to the

knocks and this will further improve this system’s security and safety level. In terms of

percentages, it has been concluded that there is an accuracy rate of above 90%, with

unseen and untested errors taking up part of the percentage.

4.2 Discussion of Results

4.2.1 Strengths of Project System

All in all, this project yields multiple benefits, particularly in domestic security.

There is a highly improved security level compared to traditional door locks seeing as

users will be required to enter not just a knock pattern, which is difficult enough by

itself with a plethora of factors coming into play such as tempo, but a pin code as well.

Having two verification methods will greatly reduce risks of burglaries and break-ins.

Eavesdropping and shoulder-surfing attempts will also be impeded by the installation of

black-tinted one-way window films on the surfaces of the acrylic casing on the exterior

of the door. Not only that, the steps in unlocking the door have hidden security

measures. For instance, the user will have to press an asterisk before being able to input

the code which will impede the break-in attempts of strangers who do not know the

system well. Besides, after entering the code, in order to submit the code entered for

verification with the accurate one, users will be required to press “#” to stop the pin-

entering process. If a user would like to change their pin code, the old code will have to

be entered first as well before proceeding to the wanted code, in which users will have

to enter twice for it to be programmed into the system. Boasting a knock pattern

accuracy of above 90%, as has been tested with multiple different rhythms and BPM, it

7
will be considerably more difficult for burglars to try and break-in, as there is a certain

threshold value for a knock pattern to be accepted. Since the Internet is not used at all, it

is impossible for hackers to break in and the private details of users will not be

compromised in any way.

In comparison to the often-extreme prices of intelligent door locks, this project

has a much lower price point which is mostly due to the fact that there is absence of

complicated manufacturing processes and components. This project merely requires

affordable materials for its overall construction. Hence, this project will also have a high

commercial potential where its estimated price as a stand-alone product will be around

RM 250 (USD 60.28). However, this project will retain similar levels of safety as

typical smart door locks.

Additionally, this project is user-friendly. This statement can be proven by the

registration system where MATLAB software has been utilised to create and program a

Graphical User Interface (GUI). Having a GUI means that this project implements

technology in a wider range, particularly Internet of Things (IoT). Appropriate elements

such as push buttons have been labelled for ease of understanding. With only a click of

a button, a new knock pattern or pin code can be programmed without resorting to

multiple physical push buttons which may lead to confusion in several cases. Not just

that but this project also utilises an LCD for clear displays of instructions, namely the

steps required for the unlocking process and updating a new pin code.

Seeing as this project is a prototype and is powered by a laptop, it is predicted to

be capable of running fully on low-power sources even though there is a DC motor with

high torque used. Without heavy reliance on keys, it is a standalone product which is

also easy to install personally.

8
4.2.2 Weaknesses of Project System

Each and every system has its flaws as well as merits and hence, there are a few

drawbacks to this project. First and foremost, there are insufficient functions to this

current system for high-quality household use. For instance, even though there is an

additional function whereby users are capable of locking the door back from the inside,

there is yet to be a way to unlock the door from the inside, although it is merely a small

matter which can be resolved rather rapidly simply by implementing another function.

This could be seen as impractical but one must note that this is merely a working

prototype and thus, future improvements to the overall design and construction of this

project can be made.

Users may also believe the extruding acrylic cases to be a bother and take up

unnecessary space, particularly that of within the household which is the interior side of

the door prototype. This could be solved by installing the required circuitry inside the

confines of the door instead. The main purpose behind the acrylic housing is to be able

to clearly show the circuit and how the project operates.

Additionally, this project may still seem too costly in comparison to

conventional door locks. However, should the product be manufactured in bulk, the

overall pricing would decline for the better. It helps that the required components and

materials for its construction are not overly complicated and hence, the costs are too

high. It is deemed a worthy purchase since the overall security of the system is

remarkably high, comparable to those of typical smart door locks.

9
4.2.3 Arduino Code

Starting with the code sections related to the knock pattern, certain variables

have been declared for the functioning of the knock pattern section. For instance, a

threshold value is set as 100 which is the minimal signal detected to be registered as a

knock by the piezoelectric sensor. A rejectValue is set as 25 for higher security which

means that should a single knock be off by this percentage, the door will not unlock

itself. As for the code’s averageRejectValue which is similar to that of rejectValue but

applied to the entire recorded knock pattern entered, it is set as 15 percent. 150

milliseconds are allowed as the knockFadeTime where the knock vibration is allowed to

fade before the piezoelectric waits and scans for another knock. The maximum number

of knocks allowed, named a variable maximumKnocks is 20 while the maximum period

to wait for a tap before concluding that it has completed is approximately 1.2 seconds.

The first step in the program flow is for the piezoelectric sensor to detect if there

is any knock entered, as can be observed by the function name denoted as

listenToSecretKnock. A knock will only be considered one if it is more than or equals to

the threshold value. Every time a knock is entered in a new arrangement, the array is

reset. The counter which is named as currentKnockNumber will be incremented every

time there is a vibration from a knock detected. If the number of knocks exceeds 20

which is the maximum and the duration of knockComplete has been exceeded as well,

then the program moves onto validating the knock sequence. Firstly, the number of

knocks is verified and compared to the registered knock pattern. The next step would be

to contrast the time periods among vibrations from knocks. The time in real terms has

been disregarded so that users are able to enter knock patterns at different speeds and

10
still be able to unlock the door as long as the patterns are similar in rhythm. This will

thus increase the user-friendliness of the system.

The second verification method involves the pin code which is obtained through

the 4x4 matrix membrane keypad. If the knock pattern entered beforehand is accurate,

only then will the user be allowed to enter the pin code. The system will first obtain the

entered code where a variable ‘j’ will be used as a counter to display asterisks instead of

the actual entered code. Once the symbol ‘#’ has been pressed, then the comparison

stage will start between the registered and entered pin codes. If the sizes of code arrays

are similar to one another where any specific value entered will be taken into

consideration, then the program moves onto the next section in the function CheckBoth

where it checks both entered verification methods.

Should both the knock pattern and pin code be accurate, then only will the

program control the motor shaft to rotate in clockwise direction for approximately 3.5

seconds in order to unlock the door.

If the lock button at Arduino Uno pin A3 is pressed, then the program will

control the DC motor shaft to rotate in an anticlockwise direction to lock the door back

for a duration of 3500 milliseconds, or 3.5 seconds.

4.2.4 MATLAB GUI Code

MATLAB software is used specifically in the programming of the Graphical

User Interface (GUI) for any new registrations of knock patterns or pin codes. GUIDE

is used to design the GUI and serial communication plays a large role in this program

section.

11
As part of the GUI’s design, the institutional logo is part of the interface using an axes

element and command ‘imshow’ to display the JPEG file for the logo of Universiti

Malaysia Perlis. Commands fprintf are used widely in this program for serial

communication with the Arduino Uno board and the program uploaded to it. ‘x’ values

are sent to the Arduino Uno depending on which push button in the GUI has been

selected.

For instance, if the Pin Code push button has been pressed, then an ‘x’ value of 0

will be sent serially. In the Arduino program, the value 0 received will indicate that the

ChangeCode function is called in which the sizes of code arrays are verified against

each other while the user enters the old code first. Moving onto the next step where the

user enters their updated code twice in function GetNewCode1 and GetNewCode2

where the two particular arrays are compared with each other if they are matching. If

they are similar, then the new array is saved in the EEPROM as the updated code.

If the Knock Pattern push button is pressed instead, then an ‘x’ value of 1 is sent

serially instead. In the Arduino program, a variable named programButtonPressed is

labelled as ‘true’ state for easier handling within the program. The array is reset every

time a knock is inserted in a new configuration. Every time a knock is detected, the

counter called currentKnockNumber is increased. Once the Stop Knock push button in

the GUI is pressed, it will replace the ‘x’ value with 2 instead and simultaneously

change the state of variable programButtonPressed from ‘true’ to ‘false’. This will stop

the piezoelectric sensor from accepting any more knocks for the new knock sequence.

Then the program moves on to update the knock pattern as the recorded one.

12
4.3 Conclusion of the Chapter

This chapter summarises the results of this project in detail. Relevant discussions

are carried out regarding knock pattern accuracy rates, strengths and weaknesses of the

project system as well as line functions in the program codes. The following chapter

will conclude the project with relevant topics namely novelty and future improvements

as well as recommendations.

13
CHAPTER 5 : CONCLUSION

5.1 Conclusion

In a nutshell, the MATLAB-based Knock Pattern Recognising Door Lock

project was successful in fulfilling all its objectives. A smart door lock based on

registered knock pattern was designed successfully using mechanical, electronic and

programming knowledge and safety and security aspects were taken into consideration

simultaneously with a double-verification method as well as tinted physical barriers.

Both verification methods were successfully implemented so that if either are

inaccurate, the door will not be unlocked. A user-friendly knock-pattern door lock

system with a MATLAB-based Graphical User Interface was also created with success

for new knock pattern registrations. With a phenomenal knock-pattern accuracy and an

astoundingly high security level in comparison to traditional door locks, this project

prototype was effectively implemented as a whole.

5.2 Novelty of Project

5.2.1 Commercial Potential Perspective of Project

This project is a novel invention and the first of its kind to be within the

prediction group of being marketed professionally for actual domestic use in a

household. Since this prototype is powered by a laptop, it is predicted to be able to work

on low-power sources even with a high-torque DC motor. It is user friendly with clear

instructions displayed on the LCD for the unlocking process and the GUI also labelled

14
accordingly for any new registrations of either not patterns or pin codes. Security is

raised remarkably through the double-verification method being implemented.

Additionally, this project is kept at an affordable price point due to its affordable

materials as well compared to typical intelligent door locks. Not only boasting a knock

pattern accuracy rate of above 90% after tedious research and experimenting, where

varying tempo was played around with and different rhythms, this project is also easy to

install personally, seeing as it is a standalone product without any heavy reliance on

physical keys the way traditional door locks are.

Consumers can also be assured that their or any user’s private details will not be

compromised in any way.

5.2.2 Sustainability Perspective of Project

In terms of the Sustainable Development Goals (SDGs) set by the United Nations

(UN), this project is able to meet a few particular goals. Firstly, the eight goal which is

Decent Work and Economic Growth can be met through providing more job

opportunities should this project be commercialised. Seeing as the production costs

would barely outweigh the estimated selling prices, this would assist in improving

economy and the country’s growth.

Additionally, the ninth SDG which is Industry, Innovation and Infrastructure can be

achieved, particularly in terms of innovation. As mentioned, this project is an

innovative invention which utilises both traditional and intelligent aspects to result in an

improved version of both. In terms of industries, this would be another step towards

Internet of Things and its implementation in domestic sections.

15
As for the eleventh SDG, Sustainable Cities and Communities, this project can assist

towards that goal through improving domestic security for all homes, particularly those

transitioning to become smart cities.

5.2.3 Environmental Perspective of Project

In terms of the environmental impacts, this project will not negatively affect the

ecosystem as there is no need to outsource materials for its creation and construction.

All materials selected and used have been considered carefully beforehand and are

readily available. Hence, there will not be any harm done to the environment in any

way.

In addition, substituting physical keys with a knock pattern would also reduce the

sourcing for metals, namely brass and nickel, to produce the aforementioned keys.

Metals to be mined for this specific function could be reduced or even eliminated in the

near future with this invention.

5.3 Future Improvements and Recommendations

One functionality that did not see the light of day in this working prototype is a

touch screen GUI, which was part of the original plan but was disregarded on the fact

that this project is merely a prototype. It would be much more user-friendly if a laptop

GUI was replaced with a touch screen attached near the system.

Additionally, there is no way within this prototype to unlock the door from the

inside of the household. Through this prototype, users are only able to unlock the door

16
from the outside and lock the door from the interior, which can be seen as limited by

some.

Besides, the circuitry can be installed inside the door itself as a way to save

space, particularly towards the interior side of the door. It will be less messy should this

be implemented instead. The main purpose of wine this prototype has its main circuitry

outside the door and in an acrylic casing instead is so that the functioning of the

prototype involving the main circuit can be seen and observed clearly.

Next, due to the fact that one way window films do not work well during the

night as there is less light on both sides, lamp lights can be installed outside of the

exterior case so that the outside view has more light reflections and hence, cannot see

through to the inside of the acrylic case.

An alarm such as a buzzer can be installed into the main circuit to notify the

users if the door is not closed properly. Users should also be alerted with a warning if

the door is opened by force. Not just that but there should be a back-up power source in

cases of blackouts where should this occur, the whole door lock system would be down

and make the entire household vulnerable to burglaries and break-ins. Much more

technological methods of verification can be implemented to replace the pin code such

as fingerprints and face recognition. In these cases, the pin code verification method can

be used instead as a back-up plan in case both previous verification methods entered are

incorrect for multiple tries. However, it should be taken into consideration that this

might lower the overall security of the door lock system.

The above-mentioned recommendations for the future should be taken as so

which means that although this project misses a few marks, it must be noted that this is

17
merely a working prototype and further versions of this project may implement these

aforementioned modifications.

18
REFERENCES

[1] Thompson, R., Tseloni, A., Tilley, N., & Farrell, G. (2018). Which Security

Devices Reduce Burglary ? https://doi.org/10.1007/978-3-319-99942-5

[2] Shetty, S., Shetty, S., Vishwakarma, V., & Patil, S. (2020). Review paper on

door lock security systems. 2020 International Conference on Convergence to

Digital

World - Quo Vadis, ICCDW 2020, (Iccdw), 1–4.

https://doi.org/10.1109/ICCDW45521.2020.9318636

[3] Fennelly, L. J. (2020). Doors and door locks. In Handbook of Loss Prevention

and Crime Prevention. INC. https://doi.org/10.1016/b978-0-12-817273-5.00040-

[4] Frith, M. (2020). UCL JDI Special Series on COVID-19 : No . 12. (12).

[5] Farrell, G. (2021). Forty years of declining burglary in the United States :

Explanation and evidence relating to the security hypothesis. Security Journal,

(0123456789). https://doi.org/10.1057/s41284-021-00284-4

[6] Mohit, M. A., Mohamed, H., & Elsawahli, H. (2017). Crime and Housing in

Kuala Lumpur : Taman Melati terrace housing. Asian Journal of Environment-

Behaviour Studies, 2(2), 53. https://doi.org/10.21834/aje-bs.v2i2.177

[7] Zhu, Z., & Cheng, Y. (2020). Application of attitude tracking algorithm for face

recognition based on OpenCV in the intelligent door lock. Computer

Communications, 154(900), 390–397.

19
https://doi.org/10.1016/j.comcom.2020.02.003

[8] Nehete, P. R. (2016). Literature Survey on Door Lock Security Systems.

153(November), 13–18.

[9] Pattnaik, P. K., Mohanty, S., & Mohanty, S. (2020). Healthcare Analytics in loT

Enabled Environment (P. K. Pattnaik, S. Mohanty, & S. Mohanty, eds.).

Springer.

https://doi.org/https://doi.org/10.1007/978-3-030-37551-5 ©

[10] Alon, A. S., Casuat, C. D., Malbog, M. A. F., & Mindoro, J. N. (2020). SmaCk :

Smart Knock Security Drawer Based on Knock-Pattern using Piezo-electric

Effect. International Journal of Emerging Trends in Engineering Research,

8(February), 339–343.

[11] Trikusuma, A. R., Rizqa, M., Wardhana, D. A., & Nada, N. Q. (2021).
“Branket”

Design as a Safe Deposit Box Security System using Arduino-Based Tap

Sensor. Advance Sustainable Science, Engineering and Technology, 3(1),

0210108. https://doi.org/10.26877/asset.v3i1.8475

[12] Haddad, N. A. (2016). Critical review, assessment and investigation of ancient

technology evolution of door locking mechanisms in S.E. Mediterranean.

Mediterranean Archaeology and Archaeometry, 16(1), 53–74.

https://doi.org/10.5281/zenodo.35521

[13] Fennelly, L. J., & Perry, M. A. (2017). Doors, Door Frames, and Signage.

Effective Physical Security: Fifth Edition, 273–277.

https://doi.org/10.1016/B978-0-12-804462-9.00013-0

20
[14] Mas Erwan, A. N., Muzaffar Alfian, M. N. H., & Mohamad Adenan, M. S.
(2021).

Smart Door Lock. International Journal of Recent Technology and Applied

Science, 3(1), 1–15. https://doi.org/10.36079/lamintang.ijortas-0301.194

[15] Milman, A., Jones, F., & Bach, S. (1999). The impact of security devices on

tourists, perceived safety: The central Florida example. Journal of Hospitality

and

Tourism Research, 23(4), 371–386.

https://doi.org/10.1177/109634809902300403

[16] Skudder, H., Brunton-Smith, I., Tseloni, A., McInnes, A., Cole, J., Thompson,
R.,

& Druckman, A. (2018). Can burglary prevention be low-carbon and effective?

Investigating the environmental performance of burglary prevention measures.

Security Journal, 31(1), 111–138. https://doi.org/10.1057/s41284-017-0091-4

[17] Tseloni, A., Thompson, R., Grove, L., Tilley, N., & Farrell, G. (2016). The

Effectiveness of Burglary Security Devices. Security Journal, 30(1), 646–664.

https://doi.org/10.1057/sj.2014.30

[18] Tseloni, A., Farrell, G., Thompson, R., Evans, E., & Tilley, N. (2017). Domestic

burglary drop and the security hypothesis. Crime

Science, 6(1).

https://doi.org/10.1186/s40163-017-0064-2

[19] Orji, E. Z., Nduanya, U. I., & Oleka, C. V. (2019). Microcontroller Based

Digital Door Lock Security System Using Keypad. International Journal of

Latest

21
Technology in Engineering, Management & Applied Science (IJLTEMAS),

VIII(January, 1), 92–97.

[20] David William Raj, L., Santhosh, K., Subash, S., Sujin, C., & Tharun, P. (2019).

Voice controlled door lock system using matlab and arduino. 2019 IEEE

International Conference on System, Computation, Automation and

Networking,

ICSCAN 2019, 1–6. https://doi.org/10.1109/ICSCAN.2019.8878708

[21] Dabhade, J., Javare, A., Ghayal, T., Shelar, A., & Gupta, A. (2017). Smart Door

Lock System: Improving Home Security using Bluetooth Technology.

International Journal of Computer Applications, 160(8), 19–22.

https://doi.org/10.5120/ijca2017913058

[22] Wang, C., Chen, Y., Liu, J., & Saxena, N. (2017). VibWrite : Towards

Fingerinput Authentication on Ubiquitous Surfaces via Physical Vibration. 73–

87.

[23] Essa, A., Lily, A., Lily, M. Al, Essa, A., Lily, A., & Lily, M. Al. (2020). The

methodology of door-knocking : Saudi household surveys on socioeconomics

and learning technologies The methodology of door-knocking : Saudi household

surveys on socioeconomics and learning technologies. Cogent Social Sciences,

6(1), 13. https://doi.org/10.1080/23311886.2020.1774982

[24] Jang, Y. H., & Park, Y. (2018). Enhanced knock code authentication with high

security and improved convenience. KSII Transactions on Internet and

Information Systems, 12(9), 4560–4575.

https://doi.org/10.3837/tiis.2018.09.024

22
APPENDIX A ARDUINO PROGRAM CODE

#include <Keypad.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h> #include
"CytronMotorDriver.h"
#include <Wire.h>
#include <Key.h>

CytronMD motor1(PWM_DIR, 4, 5);


CytronMD motor2(PWM_DIR, 6, 7);

const byte numRows= 4; //number of rows on the keypad const


byte numCols= 4; //number of columns on the keypad

char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};

char keypressed; //Where the keys are stored it changes very often char
code[]= {'0','0','0','0'}; //The default code, you can change it or make it a 'n' digits one

char code_buff1[sizeof(code)]; //Where the new key is stored


char code_buff2[sizeof(code)]; //Where the new key is stored again so it's compared to
the previous one

short a=0,i=0,s=0,j=0; //Variables used later

//byte rowPins[numRows] = {9,8,7,6}; //Rows 0 to 3 //if you modify your pins you
should modify this too
//byte colPins[numCols]= {5,4,3,2}; //Columns 0 to 3 byte
colPins[numCols] = {9,8,3,2};
byte rowPins[numRows] = {13,12,11,10};

//LiquidCrystal_I2C
lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
Keypad myKeypad= Keypad(makeKeymap(keymap), rowPins, colPins, numRows,
numCols);

23
// Pin definitions
const int knockSensor = A0; // Piezo sensor on pin A0
//const int programSwitch = 0; // Push button to change knock pattern
const int redLED = A2; // Status LED const int greenLED = A1;
// Status LED
int BUTTON_PIN = A3; //Push button for locking
//#define O_Button 1 //Push button to change pin code int
value;

// Tuning constants. Could be made vars and hoooked to potentiometers for soft
configuration, etc. const int threshold = 100; // Minimum signal from the piezo to
register as a knock const int rejectValue = 25; // If an individual knock is off by
this percentage of a knock we don't unlock
const int averageRejectValue = 15; // If the average timing of the knocks is off by this
percent we don't unlock
const int knockFadeTime = 150; // milliseconds we allow a knock to fade before we
listen for another one (Debounce timer)
//const int lockTurnTime = 650; // milliseconds that we run the motor to get it to go a
half turn...change after combining
const int unlockTime = 3500; // milliseconds that the door remains
unlocked...change after combining

const int maximumKnocks = 20; // Maximum number of knocks to listen for const
int knockComplete = 1200; // Longest time to wait for a knock before we assume
that it's finished

// Variables. int secretCode[maximumKnocks] = {100, 100, 100, 0, 0, 0, 0, 0, 0, 0, 0,


0, 0, 0, 0, 0, 0,
0, 0, 0}; // Initial setup: 3 regular knocks int knockReadings[maximumKnocks]; //
When someone knocks this array fills with delays between knocks.
int knockSensorValue = 0; // Last reading of the knock sensor.
int programButtonPressed = false; // Flag so we remember the programming button
setting at the end of the cycle.

void setup()
{
Serial.begin(9600);
lcd.begin (16,2);
lcd.clear();
//pinMode(O_Button,INPUT);
pinMode(redLED, OUTPUT);
pinMode(greenLED, OUTPUT);
//pinMode(programSwitch, INPUT);
pinMode(BUTTON_PIN, INPUT);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Knock:");

24
}

void loop()
{ a=0;
//validateKnock()=false;
digitalWrite(greenLED, HIGH);

GUIpart();

if (digitalRead(BUTTON_PIN) == HIGH)
{ motor2.setSpeed(-255); // Motor 2 runs backward at full
speed. delay(3500); motor2.setSpeed(0);
}

// Listen for any knock at all.


knockSensorValue = analogRead(knockSensor);

if (knockSensorValue >= threshold) {


lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Knock:");
listenToSecretKnock();
}
keypressed = myKeypad.getKey();
if(keypressed == '*'){ // * to open the lock lcd.clear();
lcd.setCursor(0,0); lcd.print("Enter Code :"); //Message to show
GetCode(); //Getting code function if(a==sizeof(code))
//The GetCode function assign a value to a (it's correct when it has the size of the
code array)
{
lcd.clear();
lcd.print("Correct");
CheckBoth(); //Open lock function if code is correct
}
else{
lcd.clear();
lcd.print("Wrong"); //Message to print when the code is wrong
}
delay(2000);
lcd.clear();
}
}

void GUIpart()
{
if(Serial.available()>0)

25
{
value=Serial.read();

if(value==0)
{
ChangeCode();
lcd.clear();
}
if(value==1)
{
programButtonPressed = true; // Yes, so lets save that state
digitalWrite(redLED, HIGH); // and turn on the red light too so we know
we're programming. delay(2000);
}
if(value==2)
{
programButtonPressed = false;
digitalWrite(redLED, LOW);
}
}
}

// Records the timing of knocks. void


listenToSecretKnock() {
Serial.println("knock starting");

int i = 0;
// First lets reset the listening array.
for (i = 0; i < maximumKnocks; i++) {
knockReadings[i] = 0;
}

int currentKnockNumber = 0; // Incrementer for the array.


int startTime = millis(); // Reference for when this knock started.
int now = millis();

digitalWrite(greenLED, LOW); // we blink the LED for a bit as a visual


indicator of the knock. if (programButtonPressed == true)
{ digitalWrite(redLED, LOW); // and the red one too if we're
programming a new knock.
} delay(knockFadeTime); // wait for this peak to fade before
we listen to the next one.
digitalWrite(greenLED, HIGH); if
(programButtonPressed == true)
{ digitalWrite(redLED, HIGH);
}
do {

26
//listen for the next knock or wait for it to timeout.
knockSensorValue = analogRead(knockSensor); if
(knockSensorValue >= threshold) { //got another
knock... //record the delay time. Serial.println("knock.");
now = millis();
knockReadings[currentKnockNumber] = now - startTime;
currentKnockNumber ++; //increment the counter startTime
= now;
// and reset our timer for the next knock digitalWrite(greenLED,
LOW); if (programButtonPressed == true) { digitalWrite(redLED,
LOW); // and the red one too if we're programming a new
knock.
} delay(knockFadeTime); // again, a little delay to let the
knock decay. digitalWrite(greenLED, HIGH); if (programButtonPressed ==
true) {
digitalWrite(redLED, HIGH);
}
}

now = millis();

//did we timeout or run out of knocks?


} while ((now - startTime < knockComplete) && (currentKnockNumber <
maximumKnocks));

//we've got our knock recorded, lets see if it's valid if (programButtonPressed ==
false) { // only if we're not in progrmaing mode.
if (validateKnock() == true) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Code :");
lcd.setCursor(0,1);
lcd.print("Press *");

CheckBoth();
} else {
//Serial.println("Secret knock failed.");
lcd.setCursor(0,2);
lcd.print("Incorrect"); delay (2000);
lcd.setCursor(0,2); lcd.print("
"); digitalWrite(greenLED,
LOW); // We didn't unlock, so blink
the red LED as visual feedback.
for (i = 0; i < 4; i++)
{ digitalWrite(redLED, HIGH);
delay(100);
digitalWrite(redLED, LOW);

27
delay(100);
}
digitalWrite(greenLED, HIGH);
}
} else { // if we're in programming mode we still validate the lock, we just don't do
anything with the lock validateKnock();
// and we blink the green and red alternately to show that program is complete.
Serial.println("New lock stored."); digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH); for (i = 0; i < 3; i++) { delay(100);
digitalWrite(redLED, HIGH);
digitalWrite(greenLED, LOW); delay(100);
digitalWrite(redLED, LOW);
digitalWrite(greenLED, HIGH);
}
}
}

// Sees if our knock matches the secret.


// returns true if it's a good knock, false if it's not. //
todo: break it into smaller functions for readability.
boolean validateKnock()
{ int i = 0;

// simplest check first: Did we get the right number of knocks?


int currentKnockCount = 0; int secretKnockCount = 0; int
maxKnockInterval = 0; // We use this later to normalize the times.

for (i = 0; i < maximumKnocks; i++) {


if (knockReadings[i] > 0) {
currentKnockCount++;
} if (secretCode[i] > 0) { //todo: precalculate
this.
secretKnockCount++;
}

if (knockReadings[i] > maxKnockInterval) { // collect normalization data while


we're looping. maxKnockInterval = knockReadings[i];
}
}
// If we're recording a new knock, save the info and get out of here.
if (programButtonPressed == true) {
for (i = 0; i < maximumKnocks; i++) { // normalize the times
secretCode[i] = map(knockReadings[i], 0, maxKnockInterval, 0, 100);
}
// And flash the lights in the recorded pattern to let us know it's been programmed.
digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
delay(1000); digitalWrite(greenLED,

28
HIGH); digitalWrite(redLED,
HIGH);
delay(50); for (i = 0; i <
maximumKnocks ; i++)
{ digitalWrite(greenLED, LOW);
digitalWrite(redLED, LOW);
// only turn it on if there's a delay if (secretCode[i] > 0)
{ delay( map(secretCode[i], 0, 100, 0, maxKnockInterval)); // Expand the time
back out to what it was. Roughly. digitalWrite(greenLED, HIGH);
digitalWrite(redLED, HIGH);
}
delay(50);
}
return false; // We don't unlock the door when we are recording a new knock.
}

if (currentKnockCount != secretKnockCount)
{ return false;
}

/* Now we compare the relative intervals of our knocks, not the absolute time between
them.
(ie: if you do the same pattern slow or fast it should still open the door.)
This makes it less picky, which while making it less secure can also make it
less of a pain to use if your tempo is a little slow or fast.
*/
int totaltimeDifferences = 0;
int timeDiff = 0;
for (i = 0; i < maximumKnocks; i++) { // Normalize the times
knockReadings[i] = map(knockReadings[i], 0, maxKnockInterval, 0, 100);
timeDiff = abs(knockReadings[i] - secretCode[i]);
if (timeDiff > rejectValue) { // Individual value too far out of whack
return false;
}
totaltimeDifferences += timeDiff;
}
// It can also fail if the whole thing is too inaccurate.
if (totaltimeDifferences / secretKnockCount > averageRejectValue)
{ return false;
}

return true;

void CheckBoth()
{
if(a==sizeof(code) && validateKnock() == true)

29
{
triggerDoorUnlock();
}
}

// Runs the motor (or whatever) to unlock the door.


void triggerDoorUnlock() {
//Serial.println("Door unlocked!");
//lcd.setCursor(0,2);
//lcd.print("Correct");
//delay (2000);
lcd.setCursor(0,2);
lcd.print(" "); //
unlock the door!
motor2.setSpeed(255);
//delay(lockTurnTime);
delay(unlockTime);

// stop
motor2.setSpeed(0);

// Blink the green LED a few times for more visual feedback.
for (int i = 0; i < 5; i++)
{ digitalWrite(greenLED, LOW);
delay(100);
digitalWrite(greenLED, HIGH);
delay(100);
} lcd.clear();
lcd.setCursor(0,0);
lcd.print("Enter Knock:");

void ChangeCode(){ //Change code sequence


lcd.clear(); lcd.print("Changing code");
delay(1000);
lcd.clear();
lcd.print("Enter old code:");
GetCode(); //verify the old code first so you can change it

if(a==sizeof(code)){ //again verifying the a value


lcd.clear();
lcd.print("Changing code");
GetNewCode1(); //Get the new code
GetNewCode2(); //Get the new code again to confirm it
s=0;
for(i=0 ; i<sizeof(code) ; i++){ //Compare codes in array 1 and array 2 from
two previous functions

30
if(code_buff1[i]==code_buff2[i])
s++; //again this how we verifiy, increment s whenever
codes are matching
}
if(s==sizeof(code)){ //Correct is always the size of the array

for(i=0 ; i<sizeof(code) ; i++){


code[i]=code_buff2[i]; //the code array now receives the new code
EEPROM.put(i, code[i]); //And stores it in the EEPROM

}
lcd.clear();
lcd.print("Code Changed");
delay(2000);
}
else{ //In case the new codes aren't matching
lcd.clear();
lcd.print("Codes are not");
lcd.setCursor(0,1);
lcd.print("matching !!"); delay(2000);
}

else{ //In case the old code is wrong you can't change it
lcd.clear(); lcd.print("Wrong");
delay(2000);
}
}

void GetCode(){ //Getting code sequence


i=0; //All variables set to 0 a=0;
j=0;

while(keypressed != '#'){ //The user press A to confirm the


code otherwise he can keep typing
keypressed = myKeypad.getKey();
if(keypressed != NO_KEY && keypressed != '#' ){ //If the char typed isn't
A and neither "nothing"
lcd.setCursor(j,1); //This to write "*" on the LCD
whenever a key is pressed its position is controlled by j
lcd.print("*"); j++;
if(keypressed == code[i]&& i<sizeof(code)){ //if the char typed is correct
a and i increments to verify the next caracter
a++; //Now I think maybe I should have use only
a or i ... too lazy to test it -_-'
i++;
} else

31
a--; //if the character typed is wrong a decrement
and cannot equal the size of code []
}
}
keypressed = NO_KEY;

void GetNewCode1(){
i=0; j=0; lcd.clear();
lcd.print("Enter new code"); //tell the user to enter the new code and press A
lcd.setCursor(0,1); lcd.print("and press #"); delay(2000); lcd.clear();
lcd.setCursor(0,1);
lcd.print("and press #"); //Press A keep showing while the top row print ***

while(keypressed != '#'){ //A to confirm and quits the loop


keypressed = myKeypad.getKey();
if(keypressed != NO_KEY && keypressed != '#' ){
lcd.setCursor(j,0);
lcd.print("*"); //On the new code you can show * as I did or change it
to keypressed to show the keys
code_buff1[i]=keypressed; //Store caracters in the array
i++;
j++;
}
}
keypressed = NO_KEY;
}

void GetNewCode2(){ //This is exactly like the GetNewCode1 function


but this time the code is stored in another array i=0; j=0;

lcd.clear();
lcd.print("Confirm code");
lcd.setCursor(0,1);
lcd.print("and press #");
delay(3000); lcd.clear();
lcd.setCursor(0,1);
lcd.print("and press #");

while(keypressed != '#')
{ keypressed =
myKeypad.getKey();
if(keypressed != NO_KEY && keypressed != '#' ){
lcd.setCursor(j,0); lcd.print("*");
code_buff2[i]=keypressed;
i++;

32
j++;
}
}
keypressed = NO_KEY;
}

APPENDIX B MATLAB GUI PROGRAM CODE

function varargout = FYP_GUI_Try1_GUIDE(varargin)


% FYP_GUI_TRY1_GUIDE MATLAB code for FYP_GUI_Try1_GUIDE.fig %
FYP_GUI_TRY1_GUIDE, by itself, creates a new FYP_GUI_TRY1_GUIDE or
raises the existing % singleton*.
%
% H = FYP_GUI_TRY1_GUIDE returns the handle to a new
FYP_GUI_TRY1_GUIDE or the handle to
% the existing singleton*.
%
% FYP_GUI_TRY1_GUIDE('CALLBACK',hObject,eventData,handles,...) calls the
local
% function named CALLBACK in FYP_GUI_TRY1_GUIDE.M with the given
input arguments.
%
% FYP_GUI_TRY1_GUIDE('Property','Value',...) creates a new
FYP_GUI_TRY1_GUIDE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before FYP_GUI_Try1_GUIDE_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to FYP_GUI_Try1_GUIDE_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one %
instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help FYP_GUI_Try1_GUIDE

% Last Modified by GUIDE v2.5 25-Oct-2021 12:03:54

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1; gui_State =
struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @FYP_GUI_Try1_GUIDE_OpeningFcn, ...
'gui_OutputFcn', @FYP_GUI_Try1_GUIDE_OutputFcn, ...

33
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1}); end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:}); end
% End initialization code - DO NOT EDIT

% --- Executes just before FYP_GUI_Try1_GUIDE is made visible. function


FYP_GUI_Try1_GUIDE_OpeningFcn(hObject, eventdata, handles, varargin) % This
function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to FYP_GUI_Try1_GUIDE (see VARARGIN)

% Choose default command line output for FYP_GUI_Try1_GUIDE


handles.output = hObject; axes(handles.axes1) imshow('UniMAP
LOGO.jpeg') % Update handles structure
guidata(hObject, handles);

% UIWAIT makes FYP_GUI_Try1_GUIDE wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout =
FYP_GUI_Try1_GUIDE_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output; clear all; global x;
x=serial('COM3','BAUD', 9600);
fopen(x);

% --- Executes on button press in pinbutton. function


pinbutton_Callback(hObject, eventdata, handles)
% hObject handle to pinbutton (see GCBO)

34
% eventdata reserved - to be defined in a future version of MATLAB %
handles structure with handles and user data (see GUIDATA) global
x;
fprintf (x,0);

% --- Executes on button press in knockbutton.


function knockbutton_Callback(hObject, eventdata, handles)
% hObject handle to knockbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB %
handles structure with handles and user data (see GUIDATA) global
x;
fprintf(x,1);

% --- Executes on button press in stopknockbutton. function


stopknockbutton_Callback(hObject, eventdata, handles)
% hObject handle to stopknockbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB %
handles structure with handles and user data (see GUIDATA) global
x;
fprintf(x,2);

% --- Executes during object creation, after setting all properties.


function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: place code in OpeningFcn to populate axes1

35
36

You might also like