Introduction: Smartroom Using Raspberry Pi
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.
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.
Step 1: Wiring
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.
Tip: draw your wires in a organized way otherwise it will look like spaghetti and you won’t know wich wire goes where.
Step 2: Database
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:
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
To check this you can simply try:
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.
Step 3: Setup
If you want to start coding you wil need to enable the Spi and i2c in your raspi-config.
Now you can go to the categories 1-Wire and Spi and both enable them.
Now we wil conect the pi with wifi.
First log in as root
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
Select the interface
Now reload the config
And now you can check if you are connected
Packages For the webserver to run the Site install Apache2
sudo apt install apache2 -y
Then go to python and install these packeges
Step 4: Code
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.
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:
Step 5: Case
For the case I used multiplex wood and I glued it togerther. but you can use whatever material you want.