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.

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. After a period of no motion, it turns off the display.

Materials Needed

  • Raspberry Pi 4 (1)
  • Monitor/LCD panel (19-24 inch)
  • 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, keeping LCD panel and controller board
  2. Build wooden frame slightly larger than LCD panel
  3. Secure LCD panel inside frame
  4. Place acrylic mirror sheet over LCD, shiny side facing out
  5. Secure Raspberry Pi and power strip behind mirror
  6. Drill small hole in frame and mount PIR sensor at bottom edge

Circuit Diagram

Connection Table

OUT

GPIO 4

IN

GPIO 17

Raspberry Pi Setup

  1. Install Raspberry Pi OS Lite
  2. Install MagicMirror²: git clone https://github.com/MichMich/MagicMirror
  3. Configure MagicMirror modules in config.js
  4. Set up autostart on boot

Python Script for Motion Detection

#!/usr/bin/env python3
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)

display_on = False
last_motion = 0
TIMEOUT = 60

def monitor_on():
    global display_on
    if not display_on:
        GPIO.output(RELAY_PIN, GPIO.HIGH)
        subprocess.run(['vcgencmd', 'display_power', '1'])
        display_on = True

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

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()

Installation Steps

  1. Build mirror frame with LCD and two-way mirror
  2. Mount Raspberry Pi behind mirror
  3. Install PIR sensor on frame edge
  4. Connect relay to control monitor power
  5. Install software and motion script
  6. Approach mirror to test display activation
  7. Adjust timeout in script as desired

Project Extensions

  • Add microphone for voice commands
  • Add camera for facial recognition
  • Add touch overlay for interactive features
  • Add DHT22 to display room conditions
  • Display doorbell camera when motion detected

Conclusion

This smart mirror combines functionality and style, displaying useful information only when you need it with PIR activation.

Leave a Reply

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

Component Pin Raspberry Pi GPIO
PIR Sensor Relay Module