Professional Documents
Culture Documents
Door Mechanism
Door Mechanism
knocks and their consequent vibrations on the door surface. A 4x4 matrix membrane
because there are more combinations available for the pin code and thus, this can
contribute to the safety of the system. Although eight pins on the microcontroller is
required, it is deemed a worthy sacrifice for the sake of security of a household. The
wiring required for all three components originate from a drilled hole within the door to
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
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:
1
A1 Green LED
A2 Red LED
A4-A5 LCD
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,
only the CytronMotorDriver library is required for its use. It uses four pins in total
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
2
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
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
attached to the bottoms of the door at each side for stability of the overall structure. The
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.
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
3
“Enter Knock” on its first line. The default knock of the system is four regular knocks
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.
4
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
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
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,
5
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
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
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
6
4.1.3 Testing Accuracy of Piezoelectric Sensor
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
Table 4.2 Complete Rhythms and BPM Compilation for Testing Piezoelectric
Sensor
Rhythm Name Tempo / Beats Per Minute (BPM)
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
7
4.2 Discussion of Results
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.
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
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
8
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
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
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
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.
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
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
9
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
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
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
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
10
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
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
the threshold value. Every time a knock is entered in a new arrangement, the array is
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
still be able to unlock the door as long as the patterns are similar in rhythm. This will
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
11
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
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
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
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.
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.
12
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
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.
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
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
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
This project is a novel invention and the first of its kind to be within the
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
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
Consumers can also be assured that their or any user’s private details will not be
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
would barely outweigh the estimated selling prices, this would assist in improving
Additionally, the ninth SDG which is Industry, Innovation and Infrastructure can be
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
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
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
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
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
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
[2] Shetty, S., Shetty, S., Vishwakarma, V., & Patil, S. (2020). Review paper on
Digital
https://doi.org/10.1109/ICCDW45521.2020.9318636
[3] Fennelly, L. J. (2020). Doors and door locks. In Handbook of Loss Prevention
[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 :
(0123456789). https://doi.org/10.1057/s41284-021-00284-4
[6] Mohit, M. A., Mohamed, H., & Elsawahli, H. (2017). Crime and Housing in
[7] Zhu, Z., & Cheng, Y. (2020). Application of attitude tracking algorithm for face
19
https://doi.org/10.1016/j.comcom.2020.02.003
153(November), 13–18.
[9] Pattnaik, P. K., Mohanty, S., & Mohanty, S. (2020). Healthcare Analytics in loT
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 :
8(February), 339–343.
[11] Trikusuma, A. R., Rizqa, M., Wardhana, D. A., & Nada, N. Q. (2021).
“Branket”
0210108. https://doi.org/10.26877/asset.v3i1.8475
https://doi.org/10.5281/zenodo.35521
[13] Fennelly, L. J., & Perry, M. A. (2017). Doors, Door Frames, and Signage.
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).
[15] Milman, A., Jones, F., & Bach, S. (1999). The impact of security devices on
and
https://doi.org/10.1177/109634809902300403
[16] Skudder, H., Brunton-Smith, I., Tseloni, A., McInnes, A., Cole, J., Thompson,
R.,
[17] Tseloni, A., Thompson, R., Grove, L., Tilley, N., & Farrell, G. (2016). The
https://doi.org/10.1057/sj.2014.30
[18] Tseloni, A., Farrell, G., Thompson, R., Evans, E., & Tilley, N. (2017). Domestic
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
Latest
21
Technology in Engineering, Management & Applied Science (IJLTEMAS),
[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
Networking,
[21] Dabhade, J., Javare, A., Ghayal, T., Shelar, A., & Gupta, A. (2017). Smart Door
https://doi.org/10.5120/ijca2017913058
[22] Wang, C., Chen, Y., Liu, J., & Saxena, N. (2017). VibWrite : Towards
87.
[23] Essa, A., Lily, A., Lily, M. Al, Essa, A., Lily, A., & Lily, M. Al. (2020). The
[24] Jang, Y. H., & Park, Y. (2018). Enhanced knock code authentication with high
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>
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
//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
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);
}
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);
}
}
}
int i = 0;
// First lets reset the listening array.
for (i = 0; i < maximumKnocks; i++) {
knockReadings[i] = 0;
}
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();
//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);
}
}
}
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();
}
}
// 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:");
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
}
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);
}
}
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 ***
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;
}
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
% --- 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)
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);
35
36