Circuit Diagram:
Smart Bank Safe Lock Security System Using Arduino
Welcome back! In this project, we are engineering an intelligent, multi-layered Smart Bank Safe Lock Security System. This build combines perimeter motion tracking, secure matrix credential input, visual status reporting, and heavy physical mechanics to simulate a high-security vault door.
System Architecture & Workflow
The control firmware handles two primary security layers concurrently to keep the vault protected:
[PIR Motion Sensor Area Scan] ──► Trigger System Warning Alert
│
▼
[4x4 Matrix Keypad Entry] ─────► Authenticate 4-Digit PIN
│
┌─────────────────────────────────────┴─────────────────────────────────────┐
▼ ▼
[ACCESS GRANTED] [ACCESS DENIED]
• Green LED Activates • Red LED Flashes
• OLED Displays "GRANTED" • Buzzer Sound Alarms
• Servo Lock Retracts (90°) • 2 Fails = System Lockout
- Layer 1: Perimeter Intrusion Check (PIR): An active motion sensor continually scans the environment. If unauthorized movement is registered, a warning state intercepts the execution loop, flashing indicators and delaying keypad inputs until the field clears.
- Layer 2: Matrix Credential Check: The safe remains securely locked via a servo module (0° position). Users must type the exact 4-digit numeric code via the keypad, tracked dynamically on the I2C OLED screen. A sequential counter monitors failed attempts, initiating an immediate loud lockout sequence if maximum thresholds are crossed.
Hardware Connection Pinout
To implement this setup on your prototyping bench, map your components directly to the microcontroller using the following exact connection index:
| Component Module | Hardware Pin Function | Microcontroller Target Pin | Default State / Purpose |
|---|---|---|---|
| Servo Motor | PWM Signal Line | Digital Pin 9 | 0° (Locked) / 90° (Unlocked) |
| PIR Motion Sensor | Digital Output Out | Digital Pin 13 | Active High Motion Check |
| Buzzer Module | Positive Input (+) | Digital Pin 12 | Audio Alarms & Key Feedback |
| RED Security LED | Anode (+) Terminal | Digital Pin 11 | Warning / Denied Indication |
| GREEN Status LED | Anode (+) Terminal | Digital Pin 10 | Access Granted Indication |
| I2C OLED Display | SDA / SCL Pins | Hardware I2C Pins | System UI Layout Output |
| 4x4 Matrix Keypad | Row Pins [1, 2, 3, 4] | Pins 5, 4, 3, 2 | Matrix Scanning Input Loop |
| 4x4 Matrix Keypad | Column Pins [1, 2, 3, 4] | Pins A3, A2, A1, A0 | Matrix Scanning Input Loop |
🔧 KEYPAD WIRING NOTICE: The code utilizes standard Analog pins (A0–A3) as digital inputs for the columns to ensure efficient pin allocation across your board without sacrificing high-speed SPI or I2C interfaces.
Arduino Code Configuration
Here is the complete source firmware ready to be flashed onto your microcontroller framework. It uses standard Keypad, Servo, and Adafruit_SSD1306 graphic libraries to process incoming credentials and system events:
📁 Smart_Bank_Safe.ino
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Keypad.h>
#include <Servo.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Pin Definitions
const int SERVO_PIN = 9;
const int PIR_PIN = 13;
const int BUZZER_PIN = 12;
const int RED_LED = 11;
const int GREEN_LED = 10;
// Security Logic
const String CORRECT_PIN = "1234";
String inputString = "";
int failedAttempts = 0;
const int MAX_ATTEMPTS = 2;
// Keypad Configuration
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] = {5, 4, 3, 2};
byte colPins[COLS] = {A3, A2, A1, A0};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
Servo lockServo;
void setup() {
Serial.begin(115200);
pinMode(PIR_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
lockServo.attach(SERVO_PIN);
lockServo.write(0); // Ensure locked (0 degrees)
delay(500); // Give OLED time to power up
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("OLED failed"));
for(;;);
}
showWelcome();
}
void loop() {
// 1. Security Check (PIR)
if (digitalRead(PIR_PIN) == HIGH) {
securityAlert();
// Wait until motion stops so the keypad doesn't freeze
while(digitalRead(PIR_PIN) == HIGH) {
delay(50);
}
updateEntryScreen();
}
// 2. PIN Entry Check
char key = keypad.getKey();
if (key) {
handleKeypad(key);
}
}
void showWelcome() {
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(20, 15);
display.println("SMART BANK SAFE");
display.setCursor(30, 35);
display.println("System Ready");
display.display();
delay(2000);
updateEntryScreen();
}
void updateEntryScreen() {
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("ENTER PIN:");
display.setCursor(0, 30);
display.setTextSize(2);
String displayChars = inputString;
for(int i = inputString.length(); i < 4; i++) {
displayChars += "_";
}
display.println(displayChars);
display.display();
}
void handleKeypad(char key) {
if (key >= '0' && key <= '9') {
inputString += key;
tone(BUZZER_PIN, 1000, 50);
updateEntryScreen();
}
else if (key == '*') {
inputString = "";
updateEntryScreen();
}
if (inputString.length() == 4) {
if (inputString == CORRECT_PIN) {
grantAccess();
} else {
denyAccess();
}
inputString = "";
}
}
void grantAccess() {
failedAttempts = 0;
digitalWrite(GREEN_LED, HIGH);
digitalWrite(RED_LED, LOW);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(20, 20);
display.println("GRANTED");
display.display();
lockServo.write(90);
tone(BUZZER_PIN, 1500, 500);
delay(4000);
lockServo.write(0);
digitalWrite(GREEN_LED, LOW);
updateEntryScreen();
}
void denyAccess() {
failedAttempts++;
digitalWrite(RED_LED, HIGH);
tone(BUZZER_PIN, 400, 800);
display.clearDisplay();
display.setTextSize(2);
display.setCursor(25, 20);
display.println("DENIED");
display.display();
delay(2000);
digitalWrite(RED_LED, LOW);
if (failedAttempts >= MAX_ATTEMPTS) {
lockoutAlarm();
} else {
updateEntryScreen();
}
}
void securityAlert() {
display.clearDisplay();
display.setCursor(15, 10);
display.setTextSize(2);
display.println("WARNING!");
display.setCursor(15, 40);
display.setTextSize(1);
display.println("Motion Detected");
display.display();
digitalWrite(RED_LED, HIGH);
tone(BUZZER_PIN, 800, 100);
delay(100);
digitalWrite(RED_LED, LOW);
}
void lockoutAlarm() {
display.clearDisplay();
display.setTextSize(2);
display.setCursor(10, 20);
display.println("LOCKED!");
display.display();
for(int i = 0; i < 5; i++) {
digitalWrite(RED_LED, HIGH);
tone(BUZZER_PIN, 1200);
delay(300);
digitalWrite(RED_LED, LOW);
noTone(BUZZER_PIN);
delay(300);
}
failedAttempts = 0;
updateEntryScreen();
}
System Testing Checklist
- Boot Sequence: When powered up, the OLED display should clear and showcase the "SMART BANK SAFE System Ready" status for 2 seconds before generating the text input buffer.
- Motion Handling: Pass your hand in front of the PIR sensor window. Keypad inputs should freeze temporarily while the warning alert prompts on screen.
- Lock Out Testing: Type a false pin twice continuously. The control framework will immediately route execution to the
lockoutAlarm()sequence, flashing notifications and sound lines for an extended period.
0 Comments