Introduction: Arduino Fingerprint Door Lock (with Keypad and LCD)
The Fingerprint door lock, as the name suggests, is an electronic door lock that can be installed on almost any access point in your house. It uses a keypad and fingerprint scanner to grant a user access by controlling an electric door strike with a relay. I started this project because I wanted to work with a keypad and fingerprint sensor as well as become more familiar working with LCD's, I also needed a way to lock my door from the outside so I thought an electronic door-lock would be a great opportunity to over-engineer something and learn some cool stuff :)
The basic operation of the device is as follows:
On power up the device displays a message on the LCD and a red status led lights up, indicating that the door is locked. The user then has the option of pressing a button for entering the password or for changing the password. To change the password the user would need to know the current/default password. If the password is input incorrectly then the display will show that the code was invalid and then revert to the default screen. When the code is entered correctly,the fingerprint scanner activates. If the scanner recognizes a fingerprint that has been enrolled then it will activate the relay and the a green status led for a few seconds, enough to open the door, enter and close it.
Hopefully this instructable will be easy enough to follow so that you can learn something and have a cool device to keep out minor intruders.
Step 1: Parts Bin
Below is the list of components I used for this project
- Atmega328p with arduino bootloader
- 16x2 character LCD
- ZFM-206SA Fingerprint sensor
- 4x4 Matrix Keypad
- ABS Plastic Box enclosure 180x120x55mm
- LM7805 Voltage Regulator
- FRS1-S Relay
- SPDT switch
- 22pF ceramic capacitor x4
- 220 Ohm Resistor
- 1K Resistor
- 5V Voltage Regulator
- Tactile pushbutton
- 16Mhz crystal
- 4.7K trim pot
- Red LED
- Green LED
- NPN BJT (I used TO92 package)
- Jumper wires
- 10mm nylon stand-offs
- M3x6 bolts and nuts
- screw terminals
- 16 pin Ribbon Cable
- Female headers
- foam board(optional)
- Electric door strike kit(12V AC)
- AA bateries x6
- 6xAA battery holder
- PVC trunking 3mm
- 2-wire electric cable
- Silicone adhesive
- fischer plugs
- Arduino Uno (used for programming)
- Hot glue gun
- Insulation Tape
- Dremel or Rotary tool
- Impact Drill(optional if drilling through a wall)
It's always good to have a decent supply of common components like resistors, capacitors, diodes etc. Keeping a good variety of these helps a lot when starting electronics projects. I also recommend having some experience in working with arduino before starting this project as it will make it much easier to deal with problems that may occur. If you're new to arduino you should still be able to do this project with a little extra effort.
Step 2: Circuit Schematic
The above figure contains the full breadboard schematic made with Fritzing. The schematic is based around an ATmega328p (The microcontroller used in the arduino Uno) with an arduino boot-loader. The breadboard version contains a minimal amount of components needed to run programs. Without the serial interface we cannot flash programs onto it from the PC instead the programming is done on the actual Uno board and the chip is then placed onto the breadboard.
I originally meant to use a barrel jack for power but removed it when it came to putting everything together. It's still there in the schematic. You may want to use one if you wish. Power is regulated from the batteries with a voltage regulator. As you can see in the schematic figure there are only a few components surrounding the ATmega chip. Most important is the 16 MHz crystal and the push-button, which is used for reset functionality. There are four main components to this design, the Keypad input, the fingerprint sensing, the LCD display and the relay output.
You may want to go ahead and assemble the whole schematic before testing the individual components or you may want to test and add components as you go along. The former is recommended if you intend to follow this instructable exactly as is.
Step 3: Testing the LCD and the Matrix Keypad
The official Arduino website contains well documented tutorials for using a matrix keypad and an LCD.There are also libraries available that make it easy to interface the components to the arduino. The Liquid-Crystal library is standard and should already be installed in the arduino IDE so you will just need to download and install the keypad library. Keypads are a bit tricky to read. You'll notice that a 4x4 keypad, which has 16 buttons, only has 8 pins. This is because the keypad is arranged into a matrix of 4 columns and 4 rows, thus matrix keypad (To be honest I didn't get it when I first started working with it). When a button is pressed then the row and column pins that correspond to that button are connected. You can test this by using the continuity setting on a multi-meter. How do you detect that on an arduino? I still not sure how it works but there is a library that handles that. That's one of the cons about using libraries, they make things easier to do but the abstraction means you don't really learn how it's done. The tutorials detailing how to use the LCD and Keypad with the arduino libraries can be found here:
Follow the tutorials to make sure that your keypad and LCD are working correctly and don't forget to modify the example codes to match the pins used in the schematic. For the Keypad you may need to modify the code to use a 4x4 matrix.
Step 4: Configuring Fingerprint Sensor
The Fingerprint sensor that we're using is quite simple to setup. But before we can use it in this project, you first have to register the fingerprints that you want to use, on the sensor itself. Download and install the arduino library from Adafruit here:
We're going to need the serial monitor for this part so you can wire the sensor directly as shown in the Fritzing diagram above. Run the enroll sketch from the examples and register all the fingerprints that you plan to use.
Step 5: The Door Strike and Relay Circuit
The door strike that I got requires a 12V AC signal to operate and came with a power adapter plug to be used with any mains socket supply. This poses a problem since the strike cannot be directly activated from an I/O pin on the arduino. To solve this we can use a general purpose NPN BJT transistor to drive a relay, which electrically isolates the main circuit from the door strike power supply. The circuit for this is included in the main schematic.
Step 6: Upload the Final Code
After you have made sure that all the components are working and that you have your fingerprints stored in the sensor, you can now program the full code onto the board. Just as before you upload the code using the arduino board then remove the chip from the board and plug it into the circuit. I've attached the full code in below. It may not be the cleanest code ever and I've tried to put in descriptive comments.
Once the code has been uploaded the red light should light up as well as the LCD screen and will display the default "Room 0" title. Pressing 'A' will trigger a prompt for the password which is "0000" by default. Once the code is entered correctly the lock will ask for a fingerprint. If you try using a finger that you didn't register nothing will happen but when you use a print that you did register three things are going to happen. First the LCD will identify the fingerprint ID that was found and show the confidence value for which it matched, second the green LED will turn on while the red LED turns off and finally the relay circuit will activate allowing the door lock supply voltage to flow through thus activating the strike and allowing entry. This active mode lasts for 5 seconds.
Pressing the 'B' while at the default screen will ask if you want to change the code. Press '*' to confirm and then once you enter the default code correctly it will allow you to change the code to a new four character password. This new password only lasts while the circuit is turned on. I'll try fixing that using EEPROM in a later version perhaps.
You can simply modify the code if you wish to change the default password or the activation time however you want.
Step 7: Assemble the Perfboard
Now that you've verified that all the components are working and you've also stored your desired fingerprints in the sensor, it's now time to put it all together on perfboard. This step involves quite a lot of soldering. The board layout is shown in the Fritzing diagram above which you can also download to check the connections. Take note of all the line breaks as well. It's not the most efficient design so feel free to design your own board or even make a PCB.
For the ATmega chip solder on the IC holder first and then insert the chip into the holder. It's good practice to do this with IC's since they are generally more sensitive to heat and can get damaged permanently.
Step 8: Assemble the Enclosure
For the box casing I drilled holes for the banana sockets at the top and the switch on the side. The board is attached to the case using 10mm nylon standoffs and M3 bolts.There should be space to drill on the corners of the board, then drill those corresponding holes in the casing. For power I managed to fit the 6xAA battery holder at the bottom where the power supply is. The screw terminal at the top is connected to wires soldered on the plug sockets. I also drilled and cut slots at the back so that I could hang it on screws on the wall. Your installation method may be different depending on where you plan to install.
Measure the dimensions of the LCD, keypad and sensor face and place mark out where you want to put them on the Lid. I used the Dremel to cut out the spaces. I also drilled holes for the LED's next to the LCD, I think I used a 3mm bit. I used hot glue to attach the keypad and the fingerprint sensor and LED's. I used some foam board that I had lying around but you may want to use whatever else you like just to cover the open space around there. The LCD I actually bolted to the case. I didn't want to use hot glue in case I decided to remove it and use it in another project. Bolts don't look to great on the cover so glue may be the better option.
The cable connectors also need to be assembled. This requires quite a bit of soldering. You need a 16 pin connector for the LCD and a 8 pin connector for the keypad. The latch pins are soldered and clipped onto the cable and then snap into the housings. The completed cables can be seen in step 1 and 2.
In hindsight I don't think I should have used such a big switch or put the sockets at the top since someone could just unplug them and just connect them manually to activate the door lock or flip the switch to reset the password. Although the purpose of this project is more for learning, I would go for a more rigid design and a diffferent material for some real security.
Step 9: Installation
I'm not going to detail everything I did regarding cable installation and door strike installation since I wouldn't be able to cover everyone's situation. Some may be working with a gate or wood etc.
I replaced the current door strike that I had with my new electric door strike. The kit that I bought came with a separate key slot piece that I put in as well. There was no way to access the terminals on the door strike once in was in so I put some small wires in them and drilled a hole in the door frame to pull them through.
Next I had to deliver power to the door strike. The closest plug that I could use was the one on top of my garage door motor. I put the door strike power supply there. I installed pvc trunking along the roof truss and along the wall to where the door lock device is going to be. I then drilled a hole in the wall through to the door lock device. The door strike kit also came with a switch button which I connected in parallel with the door lock so that you can easily open the door from inside. The cables were connected using PVC enclosed screw terminals or chocolate blocks as their called in some places. On the outside of the wall I drilled some holes inserted fischer plugs and screws that I used to hang up the box onto.