-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.txt
112 lines (110 loc) · 3.11 KB
/
code.txt
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
#include<Keypad.h>
#include <Servo.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(13,12,16,17,18,19);
Servo Myservo;
const int buzzer = 15;
int pos, i;
int flag ;
const int green = 11;
const int red = 2;
const byte ROWS = 4; //four rows
const byte COLS = 4;
String password;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 5, 4, 3}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
lcd.begin(16,2);
pinMode(green, OUTPUT);
pinMode(red, OUTPUT);
Myservo.attach(14); // referring to analog pin A0
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.println("Enter the custom password");// taking custom password from the user with the help of serial monitor
while (Serial.available() == 0)
{ //Wait for user input
}
password = Serial.readString();
digitalWrite(green,LOW); // intially green and red both light are switched off
digitalWrite(red,LOW);
lcd.setCursor(0,0);
lcd.print("enter 5 dig pin");
lcd.setCursor(0,1);
char arr[6];
for (int j = 0; j < 3; j++) {
digitalWrite(green,LOW);
digitalWrite(red,LOW);
flag = 0;
for (i = 0; i < 5; i++)
{
arr[i] = '\0';
while (arr[i] == '\0')
{
arr[i] = keypad.getKey();
}
delay(1);
if(i==0) //clearing second line of lcd from previous pin
{
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
}
lcd.print(arr[i]);
}
for (i = 0; i < 5; i++)
{
if (arr[i] != password[i]){
flag = 1;
lcd.setCursor(0,0);
lcd.print("wrong password "); // displaying wrong password on entering wrong password
delay(500);
lcd.setCursor(0,0);
lcd.print(" "); // clearing previous line
lcd.setCursor(0,0);
lcd.print("enter 5 dig pin ");
lcd.setCursor(0,1);
}
delay(1);
}
if (flag == 0) //if password correct leave loop
break;
}
if (flag == 0)
{
lcd.setCursor(0,0);
lcd.print("correct password");
digitalWrite(green, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH); // if password entered is correct , green led will glow
digitalWrite(red, LOW);
delay(1000);
for (pos = 0; pos <= 180; pos++){ //for movement of servo motor
Myservo.write(pos);
delay(15);
}
delay(500);
for (pos = 180; pos >= 0; pos--) {
Myservo.write(pos);
delay(15);
}
}
else
{
tone(buzzer, 1000); // Send 1KHz sound signal to piezo buzzer
digitalWrite(red, HIGH); //red led will glow
digitalWrite(green, LOW); // green will be switched off
delay(1000);
noTone(buzzer);
delay(10000); // locking the system for 10 minutes to avoid fake person from entering password again and again
}
}