Arduino Nano ESP32 - Door Lock System using Password
This tutorial instructs you how to use ESP32, Keypad and electromagnetic lock to make door lock system. Users will be ask for password via keypad. It the password is valid, the Arduino Nano ESP32 controls electromagnetic lock to unlock the door. The tutorials also optionally adds an LCD for more convenience. The Arduino Nano ESP32 code aslo supports multiple passwords.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
Overview of Keypad and Electromagnetic Lock and LCD
We have specific tutorials about kypad, electromagnetic lock and LCD. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to ESP32, Arduino Nano ESP32 code... Learn more about them at the following links:
How check the password
- A special key * is used to reset the password
- A special key # is used to terminate the password input.
- Every inputed key, except for * and # is appended in to a string.
- When # key is pressed, the password input is complete. The Arduino Nano ESP32 compares the inputed string with predefined passwords.
- If the inputed password is vaild, unlock the door.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
Arduino Nano ESP32 Code - Door lock system with password using keypad, electromagnetic lock
Detailed Instructions
To get started with Arduino Nano ESP32, follow these steps:
- If you are new to Arduino Nano ESP32, refer to the tutorial on how to set up the environment for Arduino Nano ESP32 in the Arduino IDE.
- Wire the components according to the provided diagram.
- Connect the Arduino Nano ESP32 board to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano ESP32 board and its corresponding COM port.* Click to the Libraries icon on the left bar of the Arduino IDE.
- Type “keypad” on the search box, then look for the keypad library by Mark Stanley, Alexander Brevig
- Click Install button to install keypad library.
- Copy the above code and paste it to Arduino IDE.
- Compile and upload code to Arduino Nano ESP32 board by clicking Upload button on Arduino IDE
- To simulate the electromagnet lock installed on the door, place the electromagnet near the armature plate.
- Press 1111 keys and press #
- Check the attraction force between electromagnet and armature plate.
- Press 1234 keys and press #
- Check the attraction force between electromagnet and armature plate.
- See the result on Serial Monitor
Arduino Nano ESP32 Code - Door lock system with password using keypad, electromagnetic lock and LCD
The below code added LCD I2C to display the access status. For wiring with LCD, you can see in this tutorial Esp32 - LCD I2C tutorial
※ NOTE THAT:
The LCD I2C address can be different from each manufacturer. In the code, we used address of 0x27 that is specified by DIYables manufacturer