Hello,
I was trying to make a safe(Locker)
and I wrote the code myself but...
It is not working
Here is the code : -
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>
Servo MyServo;
const byte Rs = 4;
const byte Cs = 4;
char KEYS[Rs][Cs]{
{ '1', '2', '3', 'A' },
{ '4', '5', '6', 'B' },
{ '7', '8', '9', 'C' },
{ '*', '0', '#', 'D' }
};
byte RPs[Rs] = { A0, A1, A2, A3 };
byte CPs[Cs] = { 5, 4, 3, 2 };
Keypad Keyboard_Object = Keypad(makeKeymap(KEYS), RPs, CPs, Rs, Cs);
#define RS A5
#define E A4
#define DB4 6
#define DB5 7
#define DB6 8
#define DB7 9
#define BP 12
#define GL 13
#define PP 11
char PassOne = 2;
char PassTwo = 4;
char PassThree = 5;
char PassFour = 6;
LiquidCrystal lcd(RS, E, DB4, DB5, DB6, DB7);
void setup() {
lcd.begin(16, 2);
Serial.begin(300);
MyServo.attach(10);
pinMode(GL, OUTPUT);
pinMode(BP, INPUT);
pinMode(PP, OUTPUT);
}
void loop() {
//lcd.setCursor(0,0);
//lcd.print("");
//MyServo.write(90);
char KEYs = Keyboard_Object.getKey();
while (KEYs == NO_KEY) {
Serial.println("Noooooooooooooo");
}
if (KEYs == PassOne) {
lcd.print(PassOne);
digitalWrite(GL, HIGH);
delay(1000);
digitalWrite(GL, LOW);
while (KEYs == NO_KEY) {
Serial.println("Noooooooooooooo");
}
if (KEYs != NO_KEY) {
if (KEYs == PassTwo) {
lcd.print(PassTwo);
digitalWrite(GL, HIGH);
delay(1000);
digitalWrite(GL, LOW);
while (KEYs == NO_KEY) {
Serial.println("Noooooooooooooo");
}
if (KEYs != NO_KEY) {
if (KEYs == PassThree) {
lcd.print(PassThree);
digitalWrite(GL, HIGH);
delay(1000);
digitalWrite(GL, LOW);
while (KEYs == NO_KEY) {
Serial.println("Noooooooooooooo");
}
if (KEYs != NO_KEY) {
if (KEYs == PassFour) {
lcd.print(PassFour);
for (int i = 0; i < 90; i++) {
MyServo.write(i);
}
digitalWrite(GL, HIGH);
delay(5000);
digitalWrite(GL, LOW);
} else {
lcd.clear();
digitalWrite(PP, HIGH);
delay(10000);
digitalWrite(PP, LOW);
}
} else {
lcd.clear();
digitalWrite(PP, HIGH);
delay(10000);
digitalWrite(PP, LOW);
}
} else {
lcd.clear();
digitalWrite(PP, HIGH);
delay(10000);
digitalWrite(PP, LOW);
}
}
} else {
digitalWrite(PP, HIGH);
delay(10000);
digitalWrite(PP, LOW);
}
}
if (digitalRead(BP) == HIGH) {
lcd.clear();
for (int i = 90; i > 0; i--) {
MyServo.write(i);
}
}
}
}
Here is my circuit link : -