coulam123
Published © TAPR-OHL

Keypad and oled display safe circiut

An arduino nano based circuit used to lock and unlock a safe when a code is correctly put into the keypad

IntermediateFull instructions provided1,895
Keypad and oled display safe circiut

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
5 mm LED: Red
5 mm LED: Red
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Adafruit 3x4 membrane keypad
×1
Graphic OLED, 128 x 64 Pixels
Graphic OLED, 128 x 64 Pixels
×1
Servo Module (Generic)
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

circuit schematic

please note that i have excluded the keypad from this circuit diagram

img_3143_RaM8RihV7K.jpg

please note the orientation of the keypad connector on the arduino pins

Code

code for the arduino nano

C/C++
before you can upload the code, you need to download the U8x8 library for the oled display.
#include <Wire.h>
#include <Servo.h>
#include <Keypad.h>
#include <U8x8lib.h>

#define Password_Length 7

U8X8_SSD1306_128X64_NONAME_HW_I2C oleg;
int signalPin = 12;

char Data[Password_Length];
char Master[Password_Length] = "160306";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
float voltage1 = 5;
const byte ROWS = 4;
const byte COLS = 3;
int pos = 0;
const int a = 1;
const int b = 0;
const int ledPin = 10;
const int closePin =11;
//const int shutSwitch = A1;
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};

Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
Servo lock;
Servo unlock;
void setup() {
  Serial.begin(9600);
  oleg.begin();
  oleg.setFont(u8x8_font_profont29_2x3_r);
  pinMode(ledPin, OUTPUT);
  pinMode(closePin, OUTPUT);
//  pinMode(shutSwitch, INPUT);
  Wire.begin();
  lock.attach(13);
  unlock.attach(9);
//  lock.write(100);
  digitalWrite(closePin, HIGH);
}

void clearData() {
  while (data_count != 0) {
    Data[data_count--] = 0;
  }
  return;
}

void ledFlash() {
  digitalWrite(ledPin, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  delay(250);
  digitalWrite(ledPin, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  delay(250);
  digitalWrite(ledPin, LOW);
  delay(250);
  digitalWrite(ledPin, HIGH);
  delay(250);
}
void closeFlash() {
  digitalWrite(closePin, HIGH);
  delay(250);
  digitalWrite(closePin, LOW);
  delay(250);
  digitalWrite(closePin, HIGH);
  delay(250);
  digitalWrite(closePin, LOW);
  delay(250);
  digitalWrite(closePin, HIGH);
  delay(250);
  digitalWrite(closePin, LOW);
  delay(250);
  digitalWrite(closePin, HIGH);
  delay(250);
  digitalWrite(closePin, LOW);
  delay(250);
  digitalWrite(closePin, HIGH);
  delay(250);
}
void loop() {
  static byte theState = 1;
  

  oleg.setCursor(5, 0);
  oleg.print("Enter");
  oleg.setCursor(0, 3);
  oleg.print("password");
  oleg.setCursor(0, 0);
  lock.write(100);

  customKey = customKeypad.getKey();
  if (customKey) {
    oleg.print("        ");
    oleg.setCursor(0, 3);
    oleg.print("         ");
    Data[data_count] = customKey;
    oleg.setCursor(data_count, 1);
    oleg.print(Data[data_count]);
    data_count++;
    delay(500);
  }

  if (data_count == Password_Length - 1) {
    oleg.print("        ");
    oleg.setCursor(0, 3);
    oleg.print("        ");
    oleg.setCursor(0, 0);
    if (!strcmp(Data, Master)) {
      oleg.print("Correct");
      digitalWrite(ledPin, HIGH);
      digitalWrite(closePin, LOW);
      lock.write(0);
      delay(30000);
      oleg.setCursor(0, 0);
      oleg.print("        ");
      oleg.setCursor(0, 3);
      oleg.print("         ");
      oleg.setCursor(0, 0);
      oleg.print("closing");      
      ledFlash();
      digitalWrite(ledPin, LOW);
      closeFlash();
      digitalWrite(closePin, HIGH);
      lock.write(100);
      oleg.setCursor(0, 0);
      oleg.print("        ");
      oleg.setCursor(0, 3);
      oleg.print("         ");
    } else {
      oleg.print("Incorrect");
      delay(1000);
      oleg.setCursor(0, 0);
      oleg.print("        ");
      oleg.setCursor(0, 3);
      oleg.print("         ");
      lock.write(100);
    }


    clearData();
  }
}

Credits

coulam123
0 projects • 3 followers
Contact

Comments

Please log in or sign up to comment.