Arduino Safe(Locker)

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 : -

Hi, welcome to the community!

what do you mean? explain more, provide error messages, etc

Hello vibhorgrover

Welcome to the worldbest Arduino forum ever.

I assume that you have written the programme by yourself, then it is quite easy to find the error.

There's a trick to figuring out why something isn't working:

Use a logic analyzer to see what happens.
Put Serial.print statements at various places in the code to see the values of variables, especially ones that control the motors, and determine whether they meet your expectations.

Have a nice day and enjoy coding in C++.

1 Like
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>

Servo MyServo;

const byte Rs = 4;
const byte Cs = 4;

const char KEYS[Rs][Cs] {
  { '1', '2', '3', 'A' },
  { '4', '5', '6', 'B' },
  { '7', '8', '9', 'C' },
  { '*', '0', '#', 'D' }
};

const byte RPs[Rs] = { A0, A1, A2, A3 };
const byte CPs[Cs] = { 5, 4, 3, 2 };

Keypad Keyboard_Object(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 Pass[5] = {"2456"};
char Try[5] = {0};
LiquidCrystal lcd(RS, E, DB4, DB5, DB6, DB7);


void setup() {
  lcd.begin(16, 2);
  MyServo.attach(10);
  pinMode(GL, OUTPUT);
  pinMode(BP, INPUT); // external signal? if button then pull-up needed
  pinMode(PP, OUTPUT);
  MyServo.write(0);
}

void loop() {
  static byte number = 0;
  char KEYs = Keyboard_Object.getKey();

  if (KEYs != NO_KEY) {
    Try[number] = KEYs;
    lcd.setCursor(number, 0);
    lcd.print(KEYs);
    number++;
  }

  if (number == 5) {
    lcd.clear();
    number = 0;
    bool right = true;
    for (byte i = 0; i < 4; i++)if (Try[i] != Pass[i])right = false;
    if (right)MyServo.write(90);
    delay(2000);
    MyServo.write(0);
  }
}

Your schematic is not viewable unless the person has a tinkercad account which I do not.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.