Introduction: Raspberry Pi Domotica - SecuHome

Picture of Raspberry Pi Domotica - SecuHome

Hello everybody, welcome on instructables!

I made a domotica system for a school assignment in the direction NMCT at Howest Kortrijk. I called my project SecuHome. I want to combine a sort of security when the people are away in there house. The assignment was to make something that it looks that someone live there even if they are on vacation.

I took this more like a challenge to test myself how far I can go in a few weeks. How everything works and how I made it, I will explain in the following steps.

Step 1: Demo

Picture of Demo

I made a demo about my project. Just click on the attachment and it will download.

Hyperlink to my dropbox for the demo: Demo project

Step 2: Brainstorm

Picture of Brainstorm

The first thing you have to do is to brainstorm. Which project am I going to do and how am I going to handle this? I had some weeks so you if you have a time limit, you have to make choices... What Can I do in that few weeks etc. Then you start thinking. What am I going to put in my project? In my case, I start thinking like each house has lights so I am going to put some lights in it. I added also a sunscreen so when you are away from your house and the sun is shining that the it keeps a little bit cool inside. When your sunscreens move up and down, the thieves are going to think that you are at home. Then I start thinking further. When you hear music would je enter the house? You would think that there are some people inside. So I added a buzzer to get the music effect. For outside I work with lights that will automatically turn on when it is dark outside. When there is enough light, they will turn off. The code and how it works I will explain in the following steps.

Okay, now you have the electronic part. In my case I want to store also all the data so when a part turn off or on, when the sunscreens are upside or down, when the music plays and if the lights outside or inside are burning. For the last one you can think why are you doing this but then you know if you it still works. To store all my data, I used MySQL. I start drawning and thinking which table with which relation... In one of the following steps you can find the model that I made to store my data.

The last part where you have to think of, how can I make the visualisation so I see what is on or what is off. For this part I used HTML & CSS. I started to program first in Webstorm. After that I imported everything in flask because my HTML had to work with my python files with my code inside my raspberry PI. So I installed MySQL and flask on my Raspberry PI. How everthing works and how I made it, I will explain in the following steps.

Step 3: Cost Price

When you are looking at the cost price of it you would think wow this is a lot. Just keep in mind that I bought many things twice just to be sure if a component fails that I can replace it. Sometimes it could also be cheaper but I had a deadline that I had to reach. So I was not always looking to the low price stuff because with the low price stuff you have a long deliverable time.

Step 4: Electronic Circuits

Picture of Electronic Circuits

Requirements

- 4 LED’s *

- Active buzzer

- Stepper motor

- 5V Power Supply Module

- 4x 330 Ohm resistor

- 1 k Ohm resistor

- PNP transistor or BC 547 transistor (In my fritzing schema you I worked with a PNP transistor the most of you have them. If you don't have them like me, you can use BC547. The datasheet you can find here: Datasheet Datasheet BC547. For the people that don't understand the datasheet: collector is + side, emitter is - side, base is GPIO with resistor in between.)

- MCP 3008 (Want more information about the MCP 3008? Datasheet MCP 3008.

- LDR

- Stepper expander X1

- Jumper cables arduino/raspberry pi

* You can chose how many LED's you use. On my schema you see that I use 1 LED for ground floor and 1st floor. If you put more LED's parallel you can remote both with 1 GPIO pin. When they are in another room, you have to put them on another GPIO pin. You can choose and you have to see if you house is lighten up enough or not. It was just to illustrate the ammount of LED's. If they are in the same room, I would put them on.

GPIO pins

LED on the left side: 21

Middle LED: 24

LED on the right side: 18

Buzzer: 12

Stepper motor:

- Green (IN1): 19

- Yellow (IN2): 13

- Orange (IN3): 6

- Brown (IN4): 5

Step 5: Creating a Database

Picture of Creating a Database

Sorry guys but my database is made in Dutch. I will give an example like "zonnewering" is sunscreen and 1 sunscreen give more data. The table contact isn't connected with the rest. Contact will just store the data in the database that it receives and that's it. Don't forget to make a new user! I posted my dump file as well.

Step 6: Website HTML Templates

Picture of Website HTML Templates

In the attachment, you find a zip files called templates. This templates are the pages of the website with the content of the website. I didn't remove some code. Only the HTML code is not enought because now you don't have the style like on the pictures just the content. In the following step I will post the css that is linked on this HTML. At the end of my steps, there is also a full document with my HTML, CSS, Python, Javascript, Flask together. Don't forget to use them together! The reason why I put them here seperated is that you guys got a clear overview.

You will see also some code in between like picture number 1: {% if pins[17].state == true %} here I say if my GPIO that is on 17, his state is true. You click also "on /verlichting/17/off" then the icon will display where my light is burning. It is a toggle button that I illustrate here. So when you see the icon where the light is not burning, you will click on it to let it burn. Then the icon will switch. When you see an icon that is burning and you click then on it, the icon will switch again. The else stands for the reverse of the normal if.

To let everything work you need also the python file code to go to your path but that I will post on the end in my one big zip file.

Step 7: Website Static

In the attachment, you find my static files that you can connect with the HTML files. In the static folder you will find the folders: Images, css and js. The folder Images is contains of course the images that I used but it also contains 2 other folders. The two other folders are icons and logo. In the folder icons, you find the icons that I used. For example the lightIcon that I illustrated in my previous step. In the folder logo, you find the logo that I made with Photoshop. It is simple but clear.

The other folder that you find in the folder static is css. This is a very important folder. It contains all the style of my website. Like I said in my previous step, HTML is for the content and css is for the style. If you change a class name don't forget to change it also in my templates. If you don't do that, he wouldn't apply the style.

The last folder in static are my javascript files. One of the files is meant to do display the weather connected with your GPS. I work here with a key. The icons will also change with the weather. The wind direction I changed into Dutch because my full website is in Dutch so it was easier for me. The file jquery, I used to draw my graphics.

Step 8: Database Writing to It and Retrieving From It

Picture of Database Writing to It and Retrieving From It

In this python file, I have programmed everything to write information to my database and get some information. In the screenshot that I posted, you see that you have to fill in your data. My password I removed for security reasons. So you have to fill in the password of your database. "db:" stand for the name of your database. To get information from my database I wrote a query with "SELECT" and to write to my database I did with "INSERT INTO".

Step 9: Connection Between Website and Pi and Database

In my file project, you find all the GPIO pins that I have used. All my imports you can find there too. In this file you see with each path what I do with my database and how I put the connection with the electronic part.

Step 10: Code LDR

For my lights outside I use a LDR with a MCP 3008 and two LED's. For this, I didn't made a template because my LDR has to detect automatically if the sun is burning or not. My LDR will detect this and when it is dark outside, my LED's outside are going to shine. If it detects enough light from outside, the LED's wouldn't shine. Every time he detect this, he will write it to my database.

Step 11: Construction House

Picture of Construction House
  1. Sawing of wooden boards to size and shedding of the shelves
  2. Cut in the wood for windows
  3. Put the wooden boards together with nails and hinges
  4. Make a floor so that you see the difference between the ground floor and the 1st floor
  5. Place and occupy the roof
  6. Place the lights for the ground floor and the 1st floor. After that, don't forget to put also outside some lights.
  7. Place the hatch on the side, your house will be more accessible
  8. Put your breadboard on Double-sided adhesive tape
  9. Construction for sunscreens
  10. Place the frame for your stepper motor in house
  11. Put the sunscreens on the tube of the frame
  12. Laying grass
  13. Test everything now and enjoy your new home!

Step 12: Full Code

Like I promised, here you have the full code of my project! Enjoy and goodluck!

! Some notes:

  • If you go to "grafieken" (graphics) and you click on zonnewering (sunscreens) then you will see 100%. That is normal this graphic is made if you are going to use more sunscreens that you can compare which one goes the most on and off.
  • The template "wachtwoord vergeten" (forgot your password) is not in connection with the database. I had not enough time to do this.
  • My LDR is placed in the front of my door in the grass. It is possible that you don't see this.
  • Give your stepper motor enough place to rotate. When he is 5 v like mine, he is not that strong to work with a lot counter force.

Comments

Swansong (author)2017-07-04

Good instructable, thanks for sharing :)

About This Instructable

376views

3favorites

More by Arno Van Nieuwenhove:Raspberry Pi Domotica - SecuHome
Add instructable to: