Safe Box Using I2C LCD and 4×4 Keypad On Arduino.

Let's make a safe box!

Introduction

A safety box (also known as a strong box or box) is a secure lock used to retrieve valuable objects from theft and / or fire damage. Typical boxes are usually hollow or hollow cylinders, with one face removed or turned into a door. The body and door can be made of metal (such as steel) or made of plastic by molding.

Video

This video will show you how to make a safety box using Arduino.

Hardware Preparation

This is the hardware connection and the components needed.

Calculator Bb1
Figure 1 : Hardware connection.

Sample Code

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 2);
#include <Keypad.h>
#include <Servo.h>
Servo myservo;
#define Password_Lenght 7 // Give enough room for six chars + NULL char
#define PIEZO 8
#define NOTE_G4 392
#define NOTE_C5 523
#define NOTE_G5 784
#define NOTE_C6 1047
int pos = 0; // variable to store the servo position
char Data[Password_Lenght]; // 6 is the number of chars it can hold + the null char = 7
char Master[Password_Lenght] = "123456";
byte data_count = 0, master_count = 0;
bool Pass_is_good;
char customKey;
bool door = true;
const byte ROWS = 4;
const byte COLS = 4;
char keys [ROWS] [COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {10, 9, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad myKeypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int OpenMelody[] = {NOTE_G5, NOTE_C6};
int OpenNoteDurations[] = {12, 8};
int CloseMelody[] = {NOTE_C6, NOTE_G5};
int CloseNoteDurations[] = {12, 8};
#define playOpenMelody() playMelody(OpenMelody, OpenNoteDurations, 2)
#define playCloseMelody() playMelody(CloseMelody, CloseNoteDurations, 2)
char inChar;
String inString;
void setup() {
// put your setup code here, to run once:
myservo.attach(11);
pinMode(PIEZO, OUTPUT);
ServoClose();
lcd.init();
lcd.backlight();
lcd.print(" Suad Anwar ");
lcd.setCursor(0, 1);
lcd.print(" Safe Box ");
delay(3000);
lcd.clear();
}
void loop() {
// put your main code here, to run repeatedly:
if (door == 0)
{
customKey = myKeypad.getKey();
if (customKey == '#')
{
lcd.clear();
ServoClose();
lcd.print(" Closing...");
playCloseMelody();
delay(2000);
door = 1;
}
}
else Open();
}
void clearData()
{
while (data_count != 0)
{ // This can be used for any array size,
Data[data_count--] = 0; //clear array for new data
}
return;
}
void ServoOpen()
{
for (pos = 90; pos >= 0; pos -= 5) {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void ServoClose()
{
for (pos = 0; pos <= 90; pos += 5) {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
void Open()
{
lcd.setCursor(0, 0);
lcd.print(" Enter Password ");
customKey = myKeypad.getKey();
if (customKey) // makes sure a key is actually pressed, equal to (customKey != NO_KEY)
{
Data[data_count] = customKey; // store char into data array
lcd.setCursor(data_count, 1); // move cursor to show each new char
lcd.print(Data[data_count]); // print char at said cursor
data_count++; // increment data array by 1 to store new char, also keep track of the number of chars entered
}
if (data_count == Password_Lenght - 1) // if the array index is equal to the number of expected chars, compare data to master
{
if (!strcmp(Data, Master)) // equal to (strcmp(Data, Master) == 0)
{
lcd.clear();
ServoOpen();
lcd.print(" Access Granted");
playOpenMelody();
door = 0;
}
else
{
lcd.clear();
lcd.print(" Access Denied ");
playCloseMelody();
delay(1000);
door = 1;
}
clearData();
}
}
void playMelody(int *melody, int *noteDurations, int notesLength)
{
pinMode(PIEZO, OUTPUT);
for (int thisNote = 0; thisNote < notesLength; thisNote++) {
int noteDuration = 1000 / noteDurations[thisNote];
tone(PIEZO, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(PIEZO);
}
}
view raw SafeBox.ino hosted with ❤ by GitHub

References :

  1. Build a Safe with Combination Number Lock from Cardboard.
  2. Password Based Door Lock System Using Arduino and Keypad.

Thank you

Thank you for reading this tutorial and we hope it helps your project development. If you have any technical inquiry, please post at Cytron Technical Forum.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Send Data to Firebase Using Arduino Uno WiFi Rev2
Simple Alarm System Using Maker Nano
Program Cucumber ESP32-S2 Using CircuitPython
Face Recognition Using OpenCV on Raspberry Pi 400
Turned Your Tablet as a Display for the Raspberry Pi 400
Scroll to Top