-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSensor_10_DoorLockPIR.ino
112 lines (94 loc) · 1.72 KB
/
Sensor_10_DoorLockPIR.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
//SK.Tanzir Mehedi Shawon
//Department of ICT
//MBSTU
//Date-18-05-2018
#include <Keypad.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#include<Wire.h>
Servo myservo1;
#define Password_Lenght1 4
int pos1 = 0;
char Data1[Password_Lenght1];
char Master1[Password_Lenght1] = "*0#";
byte data_count1 = 0, master_count1 = 0;
bool Pass_is_good1;
char customKey1;
const byte ROWS1 = 4;
const byte COLS1 = 4;
char keys1[ROWS1][COLS1] =
{
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
bool door1 = true;
byte rowPins1[ROWS1] = { 25, 27, 29, 31 };
byte colPins1[COLS1] = { 33, 35, 37, 39 };
Keypad keypad1( makeKeymap(keys1), rowPins1, colPins1, ROWS1, COLS1);
void setup()
{
Serial.begin(9600);
myservo1.attach(22);
ServoClose1();
}
void loop()
{
if (door1== 0)
{
customKey1 = keypad1.getKey();
if (customKey1 == 'D')
{
ServoClose1();
door1= 1;
}
}
else Open1();
}
void clearData1()
{
while (data_count1 != 0)
{
Data1[data_count1--] = 0;
}
return;
}
void ServoOpen1()
{
for (pos1 = 90; pos1 >= 0; pos1 -= 5) {
// in steps of 1 degree
myservo1.write(pos1);
delay(15);
}
}
void ServoClose1()
{
for (pos1 = 0; pos1 <= 90; pos1 += 5) {
myservo1.write(pos1);
delay(15);
}
}
void Open1()
{
char customKey1 = keypad1.getKey();
Serial.println(customKey1);
if (customKey1)
{
Data1[data_count1] = customKey1;
data_count1++;
}
if (data_count1 == Password_Lenght1 - 1)
{
if (!strcmp(Data1, Master1))
{
ServoOpen1();
door1 = 0;
}
else
{
door1= 1;
}
clearData1();
}
}