Smart HMI Door Lock with Passcode | Arduino Tutorial
In this project, you will learn how to make an HMI door lock using Arduino. This HMI door lock project allows you to unlock a door with a passcode, making it a simple and practical Arduino-based security solution for your DIY electronics projects.
Introduction
Hi friends, in this project I’m going to show you how to make an HMI door lock using Arduino. The Human Machine Interface (HMI) is a very user-friendly interface that allows you to interact with the system using a touchscreen display. By combining Arduino with an HMI, we can design a simple yet effective electronic door lock system that works with a passcode.
This project is great for learning about:
Arduino serial communication
Relay switching
Using an HMI for user input
Transistor-based relay driving
At the end of this project, you will have a fully functional door lock that can be controlled by entering a password on the HMI.
Applications
Home and office door locking
Smart lockers and cabinets
Security access control
Industrial machinery interlocks
Materials for the Project
Component | Quantity | Description | Buy Link |
---|---|---|---|
Arduino Nano | 1 | Main microcontroller board | Buy Here |
HMI Display (Nextion) | 1 | Human Machine Interface (HMI) touch screen | Buy Here |
5V Relay Module | 1 | Single channel relay for switching lock | Buy Here |
BC547 Transistor | 1 | NPN transistor for relay driving | Buy Here |
1N4148 Diode | 1 | Flyback diode to protect transistor | Buy Here |
Resistor 1K | 1 | Base resistor for BC547 | Buy Here |
2-Pin Terminal Blocks | 2 | For power and relay output connections | Buy Here |
5V Power Supply | 1 | Power source for Arduino and relay | Buy Here |
Jumper Wires | As req. | For connections | Buy Here |
Breadboard / PCB | 1 | For assembling the circuit | Buy Here |
Useful Tools
Tool | Quantity | Purpose / Notes | Click & Buy |
---|---|---|---|
Soldering Iron Kit | 1 | For making permanent connections | Click & Buy |
Solder Wire (60/40, 0.8mm) | 1 | Electrical soldering | Click & Buy |
Wire Stripper & Cutter | 1 | Stripping jumper wires | Click & Buy |
Mini Screwdriver Set | 1 | For module and relay terminal screws | Click & Buy |
Multimeter | 1 | Testing voltages and continuity | Click & Buy |
Hot Glue Gun (optional) | 1 | Securing components in place | Click & Buy |
Small Pliers | 1 | Holding and bending wires | Click & Buy |
Heat Shrink Tubing Set | 1 | Insulating exposed wires | Click & Buy |
Circuit Diagram Explanation
The wiring of this HMI door lock project is straightforward:
Arduino & Power:
Arduino provides the 5V and GND reference for all components.
A 2-pin terminal block is connected to supply external power if needed.
HMI Connections:
VCC → 5V of Arduino
GND → GND of Arduino
TX → D2 (Arduino)
RX → D3 (Arduino)
This allows serial communication between Arduino and the HMI display.
Relay Driver Circuit:
A BC547 transistor drives the relay coil.
Pin 2 (Base) is connected through a 1K resistor to Arduino D4.
Pin 3 (Emitter) goes to GND.
Pin 1 (Collector) connects to one side of the relay coil.
The other side of the relay coil is connected to 5V.
A 1N4148 diode is placed across the relay coil to suppress back EMF.
Relay Output Wiring:
COM and N.O. (Normally Open) terminals of the relay connect to the door lock system (electromagnetic lock or solenoid).
This way, when the correct password is entered on the HMI, Arduino activates the relay through the BC547 transistor, unlocking the door.
Download Circuit Diagram

Step-by-Step Guide
Step 1: Setup Arduino and Power
Place the Arduino on a breadboard or PCB.
Connect a 2-pin terminal block for power input (5V and GND).
Step 2: Connect the HMI Display
Connect VCC to 5V and GND to GND.
Connect TX of HMI → D2 of Arduino.
Connect RX of HMI → D3 of Arduino.
Step 3: Build Relay Driver Circuit
Insert BC547 transistor on the board.
Connect Emitter (pin 3) → GND.
Connect Base (pin 2) → Arduino D4 via a 1K resistor.
Connect Collector (pin 1) → Relay coil.
Connect the other relay coil pin → 5V.
Place 1N4148 diode across relay coil (Anode → transistor, Cathode → 5V).
Step 4: Relay Output Wiring
Connect COM terminal → Lock supply line.
Connect N.O. terminal → Door lock device.
Step 5: Upload Code
Write Arduino code that:
Reads passcode input from HMI.
Compares with stored password.
If correct → activates relay for a few seconds (door unlocks).
If wrong → relay stays off.
Step 6: Test the Project
Power up the circuit.
Upload the code to Arduino.
On HMI screen, enter the passcode.
Relay should click and unlock the door if the passcode is correct.
Arduino Code
Working Principle HMI Door Lock
The HMI provides a user-friendly interface to enter a password.
Arduino receives the serial data and checks against a pre-stored password.
If it matches, Arduino drives the BC547 transistor → activates the relay → unlocks the door.
A diode protects the transistor from back EMF generated by the relay coil.
Advantages HMI Door Lock
Simple and cost-effective
Can be modified with multiple passwords
Easy to expand with fingerprint or RFID modules
Low power consumption
Possible Improvements
Add EEPROM storage to save password permanently.
Use solenoid lock instead of relay-controlled lock for more reliability.
Add a buzzer for wrong password attempts.
Use Wi-Fi or Bluetooth for remote unlocking.
FAQs HMI Door Lock
1. Can I use any HMI display for this project?
Yes, you can use Nextion or similar HMI modules. Just make sure the voltage levels match Arduino.
2. Can I change the passcode without reprogramming Arduino?
Yes, if you add EEPROM storage in the code, you can save a new passcode from the HMI interface.
3. Can this circuit drive an electric strike lock?
Yes, but you may need a higher current relay depending on the lock specification.
4. What happens if the power goes off?
The door will lock by default since the relay will be de-energized.
5. Is this project safe for a real home door?
It is suitable for learning and small projects. For real security, commercial-grade locks with encryption are recommended.