Smartroom Using Raspberry Pi

by RubenRoose in Workshop > Home Improvement

219 Views, 0 Favorites, 0 Comments

Smartroom Using Raspberry Pi

64457900_372256900307827_104292070918717440_n.jpg
64515318_2010004299111918_1663688713483321344_n.jpg

For my project I made a Smartroom for Hospitals. Now you can ask me why did you choose this idea? well my mom was really sick this year and she could not do much around the house so she stayed in bed most of the time and I thought that for my project I should find a why to make her live a bit easier.

Supplies

For this project you will need severel things:

  • 1 DHT11 sensor (temperature and humidity sensor)
  • 1 HC-SR04 sensor (distance reader)
  • 2 servo motors
  • 1 LDR
  • 1 16x2 LCD display
  • 1 Rasberry Pi 3 Model B+
  • 1 microSD card (min. 16G)
  • 1 220 Ohm resistor
  • 1 330 Ohm resistor
  • 2 packs of jumperwires
  • 1 breadboard Wood

If you get all of this you will pay around €100.

Wiring

1NMCT3-ruben_roose-schakeling-breadboard.png
1NMCT3-ruben_roose-schakeling-schema_schem.png
64255919_2342577606004426_108078054525370368_n.jpg

First we are going to wire ower electonics so you have the basics of your project.

Download Fritzing and draw a circuit. this way it’s easier to see which GPIO pins you will use on your Rasberry Pi.

Fritzing: http://fritzing.org/download/

Tip: draw your wires in a organized way otherwise it will look like spaghetti and you won’t know wich wire goes where.

Database

data.PNG

Make a database model using MYSQL workbench. If that is done forward engineer your model. If that worked than you have made a database in MYSQL.

Now we will put the database in you Rasberry Pi

The first stap you take is to check if your Pi is up to date. You can use the following command:

sudo apt-get update
sudo apt-get upgrade

Now install the Mysql server:

sudo apt-get install mysql-server

Then Install the Mysql client

sudo apt-get install mysql-client

Now look at the sql server by the command:

sudo mysql

You can now import your database code by opening the .mwb file with the sql workbench and forward engineer. You copy the code and paste this in the mysql from the Raspberry. The database is made.

For the user to get all the permissions, just add your username in the table

grant all privileges on smarthome.* to ‘yourname’@’%’ identified by ‘yourname’;

Now you need to refresh the table now

FLUSH PRIVILEGES;

To check this you can simply try:

use smartroom;
select * from Historiek;

In Sensor table you can find all the active sensors with their id. The Historiek table shows the date and time, values and the sensorID.

Downloads

Setup

Interfaces

If you want to start coding you wil need to enable the Spi and i2c in your raspi-config.

sudo raspi-config

Now you can go to the categories 1-Wire and Spi and both enable them.

Wifi

Now we wil conect the pi with wifi.

First log in as root

sudo-i<br>

Then fill in the name and password of your wifi network

wpa_passphrase=”wifiname” “password” >> /etc/wpa_supplicant/wpa_supplicant.conf 

Then enter the WPA client

wpa_cli 

Select the interface

interface wlan0 

Now reload the config

reconfigure

And now you can check if you are connected

ip a

Packages For the webserver to run the Site install Apache2

sudo apt install apache2 -y

Then go to python and install these packeges

  • Flask
  • Flask-Cors
  • Flask-MySQL
  • Flask-SocketIO
  • PyMySQL
  • Python-socketIO
  • requests
  • pip
  • gpio
  • time
  • Adafruit_DHT

Code

smart.PNG

Backend

For the backend, I wrote my python code in pycharm. I used multithreading to make the code run on the background so it can work together with other code.


Frontend

On the frontend there are a two buttons who can open the curtain and bathroomdoor. there is also live data so you can see the Temperature and the Humidity.

use the code on github:

https://github.com/Rubenroose/smartroom.git

Case

64402224_2594895460522555_5575497591845552128_n.jpg
64515318_2010004299111918_1663688713483321344_n.jpg
64579276_2467471313518907_6513115229172269056_n.jpg
64457900_372256900307827_104292070918717440_n.jpg

For the case I used multiplex wood and I glued it togerther. but you can use whatever material you want.