-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSecurity_System.ino
128 lines (113 loc) · 2.64 KB
/
Security_System.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Servo.h>
Servo servo_lock;
int contrast = 20;
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
int V0_pin = 5;
const int LedPinG = 3;
const int LedPinR = 2;
const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS][COLS] =
{
{'1', '2', '3', 'A'}, // here '*' stands for ','
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{',', '0', '=', 'D'} // '#' is used as '='
};
byte rowPins[ROWS] = {13, 12, 11, 10};
byte colPins[COLS] = {9, 8, 7, 6};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
boolean init_state = false;
boolean state = false;
boolean ultra;
boolean final_state = true;
String ID, pass;
boolean access;
char separator; // stores the ','
char identity [4] = "ABCD";
String default_pass = "123456";
void setup()
{
analogWrite(V0_pin, contrast);
pinMode(LedPinR, OUTPUT);
pinMode(LedPinG, OUTPUT);
lcd.begin(16, 2);
lcd.setCursor(4, 0);
lcd.print("Namaste!");
lcd.setCursor(0, 1);
lcd.print("The Secure Space");
delay(4000);
lcd.clear();
lcd.setCursor(2, 0);
lcd.print("ID & Pass - ");
servo_lock.attach(4);
}
// NO_KEY states that no key has been pressed.
void loop()
{
char key = keypad.getKey();
if (key != NO_KEY && (key == '1'|| key == '2'|| key == '3'|| key == '4'|| key == '5'|| key == '6'|| key == '7'|| key == '8'|| key == '9'|| key == '0'|| key == 'A'|| key == 'B'|| key == 'C'|| key == 'D'))
{
if (init_state != true)
{
ID = ID + key;
float ID_length = ID.length();
lcd.setCursor(0, 1);
lcd.print(ID);
}
else
{
pass = pass + key;
float pass_length = pass.length();
lcd.setCursor(2, 1);
lcd.print(pass);
final_state = true;
}
}
else if (state == false && key != NO_KEY && (key == ','))
{
init_state = true;
separator = key;
lcd.setCursor(1, 1);
lcd.print(separator);
}
// To check the PIN entered
else if (final_state == true && key != NO_KEY && key == '=')
{
/*
for(int i; i < 4; i++)
{
if (ID == identity[i])
{
access = true;
}
else if(ID != identity[i])
{
access = false;
}
}
*/
if (pass == default_pass)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Access Granted!");
digitalWrite(LedPinG, HIGH);
servo_lock.write(180);
digitalWrite(LedPinR, LOW);
}
else
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Access Denied!");
digitalWrite(LedPinG, LOW);
servo_lock.write(0);
digitalWrite(LedPinR, HIGH);
delay(3000);
digitalWrite(LedPinR, LOW);
}
}
}