Introduction: Facial Recognition Door Lock
About a month in the making, I present the facial recognition door lock! I tried to make it look as neat as I can, but I can only do so much as a 13-year old. This facial recognition door lock is run by a Raspberry Pi 4, with a special portable battery that can output 3 Amps, something necessary for the Raspberry Pi 4. It uses the Raspberry Pi Camera V2 for facial recognition, and a touch screen to view the output. Facial Recognition is with OpenCV. The lock is a servo motor that goes into a latch on the door frame. There are many other options that I will get to later in the build. Some pictures are not shown mainly because of how many different ways you can take this project to suit your needs.
Supplies
There are a lot of supplies, so be prepared...
3D Printer
Hot Glue Gun and Glue sticks
Soldering Iron
Patience. A lot of it.
Step 1: Basic Software
Take your sd card and plug it into your computer. Download the raspberry pi software (Click here for the latest version.) Flash it onto your SD Card; my preferred method is to use is Balena Etcher. Hit "Select Image" and select the image you just downloaded. It should automatically detect your SD Card once you plug it in. If not, select it by pressing on the "Target" button. After that, hit "Flash!". Insert your Micro SD Card into the bottom of the Raspberry Pi.
Step 2: Finding Your Raspberry Pi
If you don't have a micro HDMI to HDMI cable or an external monitor, follow these steps, if not, skip to the bottom. First, plug your Raspberry PI into Ethernet (Don't worry, this is temporary). Go into your WiFi settings on your computer, in advanced settings, under TCP/IP, you should see an IP Address named "Router". Go to that site, and at the back of your router at your house, you will see your username and password in order to log into the site. Scroll down until you see "raspberrypi" under your device list . The IP Address you see is what you need. Copy it into a note edit or just save it to your clipboard. Type, in your terminal, ssh pi@(YOUR IP ADDRESS).The default password is "raspberry". Type sudo apt-get install tightvncserver. Then type tightvncserver. On a Mac, hit "Command + K". Type "vnc://raspberrypi.local:5901", then type the password that you used when you set tightvncserver up. You should now see a desktop of raspberry pi on your computer. You can connect to your wifi, then disconnect the ethernet after the WiFi is connected.
If you have the cable and external monitor: plug your Pi into the monitor and connect to your wifi in the top left corner.
Step 3: Assembling the Other Parts
Take your camera module and your Raspberry Pi out. Take the camera connector and lift it so that it is in the open position. Insert the camera cable into the port. Press the connector down into its original position. Put that to the side. Next, take your screen module and your fan. Cut off the fan's connector and strip the wires. Solder the fan according to the image to the screen. Put the fan on top of the CPU module, according to the image. Very carefully attach the screen to the raspberry pi, so that the fan is inside, like a sandwich. Lif the screen up and tuck the camera cable underneath it. Lay the screen on top of the camera, and you are done!
Step 4: Software
Follow this article made by Adafruit on their product, the PiTFT. READ THIS CAREFULLY! I could have solved why my screen wasn't displaying the desktop AND why it wasn't resizing for the small screen size. You will want to use tightvncserver for the installation of OpenCV. You will now install OpenCV and install facial recognition. Once again, SO many of my problems could have been solved if I READ CAREFULLY. After you have facial recognition working for your face, replace your pi_face_recognition.py with the one attached to this step. This has the code for the servo motor. All you have to do is type sudo apt-get install pigpio or pip install pigpio. Your software is now done, let's move to the hardware. You can, instead of a servo motor, use an electromagnet or a solenoid.
Step 5: Motor and Button
I have an index card that has all the wiring you will need, as it gets VERY confusing. Solder these pins on the top of the screen, with Motor Red being the top right (Top is the side without the USB ports). You can drill a hole through your door frame (fewer wires) or down and around (more wires). I opted for no holes, so there are bundles of wire in the picture.
Step 6: Box Installation
Now would be a good time to print the attached files using Shapeways or your 3D printer at home. It was so difficult to get this to fit I have very few pictures of it, so sorry for the inconvenience. Fist, wire your cables through the USB port section on the bottom of the case. Then, take your screen and place it into position, securing it with hot glue. My screen ribbon cable kept shifting out of position, so test the device throughout. Then, take the camera and place it inside its casing. Glue it to the body however you like. Secure the raspberry pi inside the case, making sure the USB ports are visible, the ports on the side are visible, the wires aren't kinked, and there is enough room for the battery pack. Plugin your USB keyboard and mouse receiver at the bottom. There are designated holes for nails or screws on the back. I marked the position of all the holes with a pencil, drilled screws with a wide head in the holes, and seated the case on them. I further used hot glue to keep it secure. I would put a spacer at the bottom for the battery, a lollipop stick that rests on the opening on the side works perfectly. Slide the battery in the hole at the top. Plugin the 90-degree USB-C cable so the wire faces down, then loop it back to the top so it can plug into the pack. The box is now done!
Step 7: Door Installation
Use tape to secure the wires against the door. If you aren't wiring the wires under the door, ignore this. Pull the wires as taut as you can, then tape them in reasonable sections. I used a lot of tape at the bottom so my cat doesn't chew the wires. wire them under the door, taping it on the bottom. Wire it back up to the top as best you can. the end, for me, got a little messy, but I am fine with it. Take the small square printed part and put the motor inside, using hot glue to secure it. In the other small compartment, place the button and secure it with hot glue. Route the wires through the hole on the bottom and hot glue/nail the whole box against the door frame. Take the motor attachment for the servo motor and glue it into the big rectangular prism. Using the screw hole in the front, screw it into position. Tip: turn the Pi on an run the program so you screw it in the right position; when nothing is detected screw it in so it is parallel to the floor. Take the latch, and with the two holes SCREW it into the door frame. I strongly recommend screws for structural integrity. You have finished! (I don't have the installation of the box because I edited the box design after, and the steps mentioned above do not apply the 3D printed part I made earlier.)
Step 8: Finale
You are done! Currently, I am unable to find a way to run OpenCV programs on boot. I have tried everything, so if anyone knows how, please tell me. Currently, when it boots up, you have to use the keyboard and mouse on the small screen and type, by memory. cd (your location of the file) then workon cv then sudo pigpiod then the really long command the Pi saves when you hit the "up" button in the terminal. Other then that, I am quite proud of my project! I hope you enjoyed and you can create one for yourself!