---
# System prepended metadata

title: Beginner friendly home security system
tags: [IOT]

---

# Beginner friendly home security system
###### tags: `IOT`

**Felix Hübinette - fh222xn**

This tutorial is going to show you how to develop a very basic home security system that is very beginner friendly.

The home security system is going to be able to detect movement, make sound and blink to scare off all possible intruders. 

**Estimated Time:** 4-8 Hours


### Objective

The objective of this project is to try and develop a simple but effective IOT project based on the material that the course has thought out.

I live in a student corridor so I thought this would be the perfect wake up alarm/security system for when my corridor friends try to go into my corridor room in the middle of the night. 

This project will make use of some of the different areas of IOT that this course has taught me. The project  will also give me some basic insights to how it is to work within the IOT area,that I can expand upon later by working on more advanced projects. 

### List of material
| Material | Use | Price | Link |
| -------- | -------- | -------- | -------- |
| Lopy4 and expansionboard    |Used as a main unit, runs code and connects all parts|  849 sek    | [Link](https://www.electrokit.com/produkt/lnu-1dt305-tillampad-iot-lopy4-basic-bundle/)     |
| Usb-cable    |Connect lopy4 to power | -  | Comes with above     |
| Cabels male-male|Connect the different parts | 29 sek     | [Link](https://www.electrokit.com/produkt/labbsladd-20-pin-15cm-hane-hane/)     |
| Cabels female-male    |Connect the different parts | 29 sek    | [Link](https://www.electrokit.com/produkt/labbsladd-20-pin-15cm-hona-hane/)  |
| Breadboard |Simplifies connecting parts | 59 sek    | [Link](https://www.electrokit.com/produkt/kopplingsdack-400-anslutningar/ )    |
| Passiv-buzzer    |Makes sound | 36 sek  | [Link](https://www.electrokit.com/produkt/piezohogtalare-passiv/)  |
| PIR-Sensor |Recognizes movement | 49 sek     | [Link](https://www.electrokit.com/produkt/pir-rorelsedetektor-hc-sr501/)     |
| PIR-Sensor |Recognizes movement | 49 sek     | [Link](https://www.electrokit.com/produkt/pir-rorelsedetektor-hc-sr501/)     |


### Computer setup

In this tutorial we are going to use the IDE visual studio code. The programming language we are going to use is called micropython. 

Step 1: Download and install [visual code studio](https://code.visualstudio.com/download) which we are going to use to write the code for the program.

Step 2: Install the plugin pymakr in visual code studio. This plugin is used to upload and run code on the lopy4. [Detailed guide](https://docs.pycom.io/gettingstarted/software/vscode/).

The picture below shows the interface that the pymakr provides. With a button click you can upload code to your lopy4 device, download existing code from the device and also run existing code on the device.
![](https://i.imgur.com/gnt8SSR.png)


Step 3: Download and install [Nodejs](https://nodejs.org/en/download/) which is needed to write working code.

Step 4: Update the expansion board. [Detailed guide](https://docs.pycom.io/updatefirmware/expansionboard/).

Step 5: Download the pycom updater tool and update your Lopy4 device. [Detailed guide](https://docs.pycom.io/updatefirmware/device/).

Now everything is completed that is needed for us to start working on the project. 

### Putting everything together
Below is a picture that shows how all the components are connected. The blue lines go to output for the sensors, the red lines go to power and the green lines go to ground. The PIR-sensors red power cable goes to vin. The PIR-sensors output goes to p15. The ground cables from the PIR-sensor and passive buzzer goes to the grounded line on the breadboard. The passiv buzzers power cable goes to 3v3. Lastly the passiv buzzers output goes to p22.

![](https://i.imgur.com/HOstVhF.png)

### Platform
Because of the fact that this is a beginner friendly iot project, i decided to use the platform pybytes for handling and displaying the data. Pybytes is by far the most beginner friendly and ease of use platform. Pybytes is a cloud-based device management platform that is totally free. With the help of pybytes everything can be set up from their site related to wifi and preparing signals. Pybytes setups pretty much everything and makes it very easy to start sending data to their servers.

![](https://i.imgur.com/TQu1YoA.png)

Pybytes is used by connecting your device to the site. Follow this [guide](https://hackmd.io/@lnu-iot/r1bGPUOhu) to connect  your device to pybytes. With the help of that tutorial you should be able to setup your devices wifi on the site and setup the device correctly to pybytes system. When the device is connected, signals can be sent to pybytes with data. The data from the signals can then easily be represented in different formats lika graphs and tables on pybytes site. Pybytes also has a basic notification system that can be implemented to see when the device has been offline for a certain time and so on.

### Connectivity
The data is sent whenever the device is triggered, then it automatically sends data that tha alarm was triggered to pybytes servers.  

The device is connected to my home's wifi and is using MQTT protocol when transporting the data to pybytes servers. The signals are sent with the help of pybytes functionality. Which handles everything by running just one function **pybytes.send_signal** when the device is setup and connected to pybytes system.


### Code 
The code of the project is provided in the image below. Very simple but effective code for what the project wants to perform.

![](https://i.imgur.com/iUt1dK1.png)


### Presenting the data
The data is saved to pybytes servers whenever new data is sent which is when the device is triggered. The data is then saved on pybytes servers for 30 days. 

In pybytes you can easily create different kinds of dashboards that can represent the data in a clean format. I decided to make a simple graph that shows the time when the device is triggered. A more detailed [guide](https://docs.pycom.io/pybytes/dashboard/) on how to do this. 
![](https://i.imgur.com/h7Ck3TV.png)


In pybytes I also set up a notification system that shows when the device has been offline for more than five minutes.

![](https://i.imgur.com/RNmeCm1.png)


### Finilazing the design
For finalizing the project I took all the parts and put them into a small cardboard box. I made a hole for the PIR-sensor and a small hole where light can come out. 
![](https://i.imgur.com/uyDoqeM.jpg)

Here is how the final design of my example dashboard is looking. This can be designed however you like it, depending on how you prefer it to look like. 
![](https://i.imgur.com/O1fH0zo.png)

Because of the fact that this is a very basic version of a home security system there is room for a lot of improvements. 
Another more advanced platform like ubidots can be used instead of pybytes. Then a more advanced notification system can be set up, where the user gets an email when the alarm is triggered. 
A camera can also be added to show the intruder that triggered the alarm. A louder speaker and stronger lights can also be added for a worse breakin experience for the intruder.