Smartphone Controlled Door Lock

I have created a door lock that can be unlocked from anywhere in the house using just a smartphone. Perfect for anyone who is either too lazy or physically unable to get up and open the door.

Engineer

Isaac L.

Area of Interest

Computer Science,

Electrical Engineering

School

Monta Vista High School

Grade

Incoming Junior

Reflection

This project was really important to me as I have not had any real hands-on engineering experiences before. Ultimately, it ignited my passion for both engineering and computer science. I encountered numerous struggles during these past six weeks, but these experiences were all great learning experiences. Learning about facial recognition has sparked my interest in computer vision and trying to convert code between languages has exposed me to new, interesting languages that I will continue to explore. With the knowledge that I gained here at BlueStamp, I will definitely continue to build engineering projects. My main goal would be to try and combine computer science with mechanical and electrical engineering to target the minor annoyances we experience in our day to day lives.

Demo Night Video - Isaac L.

Final Milestone

Final Milestone Video - Isaac L.

Final Milestone Images

Camera Module
Face Detection

Schematic

Door Lock Schematic

For my final milestone, I modified the project by adding a new feature: facial recognition. My only hardware modification was the addition of the Raspberry Pi camera module.

My first step for this milestone was setting up OpenCV. This process took several hours, but it was relatively straightforward. Once I set up OpenCV, I attached the raspberry pi camera module to the raspberry pi and started testing the camera. I ran some sample code I found online, but I encounter an error: Assertion Failed. After researching, I solved this problem by typing in sudo modprobe bcm2835-v4l2.

The next step was to set up the face detection. This was a pretty foreign concept to me, so I had to do a lot of research. I ended up utilizing the “Haar Cascade classifier,” which is a common way people detect faces. This classifier was developed with a machine learning approach where a cascade function is trained from a series of positive (with faces) and negative (without faces) images. I did not create my own classifier; instead, I used a pre-trained classifier, from OpenCV.

Once I set up the face detection, I had to generate the dataset that would train the OpenCV recognizer. To do this, I wrote a program that asks the user to enter their ID for the picture. Then, it takes thirty pictures and saves those pictures into a directory.

After I gathered the necessary data, I had to train the OpenCV recognizer. I created another python file for this code. The recognizer I used was the LBPH (Local Binary Patterns Histograms) recognizer. With two arrays containing all the faces and their respective IDs, I used recognizer.train() to train the recognizer. Once the recognizer is trained, the program writes the model into a .yml file. For any face that I want to add, all I need to do generate the dataset and train the recognizer.

The last step was writing the code that would actually recognize my face and enable me to control the door lock. In my code, I essentially created an infinite loop that would repeatedly detect the face and use recognizer.predict() to return the ID of the person (as a number) and the confidence level. If the person is recognized, they can choose to open or close the lock by pressing the space bar. If the person is not recognized, the ID would become “Unknown,” and they would not be able to open or close the lock.

I worked a lot on the code for this milestone, so feel free to view it on my Github.

Third Milestone

Milestone 3 Video - Isaac L.

Blynk App

Door Lock App

My third milestone is making the door lock controllable by a smartphone. To make the phone interact with the Raspberry Pi, I utilized Blynk, a popular app that only requires an internet connection to interact with numerous devices: Raspberry Pi, Arduino, etc.

When I was still controlling the Raspberry Pi through a VNC viewer on the computer, I used Python to code the servo to move. However, the app I used, Blynk, does not support Python yet. As a result, I had to convert the code to NodeJS. This proved to be a difficult task, as I had never worked with NodeJS before. With the help of reference code by someone who had done a similar project before, I was able to write code to control servo the way I wanted to. When I looked at the reference code, I made sure to research the function of each line and what everything does.

While writing and running my code, I encountered several challenges. Because I was completely new to NodeJS, I had to spend a lot of time researching and learning about how to work with NodeJS. On my Raspberry Pi, I had to install numerous packages with the command npm install. During the process of installing all the necessary packages, I ran into permission errors which prevented the installs from happening. Sometimes, using sudo before the command worked; however, sometimes it did not work. This process was quite frustrating because I felt as if I was making no progress. After many hours of research and running different commands like sudo apt-get update and sudo node-gyp rebuild, I was finally able to get my code up and running.

In achieving this milestone, I learned about NodeJS and about the node modules and packages needed to make my code work. The two modules that I used were the blynk-library and pigpio. In addition, I learned how to write basic code in NodeJS.

Feel free to take a look at my code for this milestone, which can be found on my Github.

Second Milestone

Milestone 2 Video - Isaac L.

Milestone 2 Images

Door Lock
Pi + Door Lock
Servo-Lock Interaction

My second milestone consists of attaching the servo to the actual lock. This is essentially the final layout for the door lock, as I do not have a physical door to mount the lock on. In achieving this milestone, I was able to learn about and work with Dremel tools.

In order for the servo to actually fit on the lock turning rod, I had create a special servo-plate. To create the servo-plate, I worked with power tools to create a hole that fitted my needs. During this process, I ran into a few difficulties. Although I was able to get the the servo-plate to fit on the turning rod, I found that the plate was too large. To attach the base to the rest of the lock, two screws are used; however, those screws restricted the movement of the servo. To solve this, I had to use the power tools once again to reduce the diameter of the circular servo-plate.

After I successfully made a servo-plate that would fit on the lock turning rod, I needed to mount the servo to the base of the lock, otherwise the servo would move instead of the actual lock. I did this using both super glue and hot glue, as super glue itself proved to be insufficient in terms of strength.

First Milestone

Milestone 1 Video - Isaac L.

Schematic

Door Lock Schematic

My intensive project is the door lock that can be controlled by any device connected to the web. My first milestone is simply writing code to move the servo. The two main components for this milestone were a raspberry pi and a servo. I coded in python to make the servo turn the way I wanted it to.

First, I set up the raspberry pi by downloading the Raspbian operating system onto a micro SD card. Initially I had a problem setting up the rasberry pi with just the New Out of Box Software (NOOBS), but this was solved by downloading the Raspbian operating system as well. Next, I set up a secure shell (SSH) connection so that I could control the command line of the raspberry pi remotely. Once I set up the SSH, I set up the VNC viewer so I could fully control the raspberry pi with just my laptop (initially I had to use a monitor, mouse, and keyboard connected to the raspberry pi). While setting up the VNC, a problem I encountered was that while trying to connect to the raspberry pi, the computer displayed a message: The computer has refused the connection. This problem was solved by accessing the Raspberry Pi configuration tool and enabling VNC.

To code the servo to move, I worked with Python. I learned about the GPIO pins and what pulse width modulation (PWM) was. Pulse width modulation is a type of digital signal that is used here to control the servo motor. Pulse width modulation allows us to vary the signal between high and low. In my code, I had to change the duty cycle in a way that would essentially move the servo the number of degrees I wanted to. The duty cycle describes the percentage of time a digital signal is on over a period of time. For example, a duty cycle of 2.5% would be equivalent to moving the servo 0 degrees, 7.5% would be the same as 90 degrees, and 12.5% would be 180 degrees.

Starter Project

Starter Project Video - Isaac L.

Starter Project Images

TV-B-Gone
TV-B-Gone
TV-B-Gone IR Lights

My starter project is the TV-B-Gone remote. With the click of a button, the TV-B-Gone remote allows users to turn off almost any TV within a 150 foot radius. This project helped me work on my soldering skills and learn about the basic components of a circuit.

The remote uses two AA batteries which each supply 1.5V. Some key components of this project include resistors, transistors, oscillators, capacitors, and LEDs. The resistors limit the current flowing through the circuit by restricting the flow of electrons. This is because Ohm’s Law tells us that V=IR; by increasing resistance, we decrease current. The transistors turn on and off the IR LEDs by controlling the flow of current. The ceramic oscillator functions as a timer by generating a specific signal that oscillates at a specific frequency. The capacitors store charge to be used. When the button is pressed, current flows through the circuit. The microcontroller, which is preprogrammed with all the codes, turns the IR LEDs on and off according to the program. Once the current reaches the IR LEDs, they send out lights, with longer wavelengths, to the TV. This is then received by the TV through an infrared receiver and tells the TV whether to turn on or off.

While soldering, I had to be careful not to accidentally solder two leads together because this would cause a short circuit.

Regarding the overall project, I learned about how IR LEDs emit lights of wavelengths that can be seen by digital cameras and other infrared sensors, but not by the human eye. I also learned about ceramic oscillators and how they are used to control timing. 

Leave a Comment

Start typing and press Enter to search

Bluestamp Engineering