-
Notifications
You must be signed in to change notification settings - Fork 0
/
Password-Protected_Door_Lock.ino
60 lines (50 loc) · 1.22 KB
/
Password-Protected_Door_Lock.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <Keypad.h>
char *password = "1234"; // To increase the passcode length change the numerical to the size after position
int position = 0;
const byte ROWS = 4; // 4 rows
const byte COLS = 4; // 4 columns
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
}; //mapping of the keys done w.r.t to the grid keypad
byte rowPins[ROWS] = {13, 12, 11, 10}; //connection of rows pins to the Arduino
byte colPins[COLS] = {9, 8, 7, 6}; // connection of the columns pins to the Arduino
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int Lock = 5; // Connecting the relay to the 5th pin
void setup()
{
pinMode(Lock, OUTPUT);
LockedPosition(true);
}
void loop()
{
char key = keypad.getKey();
if (key == '*' || key == 'A') //OR operator used to lock the device back again
{
position = 0;
LockedPosition(true);
}
if (key == password[position])
{
position++;
}
if (position == 4) // change this if you want to increase the password length
{
LockedPosition(false);
}
delay(100);
}
void LockedPosition(int locked)
{
if (locked)
{
digitalWrite(Lock, LOW);
}
else
{
digitalWrite(Lock, HIGH);
}
}