PIR Sensor for Smart Mirror: Motion-Activated Display

Project Overview

This project creates a smart mirror that displays information (time, weather, calendar) when someone approaches, and turns off the display when no one is present. The PIR sensor detects motion and triggers the display via Raspberry Pi. The two-way mirror makes the display invisible when off, giving it that “magic” look.

Difficulty: Advanced
Estimated time: 4-6 hours
Estimated cost: $100-150

How It Works

A PIR sensor mounted on the mirror frame detects when someone approaches. A Raspberry Pi runs MagicMirror software that displays information. When motion is detected, the Pi turns on the monitor (or wakes from sleep). After a period of no motion, it turns off the display to save energy and preserve the mirror effect.

Materials Needed

  • Raspberry Pi 4 (1) – Pi 3 works too, but slower
  • Monitor/LCD panel (19-24 inch, remove from old monitor or buy panel)
  • Two-way acrylic mirror sheet (cut to size)
  • Wood frame (to hold mirror and monitor)
  • HC-SR501 PIR sensor (1)
  • 5V relay module (to control monitor power)
  • Jumper wires
  • USB power for Pi (5V 3A)
  • Power strip (for monitor and Pi)

Smart Mirror Construction

  1. Remove monitor bezel: Carefully disassemble the monitor, removing the plastic casing. Keep the LCD panel and controller board.
  2. Build frame: Build a wooden frame slightly larger than the LCD panel.
  3. Mount LCD: Secure LCD panel inside frame.
  4. Install two-way mirror: Place acrylic mirror sheet over LCD, shiny side facing out.
  5. Mount electronics: Secure Raspberry Pi and power strip behind mirror.
  6. Add PIR sensor: Drill small hole in frame, mount sensor at bottom or top edge.

Circuit Diagram

Connection Table

Raspberry Pi Setup

  1. Install Raspberry Pi OS (Lite recommended).
  2. Install MagicMirror² software:
    git clone https://github.com/MichMich/MagicMirror
    cd MagicMirror
    npm install
    npm start
  3. Configure MagicMirror modules (weather, calendar, etc.) in config.js.
  4. Set up autostart on boot.

Python Script for Motion Detection

#!/usr/bin/env python3
# Smart Mirror Motion Detection
import RPi.GPIO as GPIO
import subprocess
import time

PIR_PIN = 4
RELAY_PIN = 17

GPIO.setmode(GPIO.BCM)
GPIO.setup(PIR_PIN, GPIO.IN)
GPIO.setup(RELAY_PIN, GPIO.OUT)
GPIO.output(RELAY_PIN, GPIO.LOW)

# Track display state
display_on = False
last_motion = 0
TIMEOUT = 60  # seconds

def monitor_on():
    global display_on
    if not display_on:
        GPIO.output(RELAY_PIN, GPIO.HIGH)
        display_on = True
        # Send command to wake display (if HDMI)
        subprocess.run(['vcgencmd', 'display_power', '1'])
        print("Display ON")

def monitor_off():
    global display_on
    if display_on:
        GPIO.output(RELAY_PIN, GPIO.LOW)
        display_on = False
        subprocess.run(['vcgencmd', 'display_power', '0'])
        print("Display OFF")

print("Smart Mirror Motion Detection Started")

try:
    while True:
        motion = GPIO.input(PIR_PIN)
        if motion:
            last_motion = time.time()
            monitor_on()
        
        if display_on and (time.time() - last_motion > TIMEOUT):
            monitor_off()
        
        time.sleep(0.5)

except KeyboardInterrupt:
    monitor_off()
    GPIO.cleanup()

Auto-start Configuration

Add to /etc/rc.local:

python3 /home/pi/mirror/motion.py &
cd /home/pi/MagicMirror && npm start &

MagicMirror Configuration Example

// config.js
let config = {
  address: "0.0.0.0",
  port: 8080,
  modules: [
    {
      module: "clock",
      position: "top_center"
    },
    {
      module: "weather",
      position: "top_right",
      config: {
        location: "YourCity",
        apiKey: "YourAPIKey"
      }
    },
    {
      module: "calendar",
      position: "bottom_left",
      config: {
        calendars: [
          {
            url: "https://calendar.google.com/calendar/ical/..."
          }
        ]
      }
    },
    {
      module: "newsfeed",
      position: "bottom_right",
      config: {
        feeds: [
          {
            title: "News",
            url: "https://feeds.bbci.co.uk/news/rss.xml"
          }
        ]
      }
    }
  ]
};

module.exports = config;

Installation Steps

  1. Build mirror frame: Assemble wooden frame with LCD and two-way mirror.
  2. Mount Raspberry Pi: Secure behind mirror.
  3. Install PIR sensor: Mount on frame edge, facing outward.
  4. Connect relay: Wire relay to control monitor power.
  5. Install software: Set up Raspberry Pi OS, MagicMirror, and motion script.
  6. Test: Approach mirror, verify display turns on. Wait 60 seconds, verify display turns off.
  7. Fine-tune: Adjust timeout in script as desired.

Project Extensions

  • Voice control: Add microphone for voice commands.
  • Facial recognition: Add camera to show personalized information.
  • Touch interface: Add touch overlay for interactive features.
  • Temperature/humidity: Add DHT22 to display room conditions.
  • Security camera feed: Display doorbell camera when motion detected.
  • Music control: Add Spotify integration to display now playing.

Troubleshooting

  • Display not turning on: Check relay wiring. Test with manual command.
  • PIR not detecting: Adjust sensitivity. Ensure sensor not blocked.
  • Display stays on: Check motion detection. Increase timeout if too sensitive.
  • MagicMirror not starting: Check config.js syntax. Review logs.
  • Mirror reflection poor: Ensure two-way mirror is oriented correctly (shiny side out).

Conclusion

This smart mirror combines functionality and style, displaying useful information only when you need it. The PIR sensor makes it energy-efficient and maintains the magic mirror effect when not in use.

Leave a Reply

Your email address will not be published. Required fields are marked *

Component Pin Raspberry Pi GPIO
PIR Sensor OUT GPIO 4 Relay Module IN GPIO 17