Projects / Keypad password door lock

Keypad password door lock

Intermediate1.7 hGuided buildReviewed

Build it step by step

0 of 5 done
  1. UNO

    Find the keypad pins

    The 8-pin ribbon is rows 1-4 then columns 1-4, left to right with the keys facing you. Wire them to D9 down to D2.

  2. UNOHelloPCF8574

    Wire the LCD

    SDA to A4, SCL to A5, VCC and GND.

  3. UNOON

    Wire the lock side

    12 V plus to relay COM, NO to solenoid plus, solenoid minus to 12 V minus. Fit the 1N4007 across the solenoid, stripe to plus.

  4. UNOON

    Relay and buzzer

    Relay IN to A0, buzzer to A1.

  5. UNO

    Upload and test on the bench

    Type 1234 then #. The solenoid should pull in for 5 s. Then change the code in the sketch.

In short

How do you build a keypad password door lock?

Enter a 4-digit code on a membrane keypad and a 12 V solenoid lock opens for five seconds, with prompts on an LCD. You need Arduino Uno R3, 4x4 matrix keypad (membrane), 16x2 LCD with I2C backpack (PCF8574), Relay Module 5V, Solenoid lock 12 V, Rectifier Diode 1N4007, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), Active buzzer 5 V and Jumper wires male to male (40 pcs, 20 cm). It takes 5 steps and about 100 minutes.

Level
Intermediate
Time
About 100 min
Parts
10

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Keypad rows 1-4Uno D9, D8, D7, D6Row lines
Keypad columns 1-4Uno D5, D4, D3, D2Column lines
LCD SDA / SCL / VCC / GNDUno A4 / A5 / 5V / GNDPrompts
Relay IN / VCC / GNDUno A0 / 5V / GNDLock control (A0 used as a digital pin)
12 V +Relay COM; relay NO to solenoid +Solenoid power through the relay
Solenoid −12 V −Return
1N4007Across the solenoid, stripe to +Absorbs the coil's voltage spike
Uno A1Buzzer + (− to GND)Key beeps and wrong-code alarm

Code

Arduino IDE, board "Arduino Uno". Install Keypad (Mark Stanley, Alexander Brevig) and LiquidCrystal I2C. Change "1234" before use. Press # to enter and * to clear.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const char KEYS[4][4] = {{'1','2','3','A'},{'4','5','6','B'},{'7','8','9','C'},{'*','0','#','D'}};
byte rows[4] = {9, 8, 7, 6}, cols[4] = {5, 4, 3, 2};
Keypad pad = Keypad(makeKeymap(KEYS), rows, cols, 4, 4);
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int RELAY = A0, BUZZER = A1;
const bool ON = LOW;
String code = "1234", entry = "";
int wrong = 0;

void prompt() { lcd.clear(); lcd.print("Enter code:"); lcd.setCursor(0, 1); entry = ""; }
void beep(int ms) { digitalWrite(BUZZER, HIGH); delay(ms); digitalWrite(BUZZER, LOW); }

void setup() {
  pinMode(RELAY, OUTPUT); digitalWrite(RELAY, !ON);
  pinMode(BUZZER, OUTPUT);
  lcd.init(); lcd.backlight();
  prompt();
}

void loop() {
  char k = pad.getKey();
  if (!k) return;
  beep(30);
  if (k == '*') { prompt(); return; }                 // clear
  if (k != '#') { if (entry.length() < 8) { entry += k; lcd.print('*'); } return; }
  if (entry == code) {
    wrong = 0;
    lcd.clear(); lcd.print("Open");
    digitalWrite(RELAY, ON); delay(5000); digitalWrite(RELAY, !ON);   // never hold a solenoid on for long
  } else {
    wrong++;
    lcd.clear(); lcd.print("Wrong code");
    beep(wrong >= 3 ? 3000 : 400);
    if (wrong >= 3) { lcd.setCursor(0, 1); lcd.print("Wait 30 s"); delay(30000); wrong = 0; }
  }
  prompt();
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Each key pressShort beep and a * on the LCD
1234 then #"Open", relay clicks, solenoid pulls in for 5 s
Wrong code three timesLong beep and a 30 s lockout
Solenoid currentAbout 0.5 to 0.8 A at 12 V while open

If it does not work

Wrong keys appear

Rows and columns swapped, or the ribbon is reversed. Swap the rows[] and cols[] arrays.

The Uno resets when the lock opens

The flyback diode is missing or reversed. Its stripe must face the solenoid plus.

The solenoid gets hot

It is made for short pulses. Keep the open time to a few seconds.

Safety

A fail-secure solenoid stays locked if power fails. Keep a mechanical key or exit button for real doors.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the keypad password door lock?

Arduino Uno R3, 4x4 matrix keypad (membrane), 16x2 LCD with I2C backpack (PCF8574), Relay Module 5V, Solenoid lock 12 V, Rectifier Diode 1N4007, 12 V 2 A DC adapter, DC barrel to screw terminal adapter (female), Active buzzer 5 V and Jumper wires male to male (40 pcs, 20 cm). Rectifier Diode 1N4007: Across the solenoid, stripe to plus.

How long does the keypad password door lock take to build?

About 100 minutes for a intermediate maker, in 5 steps.

How do I know the keypad password door lock works?

Each key press: Short beep and a * on the LCD. 1234 then #: "Open", relay clicks, solenoid pulls in for 5 s. Wrong code three times: Long beep and a 30 s lockout.

Wrong keys appear: what should I check?

Rows and columns swapped, or the ribbon is reversed. Swap the rows[] and cols[] arrays.

The Uno resets when the lock opens: what should I check?

The flyback diode is missing or reversed. Its stripe must face the solenoid plus.

The solenoid gets hot: what should I check?

It is made for short pulses. Keep the open time to a few seconds.

Safety: what should I check?

A fail-secure solenoid stays locked if power fails. Keep a mechanical key or exit button for real doors.