Introduction: How to Build a Raspberry Pi Smart Mirror!
For my computer science final project, I decided to build a Smart Mirror powered by a Raspberry Pi 3! I got this idea from Hacker House, an awesome Youtube channel that has a lot of interesting ideas for creative projects that incorporate easy to follow instructions! Though I mostly focus on coding in Java, this Smart Mirror allowed me to work a Raspberry Pi by coding in Linux and Python, languages I had never used before. As well, I got to do some interesting woodworking by building the frame around the monitor, located behind the two way mirror. Though this was my very first Raspberry Pi project, it took me around two weekends to complete, from coding of the Pi to painting the frame. It was an amazing experience to build this and I hope this tutorial helps you create your own!
Step 1: What You Will Need
Before you begin, here is a list of all the required items for the project:
- Raspberry Pi (I used the Raspberry Pi 3 Model B version, due to the fact it has easy accessibility and an easy to set up wireless option)
- Monitor (I used a 12" X 20" Samsung monitor with a HDMI input)
- Two Way Acrylic Glass Mirror (There are some online, however I used the cheaper one Hacker House recommended - see link at bottom)
- 4 x 3D Printed Brackets (These aren't necessary, however they make it easier to house the frame. Again, Hacker House has a website that supplies the STL and zip files for the design of the brackets - see link at bottom)
- HDMI Cable
- Micro HDMI Cable for Pi Power Supply
- Wood Glue
- Wood (I used two 8ft long pieces (a 1" x 3" and a 1" x 4" ) to cut the inner and outer frame)
- Keyboard (USB)
- Mouse (USB)
3D Brackets ~
Two Way Mirror ~
Step 2: Setting Up the Raspberry Pi
In order for the Pi to receive information from the Magic Mirror modules found online, it is crucial to set up your Wi-Fi and time zone. Once the operating system "Raspbian" is installed (I used the "Jessie" version) on your micro SD card, plug in your keyboard and mouse to the Pi and attach the HDMI cable to the monitor you are going to use. Wait for the system to boot up, then you can begin configuring the Pi to your location. First, click the Wi-Fi symbol in the top right of the screen. Choose your internet and enter your password. You should then be connected to your Wi-Fi. Once you have done that, access your terminal and type the following:
sudo dpkg-reconfigure tzdata
You can then begin to access your specific time-zone through the menu the Pi displays. Once you have chosen your correct time-zone, save and reboot your Pi. At this point, the Magic Mirror can use your location to display the time and access information from the internet using your Wi-Fi. Now, you can begin programming!
Step 3: Magic Mirror 2
Before you start downloading and configuring the program, you should probably know how this program works. MagicMirror is a downloadable platform created by Michael Teeuw (a.k.a MichMich), where one can access this repository on www.github.com. Using the Pi, you must download and clone the repository, along with its dependencies. By doing this, the Pi is able to run the program and display certain elements contained in the MagicMirror file. For further explanation, you can visit https://magicmirror.builders/, an online forum with tons of useful modules and troubleshooting methods for anyone coding the program. To start, access your terminal and type the following code:
bash -c "$(curl -sL https://raw.githubusercontent.com/MichMich/MagicMirror/master/installers/raspberry.sh)"
When you hit enter, the Pi will begin the automatic download of the repository, which takes around 10 - 15 min. Along the way, you will be prompted to enter "Y" or "N" for certain dependencies, such as vim. Vim is a crucial dependency that allows a text editor to manage the MagicMirror. As well, a program called pm2 will be downloaded, which automatically runs the program when your Pi boots up. Another prompt will be Node.js, which allows network applications to run on the Pi. Once MagicMirror has been fully downloaded, reboot your Pi. After the reboot, you should see a compliment, the time, and news articles (see above photo). From this point, you can begin to customize the program (add new modules, orientation, change fonts, etc).
Step 4: Modules
As shown before, MagicMirror should automatically display the time, a compliment, U.S holidays and some news articles. However, I wanted to add some features to the Pi to make it more aesthetically pleasing and have more information I could access (for ex: weather, weather forecast, a cool quote, etc). To do this, there are multiple things you must do in order for MagicMirror to receive information about the location you are in. To do this, you must access the modules folder. This folder is the key to housing all the desired options you want for MagicMirror. You can add modules, delete modules (I deleted the U.S holiday list because I live in Canada), and customize the settings. To do this, access the terminal and type:
This should open a file where you can see the module list (look for closed brackets with information in it). I started by adding the weather and weather forecast module. You should already see default modules with weather options, but you will notice that two important keys are missing. The location ID and the API ID. As stated before, MagicMirror uses online sources to display the information. These two ID's come from a website called OpenWeatherMap (see link at bottom). This site supplies API's for weather, which this module needs. First, sign up for free on the site and access your free API. Type this code in the "appid" section of the module. Then, you will need to find your city/town's location ID. OpenWeatherMap supplies a HUGE file with nearly every city in the world and its location ID beside it. I am not aware of an easier method, but you may have to scroll through the whole file until you find your city/town's ID. Once that has been found (this part seriously sucks, it took me around 20 minutes to find my city's ID), enter it into the weather and weather forecast module. After, save and exit. When your Pi boots up, you should see your city's weather. I added an additional module, where an inspiring quote is displayed at the bottom of the screen (see above photo). However, the module list is completely up to you! Make sure to check out the module webpage the MagicMirror2 forum provides on it's site! There are some really cool modules anyone can add to make their mirror a lot more interesting and fun!
Step 5: Customization
This step is entirely up to you, depending on if you want mirror to appear in a portrait perspective rather than landscape. In order to customize the Pi so it is rotated (see last photo), access the terminal and type the following:
sudo nano /boot/config.txt
This will open certain system preferences, where you can add the "rotate screen option". To do this, scroll to the bottom of the file and add:
Save and exit. When you reboot your Pi, MagicMirror should start up and displayed horizontally. As well, you should see all the modules you have added portrayed in portrait perspective. One other thing you should add to customize your Pi is pm2 startup. After installing pm2, I found that MagicMirror would not start up unless I accessed the terminal and typed in a few lines of code. To eliminate this problem, do the following:
Access the terminal and type: pm2 startup
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u pi --hp /home/pi
After, access a script by typing:
DISPLAY=:0 npm start
Save and exit. Now, when your Pi starts up, MagicMirror should automatically start
It was also hard to find how to disable the screensaver, just because you want to continually see the display behind the mirror. To do this, you will need to access the terminal and type:
sudo nano /boot/config.txt
Save and exit, then access another file in the terminal by typing:
sudo nano ~/.config/lxsession/LXDE-pi/autostart
@xset s 0 0
@xset s nonblank
@xset s noexpose
@xset dpms 0 0 0
Save and exit, then reboot your Pi
Step 6: The Frame
Though the frame is relatively easy to build, there are a few crucial things you have to do in order to prepare. First off, dealing with the two way mirror. Depending on the size of your monitor, you will likely need to cut the mirror to size around a half an inch larger (width and length wise) than the monitor. To do this, measure and mark the size on the mirror (I used a Sharpie - don't worry! There is a protective plastic layer on the frame you peel off when ready) and put some tape on the line. I used painters tape, just because it isn't super strong and can come off easily. Cut CAREFULLY along the tape (you will notice that the mirror shatters on the edge as you cut. Try to limit these breaks, as these cracks can damage the lifespan of your mirror). Once the mirror is cut to size, you can begin to make the frame. With the frame, you will need to make two portions. The inner housing and the outer frame. To do this, measure the monitor and cut the two wood pieces around 1.5 inches larger than the monitors length (see above photo). After, cut another two pieces that fit in between the larger pieces. Use wood glue and clamps to set it. To speed up the process, you can drill a screw at the corners to hold it together better. To make the outer frame (see second photo), cut four pieces with 45 degree cuts at each end (remember, when you place the outer frame on the inner housing, you should place it so the halfway point on the 45 cut rests on the housing). Once the frame has been set and is stable, sandwich your mirror between the frame and the monitor. Screw in your 3D brackets, making sure they are firmly placed. At this point, you can plug in your Pi and your power supply, and MagicMirror should start up. You should see a display behind the mirror (date, time, whatever you put on the program). Congratulations, you now have your very own Smart Mirror!
Step 7: Wrap Up
If you have any questions, please leave a comment! I would love to help out with any issues or ideas that you have! This was an amazing project to take part in, all thanks to Hacker House! One thing I would like to point out is that I highly recommend you buy a heat sink for the Pi. Since this program is designed to continually run, your processor will get incredibly hot. Buying a heat sink will allow your Smart Mirror to run more safely, as well it will alleviate any stress the Pi undergoes as it runs. I hope you give this project a try, it can be really useful and is an interesting aesthetic you can hang up in any room. Thank you so much for visiting my page, hopefully I will add some cool modules to the mirror that I can help you guys with (AI, motion sensor, alarm, etc).