How to Make a DIY Keypad Door Lock System with Arduino Nano and Solenoid Lock

Hello and welcome back! In this project, we’ll learn how to make a simple door lock system using a 4×4 keypad module. To control everything, I used an Arduino Nano board because of its small size. For the locking mechanism, I used a solenoid door lock, which is perfect for electronic door lock projects. But you can connect any other DIY lock if you like. The solenoid door lock is connected through a relay module, which allows the Arduino to control the high-current lock safely.
I’ve also added a buzzer and an LED to indicate the lock status. For example, the LED turns on when the door is unlocked, and the buzzer gives a short beep sound for successful access. Specially, I designed a PCB for this project with JLCPCB. Therefore, we can manage components cleanly and easily. Also, you can turn this into a permanent project. This project is great if you’re looking for a low-cost. Also, you can use this project for your room door, cabinet, locker, or even a small safe.
Ok, let’s do this project step by step. The required components are given below.
- Arduino Nano board x 1 — Our Store / Amazon
- Keypad module x 1 — Our Store / Amazon
- Female header x 1 — Our store / Amazon
- Male header x 1 — Our store / Amazon
- Three-pin terminal x 1 — Our store / Amazon
- 5mm LED x 1 — Our store / Amazon
- 5v Relay x 1 — Our store / Amazon
- DC barrel jack x 1 — Our store / Amazon
- 102 SMD Resistor x 3 — Our store / Amazon
- 2A Transistor x 1 — Our store / Amazon
- 1N4148 diode x 1 — Our store / Amazon
- Red SMD LED x 1 — Our store / Amazon
- Green SMD LED x 1 — Our store / Amazon
- 5V Buzzer x 1 — Our store / Amazon
- Solenoid Lock x 1 — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.















Step 2
Secondly, let’s go ahead and order the PCBs for this project.


- Click the “Instant Quote” button and upload the Gerber file, which you can download from the link below.
- Gerber file – Download
- For this project, I ordered five white PCBs. Next, select the build time and shipping method. Finally, click “Save to Cart” and complete the payment.





Step 3
Thirdly, unbox your PCB package.





Step 4
Now, start by soldering the SMD components first.




Step 5
Next, use a soldering iron to solder all the remaining through-hole components onto the PCB.




Step 6
Afterward, connect the Arduino Nano board and the keypad module to the PCB. Then, connect the Arduino board to the computer.



Step 7
Now, open the Arduino IDE, then copy and paste the code below. Don’t forget to include all the necessary libraries before uploading it to the board.
#include <Keypad.h>
#include <Password.h>
// Pin definitions
#define relay 10
#define led 11
#define buzzer 12
// Password setup
Password password = Password("1234"); // Default password
String newPasswordString; // Hold the new password
char newPassword[6]; // Char array for new password
byte maxPasswordLength = 6;
byte currentPasswordLength = 0;
bool value = true; // Used for toggling door state
// Keypad setup
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'D', 'C', 'B', 'A'},
{'#', '9', '6', '3'},
{'0', '8', '5', '2'},
{'*', '7', '4', '1'},
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8, 9};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup() {
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
pinMode(relay, OUTPUT);
}
void loop() {
char key = keypad.getKey();
if (key != NO_KEY) {
delay(60);
if (key == 'C') {
resetPassword();
} else if (key == 'D') {
// Secure toggle: Only toggle if password is correct
if (password.evaluate()) {
toggleDoor();
} else {
errorFeedback(3);
}
resetPassword();
currentPasswordLength = 0;
} else {
processNumberKey(key);
}
}
}
void processNumberKey(char key) {
if (currentPasswordLength < maxPasswordLength) {
currentPasswordLength++;
password.append(key);
if (currentPasswordLength == maxPasswordLength) {
if (password.evaluate()) {
doorOpen();
} else {
errorFeedback(3);
}
resetPassword();
currentPasswordLength = 0;
}
}
}
void doorOpen() {
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
digitalWrite(relay, LOW); // Unlock
}
void doorLock() {
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
digitalWrite(relay, HIGH); // Lock
}
void toggleDoor() {
if (value) {
doorLock();
value = false;
} else {
doorOpen();
value = true;
}
}
void errorFeedback(int times) {
for (int i = 0; i < times; i++) {
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
delay(200);
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
delay(200);
}
}
void resetPassword() {
password.reset();
}
- You can set the door PIN to whatever you like. I used ‘1234’ for this project. After that, select the correct board and port in the Arduino IDE, then click the upload button to flash the code.





Step 8
Now, remove the USB cable from the Arduino, and connect the solenoid door lock to the relay module. I used an external 12V power supply to power the solenoid door lock through the relay module.




Step 9
Finally, connect the power supply to the main system. You can use a USB power supply or a 9V battery for this. I used two Li-ion batteries to power the project. Now you can test it by entering your PIN on the keypad. Ok enjoy this project. The full video guide is below, so make sure to check it out. We’ll see you in the next project. Have a great day!



Troubleshooting Tips
- Double-check the components.
- Select the correct COM port and board.
- Check the power supply.
How to Make a DIY Keypad Door Lock System with Arduino Nano and Solenoid Lock