The Protected House

by GeoffreyH24 in Living > Organizing

319 Views, 2 Favorites, 0 Comments

The Protected House

The Protected House   FINAL

Have you ever been

robbed? Are you thinking about protecting yourself before this happens? We all have in our entourage a person who has been the victim of a burglary or we have already heard about it ... A burglar who enters by the door of the garden and steal the jewels of Mom in his room, It's pretty unpleasant, isn’t it? So, this project is for you!

The protected house will allow you to limit the impact of an undesired intrusion into your home by blocking the thief in the room where he entered. Thanks to the electro-magnets, he won’t be able to progress in the house and the jewels in the mom’s room will remain in peace.

Command Devices

reghzterh.jpg

Program materials will allows us to program the anti-intrusion system and the GSM transmission system. These were essentially an Arduino Mega and a Raspberry Pi 3.

o Arduino MEGA

The link to buy the Arduino: https://www.gotronic.fr/art-carte-arduino-mega-2560-12421.htm#complte_desc

The price is 39,90 €.

Other equipment to buy (not delivered with Arduino):

o A female cable

o A male cable

o A USB cable à To connect the Arduino to the Raspberry PI 3

The link to buy the cable: https://www.amazon.fr/imprimante-scanner-QUALITE-SUPERIEURE-Longueur/dp/B002JV4MMA

o Raspberry PI 3

The Raspberry is the interface between the user and the alarm system. Thanks to it, the user is able to visualize the state (open/close) of the magnetics contacts of doors and windows. It also allow the user to lock/unlock the alarm system and activate/deactivate the electromagnets room by room.

The Raspberry send orders to the Arduino to do some actions like: lock/unlock electro-magnets, activate/deactivate alarm system, …

The Raspberry is wired to the Arduino by a serial cable. It is supplied by a micro-usb cable with a 5V voltage.

The link to buy the Raspberry PI 3: https://www.gotronic.fr/art-carte-raspberry-pi3-b-1-gb-24532.htm#complte_desc

The price is 44,95 €.

o The Relay

For our project, we decided to control the electro-magnets used to lock the doors of the house thanks to some 24V relays.

For this, we retrieved eight relays from an electrical cabinet. The relays allows to separate the control part (Arduino) and the power unit.

We wired the inputs of the relays to two pins: a pin to 24V and the other to link to the mass. The outputs are wired on a 12V power supply connected to the electro-magnets.

In addition, we placed the relays on a mounting base, fixed on the model.

Practically, when a magnetic contact is in open state (a thief try to enter in the house and open a door or a window), the Arduino receive this information and supply the relays. Those activate the 12V supply of the electro-magnets and all the doors are locked.

The Screen

Through the screen, the user can visualize all the actions made via the Rapsberry.

The screen is simply connected to the raspberry by a VGA or HDMI cable.

Power Supply

For power supply, we used a 12 volt power supply for the electromagnets and a 24 volt for the relays. Indeed, we have connected the electromagnets to relays to control the opening and closing of the doors. On the other hand, the magnetic contacts were connected to a terminal block and then connected to the Arduino.

The Anti-intrusion Material

eyj(èj.jpg
qzergrz.jpg
rgthsteg.jpg
trhzh.jpg

The anti-intrusion material will allows to simulate realistically the operation of the system. These were essentially magnetic contacts and magnetic retainers.

o Electro-magnets

The electro-magnets are made by ourselves. We used nails, isolated with insulation strip. Then we rolled electric wire around the nails.

When electro-magnets will be supplied, they will attract a metal piece placed on the doors and lock all the access to the other rooms of the house.

The electro-magnets will be supplied with the 12V power supply.

This kind of electro-magnet is only useful if you want to create a model like us. If you want to reproduce this system at real scale, for your house, you will need real electro-magnets like this (the way to wire it to the Arduino is the same):

Example of wiring:

o The magnetic contacts :

The magnetic contacts are used to detect an intrusion through a door or a window. It’s divided in two parts:

The top part is composed by a cut wire. The bottom part is a magnet. When the two parts are near enough, the cut wire is attracted and the current is able to flow through it.

When the two parts of the magnetic contact are not near enough (a door or a window is opened by a thief), the cut wire isn’t attracted anymore so the current can’t flow.

This information is sent to the Arduino and the Rapsberry. If the intrusion is detected, the electromagnets are activated and the horn ring.

Example of wiring:

o The horn :

The horn is useful to warn the owner of the building and the neighbourhood that somebody try to enter.

The horn is connected to the Arduino by electrical wire.

Example of wiring:

Programming

Our program is separated in 2 part, the first part is programmed on the raspberry pi and the second part on the Arduino. The main function on the raspberry pi consist to generate a graphic interface for the user. For the Arduino, it sends the states of sensors and electromagnets to the raspberry. It activate or deactivate the electromagnets.

o Raspberry

When we run the program, the interface automatically open. We see buttons, lights, and the password location.

Here is the code to create a graphic interface window and buttons, the bleu part is the action of button in the program.

fenetre = Tk()

fenetre.geometry("750x500")

label = Label(fenetre, text="MAIN")

label.grid

bouton = Button(fenetre, text="Fermer", command=fenetre.quit)

bouton.grid(row =20, column= 4)

For the lights indicator, we generate the sub-window with indication and specific colour.

#txt1 = Label(fenetre, text ='etat capteur 1',bg ="blue")
#txt1.grid(row = 1, column = 3)

The most functions are same way, it sends a message to the Arduino, thanks to the command “Serial”.

def serialPrint6():
text=code1.get()

if text =='test':

ser.write('8')

else:

mdpVar='veuillez entrer le MDP'

txt20 = Label(fenetre, text =mdpVar,bg ="red")

txt20.grid(row = 17, column = 4)

Code1 is a character strings, it is defined like that, in same time we position it in the interface.

code1=StringVar()

entr1=Entry(fenetre, textvariable=code1)

entr1.grid(row = 18, column = 4)

The SerialRead function is more complex that the others. Indeed, it send a message to the Arduino but it receives the state of all sensors and electromagnet. These states are store in a list “capteur”.

def serialRead1():
var=0

capteur=[]

print("début affichage")

ser.write('2')

while var<19:

capteur.append(ser.readline())

var=var+1

Next, we change the colour of light indicator according to the state.

if capteur[1] =='1\r\n':

txt2.config(bg ="green")

else:

txt2.config(bg ="red")

o Arduino

We begin to define the variables used in the program, the inputs, and outputs.

The first function activates all the electromagnets. The output become “high”.

digitalWrite(act_1,HIGH);

The second is the reverse.

digitalWrite(act_1,LOW);

The third function, reads the all sensors state.

contact1=analogRead(contact_1);

The fourth and fifth function, sends to the raspberry pi the state of sensors and electromagnets.

Serial.println(contact1);
delay(1);


Serial.println(em1);

delay(1);

Now we are in the main loop. The Arduino wait the instruction from the Raspberry. All actions are due in a “switch case”.

To the case 0, the Arduino will deactivate all the electromagnets and the siren.

To the case 1, the Arduino will activate all the electromagnets, but if nothing sensors detect an intrusion, the electromagnets and siren are turn off. When an intrusion is detected the electromagnets and siren are turn on.

To the case 2, the Arduino will read the sensors state and sends it to the Raspberry, next it sends the electromagnets state.

To the case between 3 and 8, the Arduino will deactivates the electromagnets room by room, according in the request of the user.

To the case 9, the Arduino will deactivates the siren only.

Smartphone Application

step 6.png

A smartphone application is also used as an interface

between the user and the alarm system. It plays same role than the screen but it allows to do it remotely via the wifi connection.

The user has to install Tiny VNC on his smartphone and VNC player on the raspberry.

To control remotely your raspberry, you need to install the application VNC and change some settings in Raspberry.

In first time, you need to install hostapd:

Open the command windowand tape:

Sudo apt-get update

Sudo apt-get upgrade

Be careful about this point: You need to connect your raspberry on the internet to make the updates and installations.

After a few minutes, you can install hostapd with the following command

Sudo apt-get install hostapd

You must accept the installation.

The installation take approximately 10 minutes.

Now we must manage the wireless IP:

Sudo nano /etc/dhcpcd.conf

You must write the following code at the end of the file:

Denyinterfaces wlan0

After that you must go out of the file and save settings: CTRL+C / y / enter

Now we are going to change the IP address.

Open the file with the command :

sudo nano /etc/network/interfaces

You must change the Wlan0 code to the following code

allow-hotplug wlan0

#iface wlan0 inet manual

# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

iface wlan0 inet static

address 172.16.0.1

netmask 255.255.255.0

you can choose your IP address but you must be careful to not use not private address.

If you use the same IP address as your computer, your internet router or other you probably will have some problem.

Save the file and restart with the following command:

Sudo service dhcpcd restart

Sudo ifdown wlan0; sudo ifup wlan0


We need to change the Hostapd settings. Therefore you must change the hostapd config.

To open the hostapd config tape :

sudo nano /etc/hostapd/hostapd.conf

The command window open a new file. You need to write the following code

interface=wlan0

driver=nl80211

ssid=Pi3-AP

hw_mode=g

channel=6

ieee80211n=1

wmm_enabled=1

ht_capab=[HT40][SHORT-GI-20][DSSS_CCK-40]

macaddr_acl=0

auth_algs=1

ignore_broadcast_ssid=0

wpa=2

wpa_key_mgmt=WPA-PSK

wpa_passphrase=raspberry

rsn_pairwise=CCMP

Go out of the file and don’t forget to save it.

Now we can test if Pi is connected to wi-fi

Tape the command line :

sudo /usr/sbin/hostapd /etc/hostapd/hostapd.conf

And check with your smarphone or digital tablet if Pi3-AP is online.

Tape : CTRL+C to go out of hostapd

You can see the Wi-fi of the raspberry but for now you can’t connect your smartphone with the Pi wi-fi.

We need to add some parameters therefore.

Sudo nano /etc/default/hosapd

Find the line # DAEMON_CONF = ""

Fill in the line to have : DAEMON_CONF = "/etc/hostapd/hostapd.conf"


You need to install DNSmasq

sudo apt-get install dnsmasq

That can need a little time to be installed.

Open the dnsmasq configuration file with the command :

sudo mv /etc/dnsmasq.conf /etc/dnsmasq.conf.org

sudo nano /etc/dnsmasq.conf

In that file you need to write this code:

interface=wlan0 # Utiliser l interface wlan0

listen-address=172.16.0.1

bind-interfaces

server=8.8.8.8

domain-needed

bogus-priv

dhcp-range=172.16.0.50,172.16.0.150,12h

Restart the hostapd and dnsmasq

sudo service hostapd start

sudo service dnsmasq start


Now you need to ad vnc :

open the raspberry parameters and activate the VNC and SSH interfaces:

(see picture above - In the beginning of step 6)

Now you can open the VNC application on raspberry.

You need to install VNC application on your smartphone or digital tablet.

For the first connection, you need to be connected with the Pi3-AP wi-fi, write the Ip address and other password.

If that is not so clear, look at the video in the following address.

http://www.framboise314.fr/prendre-la-main-a-dista...