Arduino Based Door Lock System
In this blog post, I will share with you how I made an Arduino-based door lock system.
I will use the SG90 servo motor to rotate its output shaft from one position to another, a 4 by 4 keypad to enter a password composed of 4 digits, and a buzzer to generate a sound while the user is interacting with the system.
Arduino Sketch
Before starting coding, I set a group of specifications depending on what I imagined the system to do during operation to provide myself with clear instructions on the writing of the sketch.
I use the millis() function to perform more than one task simultaneously rather than using the delay() function, which freezes the code for a certain determined period before executing anything else.
Feel free to Download the Arduino sketch and to watch the explanatory video below.
Click here if you want to watch the explanation video in Tunisian dialect.
PCB
I used the online PCB design tool EasyEDA to design a PCB for my project. I chose the ATMEGA328P-AU chip because I didn’t want to occupy a big place on the PCB with the ATMEGA328P-PU chip.
Feel free to Open In Editor the schematic diagram and PCB layout and Download the Gerber, BOM, and CPL files.
Upload The Sketch
You can use a USB to TTL serial converter to upload the sketch to the ATMEGA328P-AU chip. However, I prefer to use an Arduino UNO as ISP (in-system programmer) for sketch upload.
Once the boards are connected as shown above, follow these steps:
- Connect the Arduino UNO to the computer and open Arduino IDE.
- In Tools select the board Arduino Uno and the port the board is connecting to.
- Open File > Examples > 11.ArduinoISP > ArduinoISP then upload the sketch.
- Once uploaded, go to Tools again and select the board Arduino Nano, the processor ATmega328P, the port the Arduino UNO is connecting to, then change the programmer from AVRISP mkII to Arduino as ISP, and finally click Burn Bootloader.
- Open the desired sketch to upload, and from the menu bar open sketch, then click on Upload Using Programmer.
3D Model
To complete the project, I want to make an enclosure box for the PCB in a special form to give the system a final look as a door lock device. Therefore, to design the model, I used an online CAD software called Onshape, which is free to use and to Download the STL file.
After preparing the PCB and 3D part files, I visited jlcpcb.com and selected Instant Quote. I then uploaded the GERBER file, opted for green as the PCB color, selected LeadFree HASL for the surface finish, activated the PCB assembly service, and uploaded both the BOM and CPL files.
As for the ‘+’ and ‘-‘, they are not components but merely conductive copper areas on the PCB. So, when you get an error, click on continue.
I preferred not to have certain items pre-assembled by JLCPCB and chose to solder them myself upon receiving the PCB. These items are designated as BUZ, G-LED, R-LED, RST, RX, TX, PAD, and SRV.
JLCPCB also provides a 3D printing service, so I proceeded to upload the STL files as well, and then I chose the SLA (Resin) 3D technology and CBY Resin material.
Preparing Supplementary Elements
- 5mm Green LED *1
- 5mm Red LED *1
- 5V Active buzzer *1
- 90 Degree male pin header 2.5mm * 1
- Jumper wire * 9
- Phillips head screw M3_10mm * 4
- M3 Hexagon nut * 4
Assembling All The Parts
Before ordering my 3D model from JLCPCB, I tried a local 3D printing service, but the result was not satisfying, as I faced issues with fitting the nut into the screw pocket and the LED into its designated hole.
This is why, as soon as I received my package from JLCPCB, I immediately verified the dimensions, which were perfect, as well as the PCB and PCBA.
The step that involves securing the power and servo wires beneath the bridge constructed within the enclosure box requires some time and patience. It made me think of changing the PCB footprint and the 3D part design in the future if I want to make version two. But for now, the satisfaction of seeing my hard work come together is incredibly rewarding.