Arduino-Based Keypad Security System – Project

Description:

This project is a simple and effective security system using an Arduino Uno, a 4×4 keypad, and optional output components like a buzzer, LED, or servo motor for a lock. It allows a user to enter a numeric passcode to gain access, and triggers alerts or locks when incorrect attempts are made.

Working Principle:

  • The user enters a password using the keypad
  • The Arduino compares the input with a predefined passcode.
  • If the code is correct, the system triggers an “access granted” response (e.g. unlocks a door, turns on an LED).
  • If the code is incorrect, it can trigger a buzzer or lockout mechanism after multiple failed attempts.

Main Components:

  • Arduino Uno – Processes the input from the sensors.
  • 4×4 Keypad – Used to enter a numeric password. Buzzer / LED – Provide feedback for correct or incorrect entries.
  • Servo Motor or Relay (optional) – Can be used to control a lock mechanism.
  • LCD Display (optional) – Shows system status or prompts.
  • Power Supply – Powers the Arduino and connected devices.

Circuit Diagram:

Coding:

Arduino Keypad Security System
#include <Keypad.h>
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] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
String password = "6576"; // Correct password
String inputPassword = "";
int greenLED = 10;
int redLED = 11;
int buzzer = 12;
void setup(){
 pinMode(greenLED, OUTPUT);
 pinMode(redLED, OUTPUT);
 pinMode(buzzer, OUTPUT);
 Serial.begin(9600);
}
void loop(){
 char key = keypad.getKey();
if (key){
 Serial.print("Key Pressed: ");
 Serial.println(key);
 inputPassword += key; // Add entered digit
 if(inputPassword.length() == 4){ // Once 4 digits are entered
 if(inputPassword == password){
 digitalWrite(greenLED, HIGH);
 tone(buzzer, 1000, 300); // short beep
 delay(2000);
 digitalWrite(greenLED, LOW);
 } else {
 digitalWrite(redLED, HIGH);
 tone(buzzer, 300, 1000); // long low beep
 delay(2000);
 digitalWrite(redLED, LOW);
 }
 inputPassword = ""; // Reset input after 4 digits
 }
}
}