Sunday, September 3, 2017

Building a smart mirror

In this article, I will tell you about my summer project 2017: Building a smart mirror.




What is a smart mirror?


A mirror shows just a reflection of what ever is in front of it, while a monitor on the other side can show information, regardless of what kind they are. A smart mirror finally tries to combine both of them, showing the reflection of objects or persons in front of them and information at the same time.
The idea of a smart mirror is nothing new. It is shown in some science fiction movies and shows. Also since a few years, more and more projects, startups and companies showing up offering different kinds of smart mirrors or offering building kits.


What was my intention?


I was looking for a project to do something with a Raspberry Pi for a while as I wanted to get to know this neat little computer. At some point, I just discovered a project report of Hacker House at YouTube where they build up their own smart mirror with a Raspberry Pi. They were also building the frame them self so it seemed perfect to fit for what I was looking for.


Also, another reason to go for this project was, that my wife was asking for a mirror in our hall for a few years now, we just never found something we were satisfied with.

The hardware


First, I had to gather all the components required:
  • Raspberry Pi
  • A monitor
  • The frame
  • The mirror glass
  • Some cables

Raspberry Pi


Well, I needed one of this little computers from the UK, that are in everyone's mound since a few years. I ordered one from Amazon and started to watch and read some tutorials about it. 
I went for the latest version, the Raspberry Pi 3 B, which costs about 35 € at Amazon.


I also ordered a case and a micro SD-Card which is needed as well, for about 15 € in total. Further on, a USB keyboard and mouse are needed as well.

When it arrived, I started playing around with it. Also, I noticed, that the monitor should have an HDMI port to make things easier.


Basically, a Raspberry Pi is a very compact little computer with all necessary modules and connection ports attached to it. There are also pins to further extend its functionality which I will utilize in an already planned further step of my project.

The monitor


First, I was looking for a cheap monitor to build the project. This step was essential as the size of frame and mirror glass are dependent on the monitor size.
After looking a while, I reconsidered by taking one of my old PC monitors with an HDMI port and replacing my working monitor by a better (larger and sharper) one.

Regardless, as the monitor does not need to be new or high quality, any used one will do. The costs might be around 30 € to 50 €, depending on the size wanted.

I also decided to use only the internals of the monitor, the display itself and the controller board.


Later on, I covered the front of the display with black electric tape to protect the glass of the mirror where it would get pressed against and to avoid reflections of the metal frame behind the mirror glass. 

I was breaking out the controller element for the screen off the front frame as well, relocating it to the back side of the display. This way I am still able to access the monitor onscreen settings to change input channel, brightness and so on.



The mirror glass


But why can a screen behind a mirror be seen at all?
Well, the special trick at a device like this is the kind of mirror glass to be used. Normal mirrors are silver plated at the back, reflecting all (or huge chunks of) the light that falls on it from the front back. A screen behind this kind of mirror could not be seen at all.

But there are other kinds of mirrors. Just think of the mirrors in crime movies and TV shows. They are kinda transparent from one side and reflective on the other side. This mirror glass is also called spy glass.
This kind of mirror works with a layer in between two glass plates. The mirror then works the way, that watching from the side with more light the reflection is seen while looking from the darker side the mirror is kinda transparent.
That's the way how the mirror shows the white (light) parts of the screen while at the more dark areas only the mirror image is to see. So that means, the monitor behind the glass needs to be as dark as possible in large areas and only show information in white where it should shine through.

We tested out a version of foil at an acrylic glass plate first but didn't like the result. So for our final version, we ordered one by myspiegel.de, fitting to the size of the display to be used in this project. Of course, this version was a bit more expensive, but we got a high-quality spy glass mirror plate which can be cleaned without worrying about the foil or acrylic at all.

The wooden frame


Like mentioned before, the frame size is dependent on the size of the screen and glass plate. So as this was set, we started to plan the frame.

My father was kindly taking over the wood works as he got some tools and space for it which I am missing. I made a plan of what I wanted to get. Basically a frame box for the whole screen and the glass plate as well as the Raspberry and all the cables. On the front another cover frame which the glass plate should be laying against.


After a few more telephone calls and some tries, my father made a fantastic frame for us and sent us a few pictures.
Huge thanks at this point, Rainer. ;-)



The software


While my father was working at the frame, I was focusing to get the software side done. After setting up the Raspberry Pi, installing the operating system Raspbian, a Linux version for the Raspberry and some basic settings like WiFi I was turning towards the actual software to show some information in the mirror.
There are plenty of tutorials available on the web in written or video form about how to set up and configure a Raspberry Pi so I will not go into detail here.


For that step, I was cloning the GitHub project by Hacker House which was written in Python and started working from that.
There have been a few basic settings to be made like what time format I wanted, the country where I wanted to see the news from as well as some settings for the weather information. For the weather, I was creating a key at DarkSky.net to get the weather information I needed. The basic weather feature in the Python script by Hacker House was taking the IP to decide which weather information to show. This was not working for me as it only takes the public IP in consideration which was shown by my provider so I was searching the script for an alternative which I found in providing the Geo coordinates directly instead of an IP. So looking up the Geo coordinates of Nürnberg and providing them in the script and there we go, we got weather information.


Later on, I was also switching the news lines at the bottom of the screen a bit as in the original script, the presentation was a bit screwed up when the headlines were too long.

At the Raspberry Pi itself, a few settings had to be made as well, like getting the display in portrait mode. This was done very easily by adding a line to the config.txt file in the boot folder.

Merging all together


Finally, as all the parts were done, we could merge them all together. Our biggest concern was if the glass and screen would fit into the frame, but everything fit perfectly.

First, we placed the frame face down on a flat surface, inserted the mirror glass in it, then the display on top of that. As everything was in place, we secured the pieces by some wooden ledges at the inside of the frame, using some screws at the two long sides.



After the "big" parts, the brain had to be installed as well of course.
Just using some double sided tape to lock the Raspberry Pi in place on the back of the display. Connecting it with a short HDMI cable to the display controller and with a USB cable to power.


Further on, a USB hub was connected and placed outside of the frame so a keyboard and mouse can be connected easily.
The USB hub had to be taken apart and rearranged a bit as well as it was too large to fit behind the cover. Using double sided tape again to fixate it at the bottom of the mirror behind the cover.



Now, for the first time, the smart mirror was assembled all together.

Next, we had to install the wall mount. As the mirror glass and the screen add some weight to the wooden frame, it had to be a stable construction. As you can see in the following picture, we were using a wedge mount to hold that weight securely on the wall. Also, this construction enables us to remove it very easily if we need to access the back side for further expansions.


To make the imagination of a simple mirror perfect, we decided to drill a hole into the wall and get power from the room behind. This way there is no wire to see leading to the mirror when mounted on the wall.


Finally, connecting the power and setting it up on the wall, it looked quite good in my opinion. ;-)


The costs


Of course, a project like this does have some costs. How much highly depends on what is already available or has to be bought. See the list below for a bit of a direction of what all the components cost:

  • Raspberry Pi: 35 €
  • Case for the Raspberry Pi and micro SD-Card: 15 €
  • A monitor: ~ 30-50 €
  • Cables (HDMI, corner plug, power supply): around 25 €
  • USB hub: 5 €
  • Keyboard + Mouse: 15 €
  • Wood for the frame: 25 €
  • The mirror glass: 75 €
Total: Around 200 € to 245 €

Conclusion


This has been a very exciting project to me. Sure, it was not cheap but I have learned a lot about Raspberry Pi, Python, the link between hardware and software and much more.
The project was a lot of fun and it is extremely satisfying to see it finally on the wall, working as intended. Further on, the project is not finished here by far. Actually, I will continue to work at it, extending it by new functions, new hardware, and more software so it will become a real smart home project. Work at some expansions to the original smart mirror project has begun already ...


Again, great thanks to all who contributed to this project, my wife, and my father directly, but also all who were providing information on the web about the things I used in that project. Maybe this article will help others to achieve something similar as well.