ArrowtronElectronics Store
Free shipping over ₹999
100% genuine components
Dispatch in 1–2 days
Secure payments · UPI, Cards

Keypad Door Lock with LCD and Servo Latch

Type the right PIN on a 4×4 keypad and a servo swings the latch open; get it wrong three times and the system locks you out for 30 seconds.

Intermediate~2 hours6 components

What you’ll build

A 4×4 matrix keypad feeds digits to the Arduino, the 16×2 LCD masks your entry with asterisks, and a correct PIN rotates the SG90 servo 90° to pull a latch. Wrong attempts are counted and punished with a lockout timer.

Components you’ll need

ComponentQtyPrice
Arduino Nano ATmega328P Compatible Board1₹149
Keypad 4×41₹89
16×2 LCD Display1₹39
SG90 Micro Servo Motor 9G1₹89
10K Potentiometer1₹249
400 Point Breadboard1₹299
Total₹914

Step-by-step guide

  1. Connect the keypad’s 8 pins to D2–D9 (rows on D2–D5, columns on D6–D9).
  2. Wire the LCD in 4-bit mode on A0–A5 pins as in the sketch, with the 10K pot on V0 for contrast.
  3. Attach the servo signal to D10; mount its horn so 0° blocks the latch and 90° frees it.
  4. Install the “Keypad” library by Mark Stanley from the Library Manager.
  5. Change the PIN in the sketch, upload, and test: correct code opens for 5 seconds, three failures lock the keypad for 30.

The code

The Keypad library handles the matrix scanning; the sketch just collects four digits and compares.

#include <Keypad.h>
#include <Servo.h>
#include <LiquidCrystal.h>
const byte ROWS=4, COLS=4;
char keys[ROWS][COLS]={{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rowPins[ROWS]={2,3,4,5}, colPins[COLS]={6,7,8,9};
Keypad kp(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
Servo latch;
String PIN="4321", entry="";
int fails=0;
void setup(){ lcd.begin(16,2); latch.attach(10); latch.write(0); lcd.print("Enter PIN:"); }
void loop(){
  char k = kp.getKey(); if(!k) return;
  entry += k; lcd.setCursor(entry.length()-1,1); lcd.print('*');
  if(entry.length()<4) return;
  lcd.clear();
  if(entry==PIN){
    lcd.print("Welcome!"); latch.write(90); delay(5000); latch.write(0); fails=0;
  } else if(++fails>=3){
    lcd.print("LOCKED 30s"); delay(30000); fails=0;
  } else lcd.print("Wrong PIN");
  delay(800); lcd.clear(); lcd.print("Enter PIN:"); entry="";
}

Build this project

Add all 6 required components to your cart in one click — total ₹914.

Add all components to cart
Scroll to Top