Smart Door Lock
The Smart Door Lock uses technology to capture a picture of a person at the door and emails the image to the owner. This would require a Raspberry Pi, a “small computer” to send off the email to the owner. Then the Raspberry Pi would send an output signal via GPIO pins to an Arduino to unlock and lock the door 15 seconds later. A camera module is attached to the Raspberry Pi to capture an image.
Area of Interest
Newtown High School
Coming into BlueStamp, I didn’t know anything about coding nor even heard anything about a Raspberry Pi and Arduino. I’m glad to say that I was able to learn something new, since my main project required mechanical, electrical, and computer engineering. After BlueStamp, I can take this opportunity to explore more on which engineering field I would take up on.
I’m proud to create something that I would have never created at home or school. I really enjoyed both my main project and my experience at BlueStamp.
I finished my project! For my final milestone, I was able to integrate all my milestones into one. I was able to have the Raspberry Pi control the Arduino via a GPIO pin sending an output signal to unlock the door lock and lock it again 15 seconds later. I was also able to program it all in one code in which the camera would capture an image and send an email while the door unlocks.
How it works?
First, I created a shell command in which the Raspberry Pi would take an image and send it to my email. The shell command was able to put two codes into one, so one command could run it all. “/email.sh” runs the “raspistill -o image.jpg” (which captures an image from the camera module) and runs “sendemail.py” (Milestone 2) all in one code.
Second, I had to make the Raspberry Pi control the Arduino from GPIO pin on the Raspberry Pi. GPIO is General Purpose Input/Output which sends either an input or output to another device, like the Arduino. But the pins are connected from the Raspberry Pi to a BreadBoard in order for no twitching to occur to the lock by placing a resistor on the BreadBoard.
Then, I had to put the shell command into the python script that unlocks and locks the door lock by using “Subprocess call()”. This process can be used to start a program and run it.
With that being put into one. I would just run one command “sudo python3 door_lock.py”
Image 1: Full Project assembled and integrated together
Image 2: Email sent from Raspberry Pi
What I learned?/Mistakes
I learned how to make the Raspberry Pi program the Arduino. I learned how to create a shell command. My project required mechanical, electrical and tons of software engineering so it was fun to learn new things. I learned how to assemble the lock, learn how coding the Arduino a specific way with GPIO pins to make the servo unlock and lock the door. I learned how my project included system integration from Raspberry Pi to Arduino. Some challenges I came across were errors on my python scripts, they were very tedious but overcame them. Another challenge was when my SD card got corrupted, so I had to start my python scripts all over again, so it’s best if you back it up on another SD card. Some future modifications that can happen is adding facial recognition. But by doing so OpenCV has to be compiled to the Raspberry Pi. OpenCV, is an open source computer vision which is a library of programming functions mainly aimed at real-time computer vision.
For my third milestone, I successfully programmed the Arduino to control the Servo to lock/unlock the 3D Door Lock. First I assembled the door lock. The servo would have to be inside the lock in order to move the rectangular piece to lock and unlock. With that being assembled it is connected to the Arduino, which is then connected to my laptop. Then I would launch the Arduino application to start programming and control the Servo. Once the command is set, it is first verified to check if there are no mistakes like syntax. After, it is uploaded to the Servo and begins to lock and unlock.
How it works?
First, the 3D Door lock would have to be assembled with the Servo placed inside the lock which is programmed by the Arduino to lock and unlock the door. A Servo is a small device that has an output shaft. This shaft can be positioned to specific angular positions by sending the servo a coded signal. As long as the coded signal exists on the input line, the servo will maintain the angular position of the shaft. As the coded signal changes, the angular position of the shaft changes. Servos have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically brown or black and should be connected to a ground pin on the Arduino board. The signal/control pin is typically orange, yellow or white and should be connected to a digital pin on the Arduino board to carry the command pulses.
An Arduino is an open-source platform used for building electronics projects. The Arduino consists of both a physical programmable circuit board and a piece of software, IDE (Integrated Development Environment) that runs on your computer, used to write and upload computer code to the physical board. Unlike most previous programmable circuit boards, the Arduino does not need a separate piece of hardware in order to load a new code onto the board, it simply uses a USB cable.
The Arduino board is then connected to an electronic device (laptop or desktop, etc.) using a USB Cable RoHS Compliant. Once connected, a code must be created to control both the Arduino and Servo. When I write “servo.write(0)” on the Arduino application the servo would make the door lock become unlocked but when I write “servo.write(180)”, the door lock would become locked. There is a delay in between when locking and unlocking of 1000 milliseconds. The code I used is below:
Image 1: Door lock unlocked
Image 2: Door lock locked
Image 3: Arduino connected with Servo
What I learned?/Mistakes
I learned how to program the Arduino and Servo. I had a few problems starting it up because I didn’t know much about a Servo and Arduino. I learned that the Servo library allows an Arduino board to control RC (hobby) servo motors. I learned that Servos have integrated gears and a shaft that can be precisely controlled. Standard servos allow the shaft to be positioned at various angles, usually between 0 and 180 degrees. The biggest challenge of reaching this milestone was that the door lock wouldn’t run smoothly. I would screw the pieces together and the servo wouldn’t move or it would get stuck. To fix this problem I had to file and sand the 3D door lock so it could run smoothly. Once it was done I tried to type a code in so I could see exactly what position it locks and unlocks. When “servo.write(0)” the servo would be unlocked but when “servo.write(180)” it would be locked.
For my second milestone, I successfully programmed the Raspberry Pi to capture an image using the camera module. Then , I programmed the Raspberry Pi to send the captured image to my email. The process occurs with the code command “raspistill -o image.jpg && python sendmail.py”. The code “raspistill -o image.jpg” captures an image from the camera module (see image 2) and stores it and “python sendmail.py” takes the captured image and attaches it to the email when sent. All of this is written in the command line.
How it works?
First, the Raspberry Pi Camera module had to be installed, so I inserted the cable into the Raspberry Pi. The slot is situated between the Ethernet and HDMI ports, with the silver connectors of the camera module facing the HDMI port. After it’s connected, I booted up the Raspberry Pi. Once it was on, I ran the code “sudo raspi-config” on the command line. If the “camera” option is not listed, you would run “sudo apt-get update” and “sudo apt-get upgrade”, then the “camera” option would show up and the user, would enable it. To capture an image in jpeg format, I would run “raspistill -o image.jpg” into the terminal, where “image.jpg” is the desired name of the captured image.
Then the user creates a file in the terminal. I named mine “sendemail.py” (in order to write one, you would run “sudo nano sendemail.py”). I followed “Send an HTML Email with Embedded Image and Plain Text” to set up the process of sending an email with image being attached in the email. I will also include the full code file of what I used below with some changes I did.
With that, the user would run “raspistill -o image.jpg” first so it would take a picture of someone’s face. Then run “python sendemail.py” which would send the captured image of the face to your email.
Right below is the code file used to send an email. It is called “sendemail.py”:
Image 1: Camera Module v2 installed in Raspberry Pi
Image 2: Code file of how captured image is sent through email (Clearer version shows script)
Image 3: Image captured by camera module
Image 4: Email that was sent from Raspberry Pi
What I learned?/Mistakes
I learned how to code and comment, create prints and attach files. I was able to set it up separately, but couldn’t combine both into one. I was able to take images with a command by itself and send an email with a message. I learned how to solve issues that I ran into this milestone. I would research if others have been through the same situation and many have, so I followed what they did. The biggest challenge of reaching this milestone was trying to put both codes into one. I was researching how to combine both codes and at first one of my codes would capture an image and send an email but without the captured image. I followed many file codes that other people ran but it wouldn’t work for me. So it was best as suggested by my instructor to research more and I found the answer from Darrin Massena
For my first milestone I successfully installed Raspbian and installed Python on the Raspberry Pi. I was able to connect the Raspberry Pi with the monitor, in this case a computer, as well as a keyboard and mouse. I also successfully downloaded NOOBS, a way to make setting up a Raspberry Pi for the first time much, much easier. I also installed Python on the command line by running “sudo apt-get install python”.
How it works?
This project uses a Raspberry Pi that uses coding to send off the email to your phone or any other electronic device. The Raspberry Pi is a credit-card sized “small computer” that plugs into a computer monitor or TV, and uses a standard keyboard and mouse. It is a capable device that enables people to explore computing, and to learn how to program in languages like Python. First, NOOBS has to be installed to the Raspberry Pi’s Micro SD card. NOOBS is a zip file that includes software for setting up Raspberry Pi, including the Raspbian operating system into a 32 GB of data storage. After installing the Raspbian Operating System, Python has to be installed with the code: “Sudo apt-get install python-serial”. Terminal is a window which allows users to input commands that directly manipulate their Raspberry Pi’s system. Python is a general-purpose programming language. It is for developing both desktop and web applications and also designed with features to facilitate data analysis and visualization.
Image 1: Shows all components plugged into the Raspberry Pi
Image 2: Shows Raspbian downloaded
Image 3: Shows Python installed in command line terminal
What I learned?/Mistakes
I learned what a Raspberry Pi is as I never heard of one before. I also learned how to code using Python. Python is one of various coding languages that can interact with the Raspberry Pi. Most code for the camera and the Pi itself comes from Python files. Having the prefix “sudo” which stands for “super user do” gives the code certain elevated privileges to perform certain administrative tasks such as listing the objects in a file and shutting down the system. I used the website codeacademy.com to learn the basics of Python. The biggest challenge of reaching this milestone was setting up the Raspberry Pi. It took a while to actually get an SD card and downloading the NOOBS file and installing all the necessary software took a lot of time. Also, it can take up to 10 minutes to set up the Raspberry Pi each time I use it depending on the day. All in all, I’m very proud of reaching this milestone. It’s really cool being able to see what the camera sees on my monitor and it will be really mind-blowing once Amazon is able to recognize the faces in these pictures and memorize their features.
My Starter Project is MintyBoost a small and simple, yet powerful, way to charge your favorite gadgets like cameras, cell phones, and any other gadgets you can plug into a USB port to charge. The MintyBoost uses two AA batteries to charge your gadget. The MintyBoost kit includes all electronic parts to build your own USB charger.
How it works?
The MintyBoost uses two AA batteries that provide 1.5 volts each and then it goes through the circuit in which resistors are placed that limit the flow of electricity to not overheat other components. There is a boost converter is the most important part of the circuit because it takes the 1.5 volts from each battery, which is 3 volts flowing through the circuit and turning that into 6 volts which are required to charge any device like an iPhone. The ceramic capacitors help stabilize the output voltage and filters out high-frequency noise so that the 5V output is nice and smooth, it also stabilizes the internal reference of the boost converter chip. The Schottky diode is part of the boost converter, which is essentially used to make sure that voltage stays constant. The two electrolytic capacitors help smooth both the input and output voltages, to keep them stable during the transfer of energy. The charger circuitry and the two AA batteries fit into an Altoids gum tin and will run for hours.
Image 1. Finished product (Closed)
Image 2. Finished product (Open)
Image 3. Finished product with solder (Backside)
Image 4. Finished PCB with wires (Frontside)
What I learned?/Mistakes
I learned how to solder as the whole project required soldering and how to remove solder if a mistake occurred. I also learned how to use tin snips, in order to place the circuit board and batteries in the tin as a finished project. I also learned how to file and use sandpaper to in order to make edges of the tin not sharp enough. Some mistakes that I made while creating the MintyBoost was soldering the wrong resistors in the wrong place. I misplaced the resistor with the wrong color. With that I began to solder it and noticed it was in the wrong place. When I desolder them I placed it in the correct place. Once I tested them with the multimeter and the voltage was low. When I rechecked my circuit I noticed I miss a step in applying the boost converter chip which would have increased the voltage power. Then when I retested it the voltage power was fine. After retesting it, I tried it to charge my phone and it worked flawlessly.