How I Built an Arduino Based Electronic Safe Locker

by sharepksn in Circuits > Arduino

137 Views, 1 Favorites, 0 Comments

How I Built an Arduino Based Electronic Safe Locker

Setup-GoodArduinocode.com.jpg
Arduino-Electronic-Safe-GoodArduinocode.com.jpg

Hello All,

I was planning to build a simple electronic safe. My main goal is to have a simple keypad, a display and a locking mechanism. I am using Arduino UNO, but any other Arduino family controller is fine as well.

Here is the main highlight of this Arduino based Electronic safe:

  1. Very simple User Interface and easy to design
  2. Keypad to enter the password (plus a few more functions)
  3. A simple 16x2 LCD1602 character display
  4. For the locking mechanism, I have servo motors for now. I will use them.

My code and project is completely motivated and supported by Electronic Safe from Good Arduino code site. You can have a look at the playground version of the Electronic safe. Please share your suggestions and comments as well :)

Supplies

  1. Arduino UNO
  2. 4x4 matrix keypad
  3. 16 x 2 LCD1602
  4. Servo Motor
  5. LEDs and series resistor
  6. Connecting cables
  7. Bread board
  8. 5 V adapter or battery supply for Power
  9. Misc.

Project Overview - Electronic Safe Based on Arduino

Here I would like to brief the needed user experience.

The main objectives are as follows:

  1. After first Power ON, the user should be able to enter the desired numeric password. Please have a look at online Arduino playground for Electronic Safe based on Arduino
  2. The numeric password length shall be 4.
  3. The password of the electronic safe must not be lost in the event of power failure
  4. The state of the lock or unlock should also be not lost
  5. either internal or external non volatile memory shall be there to store both the password of the electronic safe as well as the state of the lock (on/off).
  6. The program should work fine in the event of power reset
  7. user shall have option to set and reset password
  8. Simple and modular programming so that, new modules can be easily added
  9. further improvements or features can be added (proximity sensor, tone feedback for the key press, buzzer for repeated failures etc.

Hardware Connection Diagram for Electronic Safe Based on Arduino

Here is the overview of the connections

Arduino Pin ---- Device ---- DevicePin

12----LCD----RS

11 ----LCD----Enable

10----LCD ----D4

9 ----LCD----D5

8 ----LCD----D6

7 ----LCD----D7

6 ----Servo----Signal

5----Keypad----R4

4---- Keypad----R3

3----Keypad----R2

2----Keypad----R1

A3----Keypad----C4

A2----Keypad----C3

A1----Keypad----C2

A0----Keypad----C1

13----LED----Anode

Software Modules and High Level Description

Welcome Screen-Electronic Arduino Safe.jpg
Enter New Code - Goodarduinocode.com.jpg
Confirm code goodarduinocode.com.jpg
enter new code - Electronic Safe.jpg
press to lock Electronis safe Arduino.jpg
Safe locked - goodarduinocode.com.jpg

I have taken the source code from the GoodArduinoCode.com website which hosts many such Arduino programs. I have also been using Arduino Playground from the blog wokwi.com

Okay. here is the software part. The Electronic Arduino based safe module is divided into three sub modules:

  1. Main application
  2. Electronic safe Module
  3. Icons to display locked and unlocked symbol

The code is divided into three modules:

sketch.ino - Main program code, including the user interface

SafeState.cpp - Manages the state of the safe and the secret code, and stores them in the EEPROM memory.

icons.cpp - Provides the locked/unlocked icon for the LCD screen

Direct link for the complete software used in this project: https://goodarduinocode.com/projects/electronic-sa...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~0~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

void lock()

This function will lock the safe. The servo motor will be set to the position determined by the position sent as a parameter ( 0 to 180 degree). The Servo library can be accessed here to understand various servo motor related standard Arduino functions used in our Electronic Safe on Arduino project (write(), attach().. etc.)

void unlock()

This function will lock the safe. The angle sent in the function should correspond to the servo position which locks the safe. You can tune this based on your locking and unlocking requirement.

void showStartupMessage()

You can display simple welcome message here. You can tune the delay or the text as you wish

String inputSecretCode()

The function will accept only numeric key inputs. The screen will be displayed with an empty password field window. For every numeric input of the user, the asterisk symbol will be added (just as windows password field)

void showWaitScreen(int delayMillis)

This is only for the aesthetics. This can be skipped as well. But this is a nice feature considering user experience. additional to the code present in goodarduinocode.com, in the future adaptations, this time can be used in the background to align or drive the motors.

bool setNewCode()

This function asks the user of the electronic safe to enter the key. The user will enter the preferred 4 digit key. The Arduino will again ask for confirmation. The keys will be compared. If the keys mismatch, the error message will be displayed. If the keys match, the keys will be stored securely.

void showUnlockMessage()

This function displays a simple "unlocked" message. Also a symbol of the "unlock" symbol which i will get to later.

void safeUnlockedLogic()

This function presents user with the option to reset password if needed.

void safeLockedLogic()

This function will display custom message when the user has entered wrong key.

lockServo.attach(SERVO_PIN)

This function will attach the software with the pin used for driving Servo motor

You can get updates for the code for this project and many interesting and complete Arduino projects from www.goodarduinocode.com.

Please leave a comment if you would like to know in detail about working of the code in particular or other design questions in general. I will be happy to answer :)

icons.cpp

This source file is used to define our own design for the lock and the unlock symbol. These symbols are not part of the standard lookup table of LCD characters. These symbols are stored in non volatile memory of Arduino.

Electronic-safe.cpp

This source file takes care of all the vital functions of our Electronic safe project. The lock, unlock, updating the user password and other functions are handled in the source file. The header files contains necessary function definitions for the objects and other functions.

Complete Software

I strongly recommend to refer to the software link from goodarduinocode.com for digital Electronic Safe on Arduino. It helps to have access to the updated software.

It is very easy to understand the code when the source code is formatted.

The source files including the Arduino project files are attached.

Please feel free to suggest any ideas or any questions to improve my Electronics Safe project based on Arduino.

Modules That Can Be Added - OPTIONAL

  1. Red and green LEDs can be used to improve the user experience. You can refer to 5 ways of blinking the LED on Arduino to get some more basic examples of blinking the LED without delay.
  2. Both RED and Green LED can be used during the process of locking and unlocking (by simply toggling them in an alternate fashion)
  3. When the user entered password fails, Arduino can turn on only the red LED
  4. When the Electronic safe is in UNLOCKED condition, the Green LED can be lit
  5. A proximity sensor can be used to detect the user coming nearby the LED, thereby turning the backlight and/or the LEDs as well.
  6. Why not neon lights to decorate?
  7. additional tones to play when the password entered mismatches or matches
  8. keypad tones
  9. You can also plan Charlieplexing (very good idea to drive many LEDs with very less Arduino Pins

The above modules are not part of the code shared. You can add the modules on your own. For more such ideas you can visit free Arduino playground as well as a site for good collection of original Arduino projects. The online playground for Digital electronic safe is available as well where one can run the project to get a real feel without any hardware.

Additionally, I have to yet build a safe :)

When I build one physical safe, I will integrate the setup with a stable wiring and update the post. I will be happy to see others building the similar safe as well. Thank you!