rpiarduinomusings

Raspberry Pi, Arduino, Sensors and the data they produce

PIR Based Raspberry Pi Camera and Programming

One of our group is a very experienced programmer, (we have all programmed to an extent) and has come to love the Raspberry Pi (RPi) along with the rest of us.  Although his first taste of python was not well received, he has become somewhat of a fan (well that might be stretching it).  In his endeavor to reach new levels of programming proficiency as well as become more familiar with the hardware aspects of the RPi, he chose to write from scratch a program to automate the use of a PiCamera, along with accessing the GPIO ports of the RPi.  While he was at it he chose to add an LED indicator to show when movement was detected.

The PIR circuit is fairly simple affair:

 

You can but these from many vendors, I prefer Marlin P. Jones and AdaFruit.

You can wire this up on a breadboard, or connect directly to the RPi [WARNING – YOU  CAN DESTROY the RPI with these connections – we take no responsibility for your PIR or Raspberry PI if you follow these instructions!!!!!]

To be sure you have this right, check out this learning link: http://www.modmypi.com/blog/raspberry-pi-gpio-sensing-motion-detection

Three connections come off of the PIR if you use the same ones we experiment with:

  • Red jumper to VCC pin on PIR
  • Black jumper to the GND pin on PIR
  • any other color to the OUT pin on the PIR

Next you will attach these jumpers to your Pi.  Note that if you use the program written by by our programmer, you might have to change the PIN setup if you choose a different GPIO pin.

  • BLACK jumper [GND] is connected to pin 6 on the pi for ground
  • RED Jumper connects to  Pi pin 2 [5 Volts] for power
  • OUT jumper to GPIO pin x on the Raspberry Pi [remember to set x for the real pin number when you select it]

Now that the wiring is out of the way, you will need to setup your python programming to read the output of the PIR.

You must make sure to include the proper library items are available  within python.  (ASSUMPTION: You already know how to use python, if not, you might get lost in this setup; and you know how to use IDLE to test your programs.)

20160626_144051

You need to include the library for time and GPIO setup:

import time
GPIO.setmode(GPIO.BCM)
PIR_PIN = 7
GPIO.setup(PIR_PIN,GPIO.IN)
try:
print “PIR Module Test (Ctrl+C to Exit)”
time.sleep(2)
print “Ready@”
while True:
if GPIO.input(PIR_PIN):
print “Motion Detected”
time.sleep(1)
except KeyboardInterrupt:
print “Quit”
GPIO.cleanup()

There you have a clean program that you can use to test a PIR motion detector.

You can learn more at ModMYPI and visit the blogs, where I snatched this code to play with the PIR.

Soon,  one of my partners in this endeavor will discuss the rest of the programming that he did to recognize the camera module and then everything I mentioned in the prior blog about a program to read the PIR and email pictures of motion detected.

 

 

 

 

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: