Priority One

by CedricLagrou in Circuits > Raspberry Pi

427 Views, 2 Favorites, 0 Comments

Priority One

IMG_20210614_135314.jpg

I am a student 'Multimedia and creative technologies' and for school i had to make a project.

The project is a Home security system, that ensures to keep your home safe;

To do that we use sensors to check if someone is inside the house.

We can check movement inside the building by using an Infrared movementsensor, Hall sensor and a ultrasonic sound sensor. They all work their own way and detect specific types of movement. The Hall sensor is dedicated to checking doors/windows, the infrared movement sensor can detect changes in position and the distance sensor checks if someone walked through the line.

Supplies

For this Project you need:

  • Raspberry pi

I chose the raspberry pi for this project because it was necessary for our school project and it's also a perfect device for the project.

  • RC-522 RFID tag

I chose an RFID tag to turn the alarm on and off, it's a lot easier to use than to type a code

  • mini oled display

As a display i used a mini oled, it might be a small screen, but it's still really visible and does everything you need for this project

  • DS18B20 one wire sensor

I used the one wire temperature sensor, because it's easy to use and you you can plug it into the raspberry pi directly

  • breadboard 3.3V power supply

To power the RFID, one wire and oled display i used a external 3.3V power supply, you can also use the 3.3V from the Raspberry pi, but it's safer to do it this way

  • (optional T-cobbler)

A T-cobbler is optional, it can make building a project like this a lot more fun for beginners

  • Arduino

To read in all the other sensors i have, i use a Arduino, the sensors require 5V, so the arduino was the perfect fit for that, you can choose from different types of arduino's, but i used a UNO

  • HC-SR04 ultrasonic sound sensor

I used the distance calculation from the sensor to create a trip wire effect. When something passes the distance changes and the alarm will be triggered

  • MQ4 gas sensor

The gas sensor is meant to read CO- values, I find it important, especially in homes were you still you open gas heating and where the CO-values can rapidly change.

  • Hall sensor

To look if a door is opened i use a hall sensor, this sensor mesures magnetic field between a magnet and the sensor, when the magnetic field is too weak, the door has been opened

  • PIR sensor

I use a PIR to mesure movement in more open rooms, when someone walks into the room the signal goes high and you know someone is there

  • relais
  • 12V siren
  • 12V power supply

The relais, 12V siren, 12V power supply are for the sound effects, to alart potential neighbours, and the criminals that an alarm has been triggered

Fritzing

schemaPriorityOne_bb.png
SketchPriorityOne_schem.png

Here you can see how everything is put together, you can see a Breadboard view as well as a electronic view.

You can connect the Arduino and Raspberry pi using USB ( or optional a level shifter ). We'll need to have these connected to make sure we can have Serial communciation between the 2 devices.

Raspberry Pi Configuration

We got a Rasbian image from school that already had a couple things set-up, but you'll have to create an image yourself.

1) Download Rasbian

link: https://www.raspberrypi.org/software/operating-sys...

You will have different option, the best to use if you are starting off is the Raspberry Pi OS with desktop and recommended software. This version will have a lot of things already pre-installed that will make working with the Rpi a lot more fun and easy.

2) Setting up the image

For this step you will need a SD-card minimum 8gb, maximum 32gb, preferred 16gb.

You can use and existing SD-card and format it in disk-part or other applications

For disk part, just type in disk-part in the windows search bar and open it.

list all the disks

list disk

than you will see the disks available on your device

you will see a disk with 16gb and to the left of it it will have it's name, example: disk 1

you can select this disk by:

select disk 1

It should say it has selected disk 1

To clean the disk just type:

clean

3) Writing the image

To write the image onto the SD-card i used win32 disk imager

link: https://sourceforge.net/projects/win32diskimager/

in this program, you can select your sd-card and the image file and write it onto the SD-card

4) Connecting via SSH

once everything is written onto the sd-card you can go to it's directory and there should be a file named 'cmdline.txt', you can open it with notepad and add on the end of the line 'ip=192.168.168.168' and save the file

You also have to create a file named 'ssh' without any extension.

You can now eject the SD-card, but do it with the safe eject feature from windows.

Once this is done, you can insert the SD-card into the Raspberry pi and connect a LAN cable from the computer to the Raspberry pi

5) Connect to Computer

To connect to the Raspberry via SSH we need another program, called putty

link: https://www.putty.org/

you can open this and insert ip:' 192.168.168.168' and connect to port '22' and connection type SSH

now you can see a command line appear that's asking you for a login, the default user is 'pi' and it's password is 'raspberry', but you can change this.

6) settings

to get into root:

sudo -i

and to acces the raspberry pi's configuration:

raspi-config

Inside the interfacing section, you can enable one-wire, SPI, I2C and Serial communication.

7) internet connection

To add wifi to the project you have to use a command: ( SSID is network name )

wpa_passphrase "ssid" "password" >> /etc/wpa_supplicant/wpa_supplicant.conf

than you have to reconfigure the network settings.

getting into WPA_command line:

wpa_cli

select wireless lan interface:

interface wlan0

reconfigure wlan:

reconfigure

Wifi should be set up now

8) software

first of you'll have to update the existing software on the Raspberry pi:

sudo apt update
sudo apt upgrade

install apache2:

apt install apache2 -y

install mariaDB:

apt install mariadb-server mariadb-client -y

getting the python packages ready:

pip3 install flask-cors
pip3 install flask-socketio
pip3 install mysql-conector-python
pip3 install gevent
pip3 install gevent-websocket

Database

databasemod.PNG

For the database I made 3 tables. The first one is for the location, e.g. kitchen, hall, garden, ...

The second one is for the device, I use different kinds of devices, like RFID tag, temp sensor, IR, ... so I labeled them there.

And the last table is for the history, everything that happend you can see there. For example, the front door has opened, so now we see a row appear that the front door has opened.

Back-end

To create a link between the database and the front end, we'll need a backend.
For this project i used Python ( and Flask ) to do this.

I made multiples threads so multiple things could be done. We made the backend listen to the arduino, register temperature, check on front-end messages via socketio and made the backend send socketio messages with the new sensor values to the front-end.

There are also multiple threads running on the back-end, there is a RFID loop, temperature loop and a main loop, where all the other things are inside.

We also have a DataRepository, you can find the SQL-statements inside there.

You can find a link to the code in step 6.

Front-end Website

wireframes.PNG

For the web interface i went with a simple and clear interface, where colors and icons help you to navigate. You can see a picture of the wireframes i made to design to web-interface.

I recreated these wireframes using HTML & CSS.

To show backend information i used Javascript, so everything could update in real-time with socketio.

All the code is available on step 6

Code

All the code is available on github:

https://github.com/LagrouCedric/PriorityOne

Case

IMG_20210614_135333.jpg

For the case i used model cardboard, it's a good material to use, because it's easy to cut and it's decently strong and really light.

I also made a couple of attributes to give the model a nicer look and to create the home environment.

It also has a compartment for all of the electronics so you can easily get to them.