GPIO and a PIR


Raspberry Pi connected to a PIR and an LED.

I’ve finally got around to connecting a Passive Infra-Red Sensor (PIR) through the GPIO port of the Raspberry Pi. It’s been a long time coming and I wasn’t sure if the output of my PIR would be limited to 3.3 volts, or alternatively would run from 3.3 volts. In the end, I got out the multimeter and then I decided to try it.

This kind of thing is pretty easy with the PICAXE, which is where I spend a lot of my time. I’m a little more concerned about connecting up to GPIO as it’s a more expensive device all together. The PICAXE has quite robust inputs and outputs (sorry to say – I have tested this, and so have my students).

Ultimately, the PIR connects between the 5v terminal, Gnd and any available GPIO input. I’ve used pin 7. I’ve also connected an LED (through 330 ohms) so that I’ve got something to flash. I’d recommend this to anyone – testing GPIO outputs is much easier with an LED connected somewhere – we all need reassurance, right?

Circuit diagram showing the PIR connected to the GPIO

Raspberry Pi connected to a PIR and an LED – circuit diagram

From here, the Python program required was simple. Turn off the LED, check if the PIR has been triggered and flash an LED if it has. Then go back to the beginning…

The next step was to link to espeak using os.system. It works well as an intruder alert system!

What’s really amazing is the sensitivity that these little PIRs can manage. They can detect movement from a great distance and all for a few quid from “a well known auction site”. The current consumption is tiny so it doesn’t load your power supply down. Another advantage of this particular PIR is that the sensitivity and “on-time” are adjustable with two on-board preset resistors. I reckon they’re an absolute bargain.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s