Introduction: Smock (Your Very Own Smart Lock)
How Cool would it be To have a lock that could be controlled anywhere around the world? For example you were away on a business trip and you had to let someone into your house, and NOW you will be able to do just that with a tap of your phone ^.^. We will heavily be using Microsoft Azure which is a fantastic Cloud Computing tool(VPS, Big Dat, etc...) , to host all the Server sided aspects of this project! However, before you commit a basic understanding of Networking, Java, and Database Control should be just skimmed through!
This Project is very Coding intensive and takes a lot of varied knowledge to be able to pull off. HOWEVER, Java is such a documented and widely used project that anyone with the right attitude can figure it out! I promise that 99 percent of the challenge is in the first step, which is the Software step, after that you are so set and ready to easily take on the rest half awake!
Our Smart Lock has 3 main aspects, the software,
electronics, and hardware. Each component plays a vital role in the overall successful completion of the project.
Before you Begin here are all the components you will need!
X1 Raspberry Pi 35$
X1 Stepper Motor 6$
X1 L293D Driver 5$
X1 GPIO Header 5$
X1 Breadboard with Pins 5$
X1Wireless Adapter 5$
IM ALWAYS HERE TO HELP YOU AND WILL ALWAYS DO MY BEST NO MATTER WHAT SO NEVER GET DISCOURAGED IM HERE FOR YOU <3
And if you liked or were inspired by my project be sure to vote on the Coded Creations Page! :)
Without Further Ado, Let's get started!
Step 1: Getting Your Software Ready!
Of Course in the line of software development there are an infinite amount of ways to go about making a program do your bidding, so I highly recommend understanding everything in my code and asking questions, as the best thing to do is Learn! This is a very complicated component to add pictures, as there is so many pictures for each little step. Nevertheless do not get discouraged as the coolest Projects come from the most keyboard bashing!
For the user to be able to do everything remotely,
there are two things that need to be taken care of: The server-sided application, and the client-sided application. The server sided application takes care of all the behind the scene things, such as creating action based on user input and database values, all logical handling (for example if the door is in the locked state, hitting the lock button will just throwback an exception like “Door is already locked”) , and all other action handling such as running a script that will run a motor. The client side application will be used by our user. It includes anything from giving the user an Unlock/Lock option or even giving them a nice User Interface like a website to work with. In most and in our case, the server sided application will be a much tougher challenge. It is going to be very challenging for me to take you precisely step by step through everything because of how unlimited the implementations are! But I will always answer your questions and guide you to completion :)
A very big portion of this is Microsoft Azure's cloud computing capability. We need to create a bridge between the User and His/Her Raspberry Pi Lock, which will be our Microsoft Azure Dedicated Server. A dedicated server is basically a computer that is sitting up with racks of other computers at some Microsoft Hub, that we can control using the Remote Desktop Connection protocol that can be used on PCs, Macs, and Linux Operating Systems. You can sign up for a free Microsoft Azure trial here to get started: http://azure.microsoft.com/en-us/. The first thing you will be doing is setting up a Dedicated server. Pick whatever package you please as our server will not be under heavy strain until we incorporate multiple locks! On your Dedicated server, install MYSQL, which is an open source Database Utility by Oracle. (Sorry Microsoft no SQLServer for this guy :D ). Taking Microsoft documentation as aid, properly open port 3306 and make sure both UDP AND TCP outgoing and inbound traffic is allowed. On MYSQL you want to create a database and configure its tables based on how you implement the Java program discussed below. The Key idea is that our Database is being hosted on an IP Address like 184.108.40.206:3306, and can be accessed, and Queryed using our Java program below! Once again Do not get overwhelmed, Microsoft has provided a TON of documentation of working with their dedicated servers and is very easy to understand.
ONE POINT OF ADVICE: When picking what package for Microsoft Azure, make sure its a Window Server as it is much easier for the common user, but if you are a Linux GOD do what you want ^.^
Server Sided Application:
We need to first create a mechanism of controlling our Raspberry Pi microcomputer so it can control all aspects of the lock. We will accomplish using a Java program, the program will have to be able to keep track of the state of the lock(unlock/locked), be able to run scripts that drive the motor, read user input from the Webpage the user will be using. Before we continue, we have to setup a database that will hold all user inputs in the form of one number. So when the User hits the unlock button on their Phone it will write a 0 to the database, and if they hit the lock button it will write a 1 to the database. The program will then have to check the status of the lock and compare it to the database value, if they are the same no action has been taken, however if they differ the program knows the User has hit a button and will take the respective action, after the action is taken it will update the status of the lock and then the value of the database should equal the status value as well. This is the basic idea of the program which is attached to the end of this report(Smock SQL). There is one more component of the server sided application which is the mechanism by which the motor will be moving. This will be accomplished using two different scripts made in Python. One script will move the stepper motor in the needed amount of steps, and the other will do the same exact thing in the opposite direction. These scripts will be run by the Java program, when the database value and status value are different as discussed earlier. All these combined will create the server sided aspect of this project. You will obviously have to install Java for this to work, and configure your Azure Dedicated Server properly! Also the Stepper.py provided below is a general outline, you can create into 2 separate scripts very easily(unlock and lock).
The Files attached called: Stepper.py and SmockSQL.java show you what I did!
Client Sided Application:
The User needs a mechanism by which he can edit the values of the database, so the Java program knows when an action is needed to be taken. Many ways can accomplish this end goal, one being having the user logging on to the server that has the database and changing the value, but this is tedious and is not practical for our users. So we will create a website on which they can log onto their account and control the door with a very familiar lock and unlock button. This unlock and lock button will be within a JSP page, which is basically a Java-based web application. The goal of this page is so when the User hits the Unlock/Lock button, the needed query to the database will be run and the value of the database will be updated based on the button hit. Then our Server sided Java will read this updated value and carry out the necessary action. The JSP page with its Java application’s code used for this project at the end of this report as well.
The Files attached called: The rest of the Java files are JSP pages that show you what I did! You can implement these JSP serverlets into webpages using Netbeans, and deploying it as a WAR file on our Microsoft Azure VPS.
This pretty much concludes all the Software of the project. On to the Next Phase!
Step 2: Electronics
Oh to you guys I am a scrub at electronics. I literally do not even know what a transistor is and had to have my friend help me wire everything( it took him about 5 minutes).
Our Raspberry Pi, is a versatile microcomputer that
is known in the Tech community as a Single Board Computer. It is running on 512MB RAM and a very basic ARM processor. It comes with 4 USB ports, a power supply extension, Ethernet interface, HDMI connection, an SD Card reader that hosts the computer’s image, and a GPIO header, that can be used to interface a Breadboard to the Pi. We will be using a WiFi dongle that will connect to the router and give access to all online resources needed such as the Database to access values. A big reason I used a Stepper Motor is so I didn't have to wire another power source for something like a solenoid or a DC motor, but you electronic champions will have it done in a jiffy.
Our main focus will be the GPIO Header. We will connect one end to the PI’s interface, and one to a small breadboard. Attached to the Breadboard we will have a Stepper motor which will be drawing current from the PI’s power and will be able to move based on our Program setting individual pins on the board to High and Low. We picked a stepper motor due to its extreme accuracy compared to a standard DC, however we didn’t account for how weak a Stepper Motor is, so we will have to create a gear ratio to increase its power, sacrificing speed. The following are diagrams of how the breadboard and PI are all wired up.
In the picture above we can see the GPIO Header on the bottom,
the Stepper Motor on the top left. And one thing not covered is the L293D IC. Which is what is able to control the motor, by interpreting the Python programs(Our unlock and lock scripts) On and Offs.
The Raspberry Pi is not in view but is just connected by the Ribbon cable on the GPIO Header.
I put more pictures of the breadboard on the next step!
ONWARDS TO THE EASIEST PART!
Step 3: Hardware
The final component of our project is the Hardware aspect of the project. Technically if we had used the powerful DC motor this would have been a breeze, but as we went for accuracy and no external power it is important to understand how a stepper motor works.
*Reference the picture*
By energizing the coils in the right order, the motor is
driven round. The number of steps that the stepper motor has in a 360 degree rotation is actually the number of teeth on the cog.
The motor we are using has 8 steps, but then the motor also incorporates a reduction gearbox of 1:64 that means that it needs 8 x 64 = 512 steps.
Since we are using a L293D that is very good at reversing the current, we do not need this common connection, we can supply current in either direction to the whole of each of the coils.
Due to this limited Power we had to find a way to either amp up the power of the motor which could be dangerous to its life cycle, or to somehow manipulate the hardware to create more power, an example being a gear ratio.
Else this is so simple to just put on a Door Lock just find an intuitive way to package and mount everything! You can check out the one my friend made for me, due to the need of gearing up the stepper it was much bigger than needed! I also mounted it on a standard deadbolt which almost all Houses have!
Participated in the