Introduction: SmartMirror With Backlighting
After a long process of thinking I came to the conclusion to build a smart mirror. I have the habit of having an irregular sleep schedule so I wanted this mirror to help and log my waking hours etc. I wanted to keep it simple and implement 3 sensors and ofcourse the backlighting.
I will take you through the process of building my idea.
- One Wire Temperature sensor (DS18S20)
- DHT11 Humidity & Temperature sensor
- Infrared motion sensor
- Raspberry Pi 3
- Two way acrylic mirror.
- Computer monitor
- Wood planks
- Led strip
- LED strip 120LED/m 5050
- HDMI Cable
- Mosfets IRFZ44N
- SD card
- 4,7K, 1K, 2K Resistors
Step 1: Wiring
This is the wiring with the needed sensors and resistors. We need a 12V powerjack to use this on the breadboard. In this scheme this is on the same breadboard but in reality it is safer to do this on seperate breadboard.
Step 2: Database
The database can store the data of the 2 sensors that deliver the data. It has an unique ID to identify the measurement together with the value and sensorID. The time of the measurement is also stored. The sensors have an foreign table to identify them in their parent table.
We will need to upload this database to the pi but first we have to install MariaDB.
sudo apt install mariadb-server
Just press enter. Then Y and enter password 2 times.
Just press Y for the whole process.
mysql -u root -p
Enter your password for connection.
Then upload the database to the PI and you are good to go.
You can find my SQL database under here.
Step 3: Mirror Building
I used MDF wood to create this mirror. I first created a square to put the mirror on and another square to put the monitor and electronics behind. I attached the mirror with insulation so it could not move anymore. I used woodglue to glue the 2 woos squares together.
I drilled a hole to put the LED strip through to attach it to the side of the mirror. The LED strip is attached with isolation tape.
I painted the mirror for a nice finish. It also blends okay with the tape.
I attached the monitor with 2 way strong tape. Fortunately this was a mistake because you can see the white tape through the mirror. I taped the rest of the back of the mirror with black tape so light could not pass through.
I glued the breadboards and pi to the back of the monitor.
Step 4: Code
I used a lot of sockets for the live data on my website and a couple of fetches for the measurements each day. When the mirror is running it will display the sensor values on that moment and the local time.
You can find my code here: GitHub Repository
Step 5: Running Mirror on the PI
To rotate the screen to hang it sideways you need to navigate to:
sudo nano /boot/config.txt
and add the following line at the bottom:
Installing apache webserver:
sudo apt install apache2 -y
Upload all frontend files to /var/www/html/ with filezilla and it will run on the sebserver.
Autorun the backend in rc.local:
sudo nano /etc/rc.local
Add the following line of code before 'exit 0' but use the location of your backend file:
sudo python /home/gilles/mirror.py
Now the PI is running the webserver and backend on startup.
Run mirror page
Now we want the pi to run the html page of the localhost in fullscreen (our mirror page)
create a script in your wanted path with this code:
DISPLAY=:0 chromium --noerrdialogs --kiosk http://localhost/mirror.html --incognito
Now save the file and navigate to:
sudo nano lxsession/LXDE-pi/autostart
then insert this line of code at the bottom:
The mirror will now automatically run on startup and you will see your own smart mirror!
Just surf to the IP address on the screen and you can access the website on your phone, laptop...