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:

git clone git://

Download Cowboysdude’s PIR-sensor script from here:

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:

sudo chmod +x

sudo chmod +x

sudo chmod +x

3. Make your script run on boot

From a terminal, enter the following command:

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

Add this to the bottom of the file:

@/usr/bin/python /home/pi/

Press ctrl+x to save.

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

sudo reboot

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

SHUTOFF_DELAY = 20 # seconds

You may also like...

Leave a Reply

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