At the start of my internship was forced to transition into a remote and virtual experience. Whenever I had a meeting, my housemates would find ways to disturb me, whether by knocking loudly, or by walking in unannounced. I searched everywhere for a smartlock that would be able to alert people outside that I was in a meeting. Unfortunately, I could not find anything that fit all my needs. Fortunately, being the engineering student I am, I knew what I had to do. It was time to bring this idea into existince and build it myself.
- Demo/Features
- Installation/Instructions
- Cloud Architecture
- Embedded Software
- 3D Printed Parts and CAD Model
- Electrical
- Materials and Equipment
- Troubleshooting and Common Problems
My work from home security system, aid in alot more ways then just a smart door lock. There would be a live gif and a small explantion for all features:
-
Remote Arming/Disarming from serverless site
-
Live updates from serverless site
-
Google calendar API
-
Autonomous Motion Light/System Sensor
-
Biometric Authentication
Click for Live Demo
- Authenticate authorize user to gain access to the room with their pre-regsiter fingerprint, the light will also blink a certain colour depending on the assessment. It will also save any fail fingerprint on local storage for identifying potential unauthorized events.
-
Excceded Timeout
Click for Live Demo
-
Forced Entry Detection
-
E-mail alerts
-
Logging events into database
-
Motion alert
-
Daytime/Nightime Mode
Youtube video Coming Soon
Since this project is made up of cloud, electrical and software engineering. I have split up instructions into their own categories to make it easier to follow. The React static site has it own separate repo, which will appear again in the step below when needed.
Please follow these sequence of instructions in order by clicking on the collapsable tabs:
Click on any pictures/GIFs to enlarge them
-
Click for General Setup Instruction
- Gather the materials and make sure you have aquired or have access to the required equipment, found here
- Start the 3D print of the Front and Back IO, these prints will take about 1-2 days to 3D print, click here for files
- There should be 4 total seprate prints
- These prints will take 1-2 days depending if you deviate from the recommended print settings
- If you use prusasilcer like me, I highly recommend using these settings here
- You can find the files here
- Setup the Raspberry Pi
- RECONMEND: I would use remote access methods like VNC Viewer or SSH, it makes it much easier to control the pi instead of direct connection
- Please follow this setup tutorial here, once completed move onto step b
- Please clone this repo to the pi
git clone https://github.com/KevyVo/Smart-Doorlock
- cd into the the requirements folder
cd Smart-Doorlock/requirments/
- Install the requirements
pip install -r require2.txt -r require3.txt
- You can also do this inside a virtual environment(venv) if you want
- Move onto the Electrical Instructions
-
Click for Electrical Instruction
For a larger image of the wiring diagram and wiring table, please click here
- I would recomend testing all of your components indivdially first to see if there are any defects/problems
- Go to the Test directory
- Select desired component base on the python file
- Follow the comment instrutions in the py file of what gpio pins to connect to
- If the python file does not run in the ide, run it in the terminal using python3 command
python3 component_name.py
- By doing this you will understand how each component behaves and interacts with each other, and assures that it is free of defect
- cd into the
cd Smart-Doorlock/Components/pyfingerprint/example_enroll
- I am still working on a feature to enroll your fingerprint using a button on the static- please stay posted! For now, use this method, unless you want to help the project add to it :)
- Run the file either in the terminal or ide
- Congrats! Your fingerprint has been enrolled locally to the system
- When connecting the dupoint connectors, make sure you can disconnect the male to female cable apart. This will be useful for mounting installtion later.
- Label all cables like this; it make the rewiring installtion easier later on
- Connect and solder all the electical connections using this diagram and connection tables found here
- Run the non cloud base script, to test how all the components will work all together
- If you see any warnings that do not effect your program, just ignore them for now
- If everything was successful please move onto Cloud instructions
- I would recomend testing all of your components indivdially first to see if there are any defects/problems
-
Click for Cloud/Software Instruction
If you want to read more about how the cloud architecture works please click here
If you want to read more about the flow of the software, please click here
- Sign up for a AWS account (if you already have a account you can skip this step)
- Follow this guide for help if needed
- AWS is free if you stay below the free teir limit (we won`t even get close to hitting the limit in this project); AWS is also cheap for personal use if you go over the limit.
- Setup a new IAM user- make sure to give programmatic access and console access and AdministratorAccess policy (you can add the appropriate policy if you know what you are doing)
- Retrieve the credential for later use
- Open up the terminal on the Pi and enter:
aws configure
- Enter that AWS account credentional; please refer to the screenshot for futher assitance and link
- We need to sign into the aws console and go to AWS Iot core
- Go to Manage->Things->Regsister a thing
- Click create a single thing and Give your thing name, scroll down and tap on the Next button and then you are immediately offered the one-click certificate generation option. An individual X.509 certificate per device is the recommended way of interacting with AWS IoT services from devices, offering the ability to burn the private key into the device upon enrolment that is then never transferred across the internet alongside requests, a security win. Download the certificate and private key for each device, and also a root CA. Make sure to hit that activate button so the certificate can be used. finish the process by clicking on the “Done” button.
- Next point is to create and attach a policy to the certificate, authorizing the authenticated device to perform IoT actions on IoT resources. for this tap on the “secure” tab from the AWS IoT menu which is on the left side, later go for the policies section. Now tap on the button named “Create” which is on the top right corner beside the iot-notifications Icon. give your policy name and fill the fields(Action, Resource ARN ) with a star “*” and check to Allow for Effect option then press the “create” button.
- Now tap on the certificates section which is right above the policies section, You will see a certificate which you have created earlier, tap on the three dots and choose to attach the policy, a pop will come showing your existing policies, check on the recent policy that you have created and attach. That’s it you have successfully created a thing, generated a certificate and attached policy to it.
- You can find the endpoint here
- I recommend putting all the files/cerficates in the empty directory I premade called "Credtionals"
- The endpoint can found here
- Fill out the appropriate lines out with the correct pathing in the main.py
awshost = "xxxxxxxxxxxxxx-ats.iot.us-east-2.amazonaws.com" # Endpoint awsport = 8883 # Port no. clientId = "xxxxxxxx" # Thing_Name thingName = "xxxxxxxxxx" # Thing_Name caPath = "/home/pi/xxxxxxxx/xxxxxxxx.pem" # Root_CA_Certificate_Name certPath = "/home/pi/xxxxxxxx/xxxxxxxx-certificate.pem.crt" # <Thing_Name>.cert.pem keyPath = "/home/pi/xxxxxxxx/xxxxxxxx-private.pem.key" # <Thing_Name>.private.key
- We can test the if the pubsub is working using this script
python only-pubsub.py
- You should be able to see a Message sent on the ide or terminal when you scan your fingerprint or change the state of the door
- You can see the data be pushed to AWS Iot core buy going to AWS Iot Core->Test
- Subcribe to topic(it the thingname filled out above)
- Everything can be default
- Hit Subscribe to topic
- You should see a message send like this on your browser
This diagram shows how the User table interacts with the main python script; to learn more about it click here
- We are going to build this table in the following step
- Navigate to AWS Dynamodb and make a new Table label: User
- Fill out the parameter of the table like this
- Navgaite to AWS Iot Core->Act and Click on Create a rule
- ![create](media/Images/Screenshots/Create Rule.png)
- Enter
real-time-door
for Name - Under Rule query statement, choose the latest version from the Using SQL version list.
For Rule query statement, enter:SELECT * FROM `Smart_Lock`
- Click add Action
- On Select an action, choose to Insert a message into a DynamoDB table and then choose Configure action.
- On Configure action, choose to create a new resource.
- On the Amazon DynamoDB page, choose Create table.
- When creating the DynamoDB table, enter
Users
for table name. In Partition key, enterdate
. Select Add sort key, and then enterunix
in the Sort key field. Choose String for date (partition Key) and choose Number for unix (sort key) and then check Use Default settings.Now choose to Create as marked in the below screenshot. - It takes a few seconds to create your DynamoDB table. Close the browser tab where the Amazon DynamoDB console is open. If you don’t close the tab, your DynamoDB table is not displayed in the Table name list on the Configure action page of the AWS IoT console.
- On Configure action, First of all, refresh the resources by clicking on the refresh sign between the Table name drop down and Create a new resource button. Then choose your new table from the Table name list.
- In Create a new role, enter a unique name, and then choose to Create role.
- Choose Add action
- Choose Create rule.
- After the successful creation of the rule, you will see the following screenshot.
- To see if your AWS Iot Core has logged your events, you can go to AWS Dynamodb and click on the table you just created
- Click on items and you will see your last couple of messages that was sent from your pi
For right now this only work with G-mail account
- Navigate to the file cred/e-mail.txt
- Fill out your credtional in the format of the placeholder and save the text file (This will be the sender e-mail)
- Go to the main.py and replace the placeholder of the receving e-mail
- If this section was successful you shoud recieve e-mail only for 3 events
- Sign up for a AWS account (if you already have a account you can skip this step)
-
Click for Static Site Instruction
- Since the static repo had to be a different repo, I have tranfer the instruction for portion onto the static repo
- Please return here after completion of the static site repo
- Congrats! If everything works, the only thing we still need to do is mount it onto our door. Move onto the Mounting instrutions
-
Click for Smart Lights Instruction
As of now, this device is only compatiable with Philips Hue Lights (mention in Material list)
- The lights and Hue bridge should be installed normally with the regular instrutions
- You know need to find what is the Hue bridge IP address, there are a couple method on how to find this ip:
- Accessing your router using the browser
- A windows scanner called Advanced IP Scanner
- Nmap scanning
- Make sure that all the lights have recognizeble names on your smartphone app
- Call the Hue bridge API by typing this into your browser, URL:
http://<IP>/debug/clip.html
Use the IP we retrieve above - We need to create user to use the api
- Press the Hue bridge button, then in the following 30 seconds hit the POST button to run the query
- A username should now be generated; please record the username somewhere. We will need this information later.
- We will now call all the lights to idenify their names; this will ensure that both lights are connecting with the API
+ Fill in the parameter like this:
URL: /api/<username>/lights (Replace <username> by the one you got in the previous step (long random string))
- Press the GET button
- One last test is to turn off one of the lights
+ Fill ther parameter like this:
URL:/api/<username>/lights/2/state Message Body: {"on":false}
- Press the PUT Button
- Navigate to
Smart-Doorlock/Classes/lock_lib.py
- Open the file in a IDE and replace the placeholder #IP Address with the IP of the Hue bridge
- Save and close the file
- Run the python file
Smart-doorlock/Test/Smartlightmain.py
in the terminal - Try unlocking and Locking your door using your fingerprint.
The light should flash green on successful fingerprint authention and flash red on incorrect fingerprint - If the lights work properly with the python file, move on to the Google Calendar Instructions
-
Click for Google Calendar Instruction
- Sign into your google account, using the same address as the E-mail alart
- Navigate to google calendar and make a differnt calendar called Work
- Make a Fake meeting from now until four hours from now.
- Click on this link, You only need to do step one of the google guide by clicking the blue button: Enable the Google Calendar API
- It will create a new Cloud Platform project and automatically enable the Google Calendar API and make a credentionals.json for us to use
- Navigate to the directoty and run Smart-Doorlock/G-Cal/gen_pickle.py
- A window should appear to sign in and give authentican to this python file, it also geneerate a token for future uses
- Now we can run the final script
- Open a terminal and Navigate then run the file Smart_Doorlock/Src/main.py
- The IO diplay should also know display a active meeting when motion is detected
- Congrats! The entire system works now, move onto Mounting instrutions
-
Click for Assembly and Mounting Instruction
- Insert the all components to the front IO like this
- Use the hot glue gun to keep everything secure, be careful not to touch the 3d print. The heat will burn/damage the print.
- Attach the PCB to the base plate of the door mount
- Attach all the components to the back of the IO like this
- Drill 3 holes on the cover
- Put the 3 x M3 bolts and nuts to secure cover to the base by using the hinge
- Pick a spot where you like the housing to be placed and drill a 1/4 inch hole
- Mount the Front IO to the door using the 4x10mm serews
- Mount the reed switch to top of the door
- Connect the reed pin to the pi
- Mount the electromagent to the top of the door
- Connect the electromagent to the relay + WARNING: be careful using a electromagnet, these magnet can seriously hurt you due to the crushing magnetic attraction force
- Attach the Front mounting base to the other side of door and use a level to ensure that it is straight
- Route the wires through the hole and push the cover onto base until flush with the door
- Reconnect the wires using the labels from earlier
- Connect the Power to usb c on the pi(For now the power will be deliver from the wall, I am looking to making a long lasting battery solution.)
- Close the lid, the magnets will attach onto the metal serews holding onto the door
- Plug in the electromagent power
- VNC or SSH into the pi and run the file
Smart-doorlock/main.py
in the terminal - Congrats! You have just join the advanced smart security system club. No more bursting into your room!
The majority of the web services I used is Amazon Web Services(AWS). Here are the reasons I why I used AWS. Firstly, I was the most comfortable using AWS because of my experience working at Amazon with AWS. Secondly, it has the service AWS IOT Core which the other companies do not offer a PubSub system. You can also used AWS SNS too instead of using the STMP server. I did this because using a STMP server would be free instead of paying for each message send by AWS SNS. The fingerprint files are stored on the local drive of the raspberry for security, instead of being uploaded to S3. My current stack of AWS is free, as I was below the 5GB free teir limit. The only thing I had to pay for was my one time website domain, heimdallr.ca.
The diagram represent will how the main.py states change depending on the inputs and sensor data. You can download/enlarge the image by clicking on it.
The flowchart explain every logic decisions in a very low-level. You can download/enlarge the image by clicking on it.
Click for explanation
- User scan fingerprint on scanner
- The fingerprint image get converted into a characteristic text buffer file. The file contain the unqie features of every different fingerprint then stores it into this buffer file.
- The characteristic file now compares itself to the other key characteristic in the local database. Every different fingerprint file has a index slot that corresponds to it characteristic file.
- If the buffer file matach over 60% similarity to local characteristic file it will go to the AWS Dyanmodb User Table and lookup the corresponding index number. If not match was found, a value of -1 will be return.
- AWS Dyanmodb Table will now return all the infomation corresponding to the index number back to the main.py to authenicate the user.
wfh-security-system (root)
├───cad
│ ├───Back
│ │ └───Mk3s
│ └───Front_IO
│ └───Mk3s
├───electrical
│ └───Images
├───libs
│ ├───creds
│ ├───custom
│ ├───phue
│ ├───pyfingerprint
│ │ ├───doc
│ │ └───src
│ │ ├───debian
│ │ │ └───source
│ │ └───files
│ │ ├───examples
│ │ └───pyfingerprint
│ └───raspberrypi-lcd
├───media
│ ├───Gif
│ └───Images
│ ├───Brands
│ ├───CAD
│ │ ├───Back
│ │ └───Front
│ ├───Diagrams
│ │ ├───Cloud
│ │ │ ├───Final
│ │ │ └───Icons
│ │ ├───Fingerprint
│ │ ├───FlowChart
│ │ └───State_Diagram
│ └───Screenshots
├───requirements
├───src
└───test
├───Button
├───Buzzer
├───Calendar
├───Combine
├───DB
├───E-mail
├───Lcd
├───Led
├───Main
├───Pir
├───Pubsub
├───Reed
├───relay_lock
└───Scrap
I have created these 7 custom libraries to interact with the main.py file as the main driving file.
- lcd_lib.py
- Responsibilty:
- Provides a class intake a string and convert it to bits to display the string on the LCD
- Responsibilty:
- lock_lib.py
- Dependency:
- lcd_lib
- awsIOT_lib
- Responsibilty:
- Handles all of the locking and re-locking logic
- Handles all the buzzer sounds and lights sequence
- Send state messages to AWS IOT Core
- Dependency:
- db_lib.py
- Responsibilty:
- Checks if the table exist, if no table then create a new table
- Retrieve information from tables
- append items
- Responsibilty:
- awsIOT_lib.py
- Responsibilty:
- Connects to the AWS Iot Core
- Publish MQTT messages
- Responsibilty:
- awsIOT_sub.py
- Responsibilty:
- Connects to the AWS Iot Core
- Constantly listen to the command sent from React site
- Responsibilty:
- GCAL_lib.py
- Responsibilty:
- Connects to the Google calendar api
- Constantly listen to work calendar for event and event changes
- Responsibilty:
- mail_lib.py
- Responsibilty:
- Connects to SMTP server
- Send e-mails from lock e-mail to user email
- Responsibilty:
For Prusasilcer my 3mf file has all of the print settings, just set the machine to other models if you are not using a Prusa i3 MK3s
Click for Cura silcer
- Cura Normal profile
- Nozzle 0.4mm (haven`t tested other nozzles)
- Infill density: 20%
- Skirt: 3 layers
- Support from build plate only
Click for other silcers
- Support from build plate only
- Nozzle 0.4mm (haven`t tested other nozzles)
- Infill density: 20%
- Skirt: 3 layers
- First layer speed 20mm/s
- Perimeters: 45mm/s
- Infill speed: 80mm/s
Click here for CAD files
Click here for 3mf/gcode for Prusa i3 MK3
Click here for CAD files
Click here for 3mf/gcode for Prusa i3 MK3
Front
If the image is to small you can click and download the image. There are also corresposing wiring tables below if the diagram need more clearifcation.
Click for Stand Alone Components Table
BB GND = Breadboard Ground
BB POS = Breadboard Positive
PIR = Passive Infor read Sensor
From | To | Wire Colour | Component |
---|---|---|---|
#1(3v3) | Fan Pos | Red | Cooling Fan |
#9(GND) | Fan Neg | Black | Cooling Fan |
#29(GPIO 5) | Reed Pos | White | Reed Switch |
#25(GND) | Reed Neg | Black | Reed Switch |
#4(5V) | PIR Pos | Red | PIR |
#7(GPIO 4) | Data | Yellow | PIR |
#14(GND) | PIR Neg | Black | PIR |
BB GND | LED GND | Black | LCD |
BB POS | LED Power | Red | LCD |
#12(GPIO 8) | DB7 | Orange | LCD |
#16(GPIO 23) | DB6 | Grey | LCD |
#18(GPIO 24) | DB5 | Brown | LCD |
#22(GPIO 25) | DB4 | Cyan | LCD |
#10(GPIO 15) | E | White | LCD |
BB GND | R/W | Black | LCD |
#28(ID_SC) | RS | Light Brown | LCD |
BB GND | V0 | Black | LCD |
BB Pos | VDD | Red | LCD |
BB GND | LCD1 | Black | LCD |
#40(GPIO 21) | Buzzer Pos | Red | Buzzer 1 |
#39(GND) | Buzzer Neg | Black | Buzzer 1 |
#38(GPIO 20) | Buzzer Pos | Red | Buzzer 2 |
#34(GND) | Buzzer Neg | Black | Buzzer 2 |
Click for Resistor Componets Table
BB GND = Breadboard Ground
R = 10K ohms Resistor
From | To | Wire Colour | Component |
---|---|---|---|
#36(GPIO 16) | Cathode with R | Green | Green LED 1 |
BB GND | Anode | Black | Green LED 1 |
#37(GPIO26) | Cathode with R | Green | Green LED 2 |
BB GND | Anode | Black | Green LED 2 |
#31(GPIO 6) | Cathode with R | Cyan | Pushbutton 1 |
BB(GND) | Anode | Black | Pushbutton 1 |
#33(GPIO 13) | Cathode with R | Yellow | Pushbutton 2 |
BB GND | Anode | Black | Pushbutton 2 |
#35(GPIO 19) | Cathode with R | Pink | Red LED 1 |
BB GND | Anode | Black | Red LED 1 |
#13(GPIO 27) | Cathode with R | Pink | Red Led 2 |
BB GND | Anode | Black | Red LED 2 |
Click for Muti-Components Table
There will be a table for each component in this section.
BB GND = Breadboard Ground
BB Pos = Breadboard Postive
From | To | Wire Colour | Component |
---|---|---|---|
#11(GPIO 17) | Relay Data | Blue | Pi-Relay |
BB Pos | Relay Pos | Red | Pi-Relay |
BB GND | Relay Neg | Black | Pi-Relay |
Electromagenet Pos | Middle Relay Slot | Red | Relay-Electromagent |
Electromagenet Neg | Normally Closed(NC) | Black | Relay=Electromagenet |
From | To | Wire Colour | Component |
---|---|---|---|
3v3 | Positive | Red | CP2102-FPM10A |
Rx | Rx | Green | CP2102-FPM10A |
Tx | Tx | Blue | CP2102-FPM10A |
GND | GND | Black | CP2102-FPM10A |
If you do not own a 3D printer, there are many other ways you can gain access to one.
Here are some possible options:
- A University or School, most places of education now provide 3D printer for use
- A community center
- A friend or a famliy member
- A maker space
- A online/local printing service
Click for Equipment list
If you like to buy some of these items please consider helping support me by buying them through my affiliate links, they would be the same low price either way you purchase them.
- 3D Printer (This is the one I have, not a affiliate link)
- Wire Strippers
- Hot Glue Gun
- Soldering Iron/ Soldering Station
- Needle nose pliers
- Wire cable cutter
- M3 hex wrench (Usually comes with machine screws)
- Metal Pick (optional, used for support removal)
- Serewdriver
- Power drill
- Philips head attachment (from screwdriver)
- 1/8 inch drill bit
- 1/2 inch hole saw attachment
I do recommend in just using old parts from pervious projects or leftover from bulk orders. You can try to also find some from a friend or school as well.
If you like to buy some of these items please consider helping support me by buying them through my affiliate links, they would be the same low price either way you purchase them.
Click for Materials list
- Raspberry Pi 4 or 3B+, any GBs is fine (I recommend pi 4)
- CP2104 USB to UART
- A Pack of Dupoint connectors
- A set of 22 gauge wires
- 3D printing Filament (I used PLA)
- Red LEDS x 2 pieces
- Green LEDS x 2 pieces
- 40mm x 40mm Fan
- 1 Heatsink
- 5V 3A power supply for raspberry pi 4
- Electromagnet
- Reed switch
- Pushbutton
- USB type C for raspberry pi power
- Fingerprint scanner (FPM10A)
- Solderable prototyping PCB
- 1602 LCD
- PIR sensor
- Passive Buzzers
- Relay
- A set of 10K resistors
- Small hinge
- 8mmx3mm magnets x 2 pieces
- Philip Smart Lights
- All the screws sizes and quantity
- M3 x 8mm Socket head x 8 pieces
- 7mm washers x 4 pieces
- #8 x 5/8 inches wood screws x 8 pieces
- Hinge screws comes with the hinge set
blah blah blah :)