Max Farrior
by Max Farrior

Categories

  • Magic Mirror

After building a larger Magic Mirror, I thought it would be very cool if the Magic Mirror application would normally be off, but turn on when somebody stands in front of it.

The Hardware

I found that somebody standing in front of the mirror could be accomplished using a Passive Infrared (PIR) sensor. I also found out that a PIR sensor made for DIY projects already exists, and it’s super-cheap too. The HC-SR501 sensor can be found for $5-6.

With the PIR sensor in hand, I set off to add this to my Magic Mirror.

The Software

I wanted motion to trigger the mirror coming on. This MM module is the de-facto module for use with a PIR sensor. But I wasn’t happy with how this looks visually. When motion is detected, the whole LCD is powered on. This prodes a blue “DVI” message on my LCD, and is quite sudden. Minor gripe, I know, but I wanted something more elegant.

So I decided to write my own module, using code from that module and some others.

I started with this module that allows everything on screen to be hidden. It was made to respond to the MMM-PIR-Sensor module. This is a great start, using these modules, I can use the PIR sensor to show and hide the MagicMirror application. (Without turning the LCD off/on.)

But what I really really wanted, was to have the modules fade in and then fade out. So I forked the mm-pir-hide-all module, so I could add the fading functionality. Luckily, I don’t need to reinvent the wheel, I found this module which is a fork of mm-pir-hide-all. This module implements the fade in / fade out, in response to the PIR sensor.

With all of that in place I created my own module, MMM-PIR-Fade-Hide-Mod, which ties all the functionality together. My module manages the LCD power separately from the module visibility. So the PIR sensor will just trigger the modules fade in. Once no motion has been detected, my module will then fade out the modules (while leaving the LCD on). And after another timeout, my module will turn off the LCD. If motion is detected while the LCD is on, but the modles are faded out, then the module will simply fade the modules in again. And if the LCD is off, and motion is detected, the LCD will first be turned on, and after a short delay, the modules will be faded in.