Introduction: Basic Room Automation
Hi
for my school project I made a mini home automation system. This could be used for people who work in the office all the time and forget to regulate the lighting, open the window or cool the room when its to hot. I’ve been that guy to many times while I play games or work for school. I just need to make this for my room in real life and I’m good to go! For now it’s just for my friend ‘Anthony’, a play mobile figure…
What :
A mini home automation system that regulates temperature, lighting and air quality for us hard working office people. It works automatic but you regulate everything on the website.
Why :
As I mentioned before, I made this for a school project. It’s something I would love in real life so maybe one day I can build it for my room who knows…
Attachments
Supplies
The following items are required to make this project. You dont need to order everything from the linked sites, this is just where I got it.
(In the attachement you can find the same list, just a bit cleaner and with prices.)
- 1 x https://www.gotron.be/raspberry-pi-4-b-4gb-ram.ht...
- 1 x https://www.gotron.be/arduino-uno-rv3-programmeer...
- 1 x https://www.gotron.be/ldr-photoresistor-100mw-50-...
- 1 x https://www.gotron.be/temperatuur-sensor-9-12-bit...
- 1 x https://www.gotron.be/sparkfun-air-quality-breako...
- 1 x https://www.gotron.be/pir-motion-sensor.html
- 1 x https://www.gotron.be/analog-micro-servo-1-3kg-cm...
- 1 x https://www.gotron.be/dc-motor-6vdc-250ma-14500tp...
- 1 x https://www.gotron.be/propeller-fan-voor-dc-motor...
- 1 x https://www.gotron.be/voedingsmodule-voor-breadbo...
- 1 x https://www.gotron.be/5v-relaismodule-compatibel-...
- 1 x https://www.gotron.be/10bit-ser-adc-8ch-spi-dip16...
- 1 x https://www.gotron.be/lcd-2x16-characters-led-bac...
- 1 x https://www.gotron.be/componenten/actief/dioden/d...
- 1 x https://www.gotron.be/printplaat-100x160-3-gaten-...
- 1 x 1k ohm resistor
- 2 x 10k ohm resistor
- 6 x 220 ohm resistor
- 6 x https://www.gotron.be/led-5mm-9000mcd-wit-20-wate...
- To many wires
- Green MDF or any other type of wood
- Quite some glue
- 200 cl paint for MDF, any color you want.
Step 1: The Case
In the files you you find all the sizes you need to create the sperate wood or mdf panels. I used a CNC machine to make the holes. Using that machine is not a must! You can use more basic tools and achieve a simular result.
The pieces are made to nicely fit in each other so with some glue you can put them all togheter.
Note that the "fake" inner wall is not glued so I can take it out, same for the "fake" ceiling, the outer piece of the "fake" wall and the ceiling itself. We will need to acces the fake ceiling and fake wall later when we put in the electronics.
Next you can paint the box if you wish to do so. I used white paint but it can be any color you want.
Attachments
Step 2: Electronics
Please use the fritzing breadboard file when you make the circuit. I suggest that you use the same pins as me or you could be in some trouble. Since we already made the box there is no need to make a "test" circuit, you can build it in 1 of 3 ways listed below.
There are multiple ways of putting this circuit in the box.
The "lazy" way:
- You can fit the breadboards between the fake wall and the actual wall then use longer wires to reach the sensors on top.
The "more professional" way:
- You can do like me and make a pcb where you solder everything on it so it's a bit more professional
The "this is for my job" way:
- You still need a pcb you you order one where the wires are part of the pcb so you just need to solder the components and some wires to reach the top of the box.
Attachments
Step 3: Setting Up the PI
For those who have never coded on a Pi yet, you first need to set it up.
This link will show you how to work remotely using ssh.
Link: https://code.visualstudio.com/docs/remote/ssh
This link will show you how to setup the databaseserver
Link: https://www.youtube.com/watch?v=lCfSKtPADYw&list=WL&index=2&t=0s
Then you will want to install some packages, select the folder you had to create using the guide and open a terminal.
You need to install:
pip3 install mysql-connector-python
pip3 install flask-socketio
pip3 install flask-cors
pip3 install gevent
pip3 install gevent-websocket
Step 4: Connecting MySQl
Once you have opend MySQl workbench you need to make a new connection.
The connection should look like the picture above.
- Obviously you name it to whatever you like, I named it "Raspi"
- Then you set the connection method to "Standard TCP/IP over ssh", THIS IS VERY IMPORTANT
- The ssh hostname is just the IP address of your PI
- Ssh username is the user of your pi
- Mysql hostname does not need to change
- The port doesn't need to be changed either
- Username should be your workbench username.
Link to mysql workbench: https://www.mysql.com/products/workbench/
Step 5: the Code
In the repository you'll find the nessessary code.
Note that you need arduino aswell, the code for reading the air quality is written in arduino.
Github: https://github.com/howest-mct/1920-1mct-project1-...
Library for the air quality sensor: https://learn.sparkfun.com/tutorials/ccs811-air-quality-breakout-hookup-guide?_ga=2.161258877.1738033366.1590667992-683882317.1590159462
Just placing all the files in visual studio code is probably not going to work.
First you'll need to check if:
- Serial communication is activated on your PI
- SPI is activated on your PI
- One wire is activated on your pi
Then you can place the backend code where ever you like on your pi but the "html" folder needs to be in /var/www.
Feel free to change the code and improve the project.
Step 6: The Database
To save the data and to be able to use the system you need this MySQL database.
I used Maria DB as database management system on my Raspberry Pi (https://mariadb.org/).
If you don't understand the database, you can read the "DB help" and hopefully understand everything.
The data in the database should be left there. This is for the devices, without this data the system will not work.
Attachments
Step 7: Step 5 Testing the Program
In order to be able to test if everything works, you will first need to plug in your PI, and the power supply. It is absolutely necessary to have a 3.3V and 5V power supply. If you miss 1 of them the project is not going to work.
To get to the website you just need to google the IP-adress of you PI.
Then you can register, log in and explore.