Published © CC BY-NC-SA

Not-So-Smart-But-Very-Wholesome-Yet-Slightly-Creepy Mirror

In need of a mirror but not willing to add yet another smart object to your home? Then this project is just right for you!

BeginnerFull instructions provided16 hours1,249
Not-So-Smart-But-Very-Wholesome-Yet-Slightly-Creepy Mirror

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Adafruit USB Speaker
×1
Mirror
×1

Software apps and online services

Raspbian
Raspberry Pi Raspbian

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

A

CloseTag

D

E

H

OpenTag

Slash

Code

Mirror Code

Python
# Not-So-Smart-But-Very-Wholesome-Yet-Slightly-Creepy Mirror
# 8 Bits and a Byte, 2019
# https://projects.raspberrypi.org/en/projects/parent-detector/5

from gpiozero import MotionSensor
import time
import os
import json
from random import randint

pir = MotionSensor(4)

while True:
    pir.wait_for_motion()

    # Collect all the names of the audiofiles in our folder and the amount
    names = [name for name in os.listdir('/home/pi/Desktop/audio')]
    total = len([name for name in os.listdir('/home/pi/Desktop/audio')])

    # Generate a random number, -1 because our index starts at 0
    random = randint(0, total-1)
    print(total)

    # Fetch the name belonging to this random number
    name = '/home/pi/Desktop/audio/'+names[random]
    print(name)

    #Play the audio
    os.system('mpg123 ' + name)

    time.sleep(5)

Credits

Comments