How to: Install a PIR motion sensor on your Raspberry Pi Magic Mirror

Some people don’t want their magic mirror to be constantly on, for example during the night or when no one’s home. There is an easy solution to this, just install a PIR sensor!

You will need a PIR sensor, they are really cheap online, here are a couple of options:

So let’s get down to how to set this up..

1. Hook up the PIR module to your Raspberry Pi

This is pretty easy, you connect three Female/Female jumper cables to the PIR module.

the other end of the cables go to these pins on the Raspberry Pi 3 pins:

  • 5v goes to pin 2 on the raspberry pi
  • The gnd (ground) wire goes to pin 6 on the pi
  • The middle wire goes to pin 11 (GPIO #17 – See diagram here)

2. Install WiringPi & Other stuff

Type the following into your Pi’s terminal window to install WiringPi:

1
git clone git://git.drogon.net/wiringPi

Download Cowboysdude’s PIR-sensor script from here:
https://github.com/cowboysdude/Pir-Sensor/archive/master.zip

Upload the files to your Pi’s root folder, otherwise it won’t work without modifying the script.

Now make your files executable. From a terminal, run the following commands in the root directory:

1
2
3
4
5
sudo chmod +x pir.py

sudo chmod +x monitor_off.sh

sudo chmod +x monitor_on.sh

3. Make your script run on boot

From a terminal, enter the following command:

1
sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart

Add this to the bottom of the file:

1
@/usr/bin/python /home/pi/pir.py

Press ctrl+x to save.

Now your script should be all set up, reboot the pi and test if it works:

1
sudo reboot

By default, the monitor shuts off after 20 seconds of no movement. To change this, edit the pir.py script and change this line:

1
SHUTOFF_DELAY = 20 # seconds

You may also like...

Leave a Reply

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