Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Security & Surveillance

Keypad Door Lock: 4×4 Matrix with Solenoid Arduino Build

Keypad Door Lock: 4×4 Matrix with Solenoid Arduino Build

March 11, 2026 /Posted byJayesh Jain / 0

Table of Contents

  • How a Keypad Lock Works
  • Components Required
  • Wiring Diagram
  • Arduino Code
  • EEPROM PIN Storage
  • Improvements and Extensions
  • FAQ

How a Keypad Lock Works

A keypad door lock with Arduino replaces a traditional key with a secret PIN code. When the correct PIN is entered on a 4×4 matrix keypad, Arduino activates a solenoid or electric strike to release the door. This type of access control is widely used in Indian offices, server rooms, and home gates costing Rs 500-1,500 in components versus Rs 3,000-8,000 for commercial smart locks.

The 4×4 matrix keypad has 16 keys (0-9, A-D, *, #) but uses only 8 GPIO pins via a matrix scanning technique. The solenoid is a 12V device that pulls a metal plunger when energised, releasing a mechanical latch. A transistor or MOSFET is required to drive the solenoid from Arduino 5V logic.

Recommended: MH-SR602 Mini Motion Sensor Detector Module For Arduino – MH-SR602 Mini Motion Sensor – add passive occupancy detection to wake your keypad system and save power between entries.

Components Required

  • Arduino Uno or Nano
  • 4×4 membrane matrix keypad (Rs 40-80)
  • 12V solenoid lock (Rs 200-400) or 12V electric strike
  • NPN transistor (TIP120 or IRF520 MOSFET)
  • 1N4007 flyback diode (protects transistor from solenoid back-EMF)
  • 1k ohm base resistor, 12V/1A power supply
  • Small buzzer (Rs 15-30) for feedback tones
  • Red and green LEDs with 220 ohm resistors

Wiring Diagram

Keypad column/row pins connect to Arduino D2-D9. Solenoid: + to 12V supply, – to MOSFET drain. Flyback diode across solenoid (cathode to +12V). MOSFET gate to Arduino D10 via 1k resistor. MOSFET source to GND. Arduino GND shared with 12V supply GND.

Arduino Code

#include <Keypad.h>
#include <EEPROM.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[4]={2,3,4,5}, colPins[4]={6,7,8,9};
Keypad kpad=Keypad(makeKeymap(keys),rowPins,colPins,ROWS,COLS);
#define SOLENOID 10
#define BUZZER 11
String inputPIN="", storedPIN="1234";
void setup(){ pinMode(SOLENOID,OUTPUT); }
void loop(){
  char key=kpad.getKey();
  if(key){ tone(BUZZER,1000,100);
    if(key=='#'){ if(inputPIN==storedPIN) unlock(); else denied(); inputPIN=""; }
    else if(key=='*') inputPIN="";
    else inputPIN+=key;
  }
}
void unlock(){ digitalWrite(SOLENOID,HIGH); delay(3000); digitalWrite(SOLENOID,LOW); }
void denied(){ tone(BUZZER,200,500); }

EEPROM PIN Storage

Store the PIN in EEPROM so it survives power cycles. A dedicated change-PIN sequence using master PIN + new PIN + confirm prevents accidental changes. Reserve EEPROM bytes 0-5 for the PIN (up to 6 digits). EEPROM is rated 100,000 write cycles – read on startup and write only on PIN change.

Improvements and Extensions

  • Wrong-PIN lockout: After 3 wrong attempts, lock for 30 seconds and sound alarm.
  • RTC time-based access: Add DS1307 to restrict access to office hours only.
  • Logging: SD card or ESP8266 to log entry attempts with timestamps.
  • GSM alert: SIM800L to send SMS on wrong PIN attempts to owner number.
Recommended: Tiny RTC Real Time Clock DS1307 I2C IIC Module for Arduino – DS1307 RTC Module – add real-time scheduling to your keypad lock for time-based access control.

Frequently Asked Questions

What voltage does a solenoid door lock need?

Most Indian solenoid door locks require 12V DC at 500mA to 1A. Never connect directly to Arduino 5V – the solenoid will not operate and you risk damaging GPIO pins. Always use a dedicated 12V/1A adapter and a transistor or MOSFET as the switch.

Can I use a relay instead of a transistor to drive the solenoid?

Yes – a 5V relay module (Rs 20-40) can switch the 12V solenoid circuit. However, a MOSFET (IRF520) or transistor (TIP120) is more reliable – relays have mechanical wear rated 100,000 cycles, audible click, and slower switching. For a security application with multiple daily operations, a solid-state MOSFET is preferred.

How do I prevent brute-force PIN attacks?

Implement exponential backoff: after 3 wrong PINs, lock input for 30 seconds. After 6 wrong PINs, lock for 5 minutes. Store attempt count in EEPROM so power cycles do not reset the lockout. Sound a loud alarm buzzer during lockout to alert occupants.

What PIN lengths are supported?

Variable-length PINs terminated by the # key. Minimum recommended: 4 digits. Maximum practical: 8 digits. Adding a second factor (RFID card + PIN) dramatically improves security even with a short PIN.

Shop Security & Surveillance at Zbotic

Tags: 4x4 matrix keypad Arduino, Arduino access control India, EEPROM PIN storage, keypad door lock, solenoid door lock
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Coding and Electronics: Best R...
blog coding and electronics best resources for self study india 599381
blog smart fan speed controller pwm with temperature sensor 599394
Smart Fan Speed Controller: PW...

Related posts

Svg%3E
Read more

Trail Camera: Wildlife and Property Monitoring India

April 1, 2026 0
Table of Contents Trail Cameras for Indian Wildlife PIR-Triggered Camera Design ESP32-CAM Configuration for Trail Use Night Vision with IR... Continue reading
Svg%3E
Read more

Solar Powered Security Camera: Off-Grid Surveillance

April 1, 2026 0
Table of Contents Off-Grid Surveillance Needs in India Solar Panel and Battery Sizing Power Management Circuit ESP32-CAM Low Power Optimisation... Continue reading
Svg%3E
Read more

Remote Viewing Setup: Access Cameras from Anywhere

April 1, 2026 0
Table of Contents Remote Viewing Options P2P Cloud vs Port Forwarding Dynamic DNS Setup VPN for Secure Access Mobile App... Continue reading
Svg%3E
Read more

Motion Detection Zones: Reduce False Alarms

April 1, 2026 0
Table of Contents The False Alarm Problem How Motion Detection Works in Cameras Setting Detection Zones Sensitivity Adjustment Object Size... Continue reading
Svg%3E
Read more

Security Camera Placement: Best Positions for Coverage

April 1, 2026 0
Table of Contents Camera Placement Principles Height and Angle Guidelines Coverage Overlap Strategy Indian Home Layouts Commercial Property Placement Avoiding... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now