Configure and Test

There are lots of ways to get the sketch from the listing below onto your Raspberry Pi. Perhaps the easiest is to connect to your Pi using SSH (See Lesson 6) opening an editor using the command below:

nano switches.py

.. and then pasting in the code , before saving the files using CTRL-x.

To start with, place the magnet next to the switch and cover the PIR sensor with something.

Run the program as superuser using the command:

sudo python switches.py

..and you should see some trace appear in the terminal, when you move the magnet, or take the cover off the PIR sensor.

A good exercise might be to place your kids in-front of the PIR sensor and see how long they can keep still!

PIR sensors and the Pi 3 sometimes don't get along - if you're having false trigger reports, make sure the PIR Sensor is far away from the Pi 3
Last updated on Jun 23, 2016 Published on Feb 13, 2013