element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
STEM Academy
  • Learn
  • Learning Center
  • STEM Academy
  • More
  • Cancel
STEM Academy
Blog PIR-fect
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join STEM Academy to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mconners
  • Date Created: 22 Dec 2014 8:35 PM Date Created
  • Views 1550 views
  • Likes 5 likes
  • Comments 8 comments
  • b+
  • stem
  • raspi
  • stem space
Related
Recommended

PIR-fect

mconners
mconners
22 Dec 2014

OK, I dug deep into my parts bin and found another Parallax part. The Passive Infrared Motion Sensor, or PIR sensor. This is another very simple device that you can connect up to your B+ (or any other Raspberry Pi devices).

 

The theory behind the PIR sensor is that is is a pyroelectric device, this means that it can detect small changes in the radiant heat of objects in the sensors vicinity, when this occurs the output of the sensor will flip from low to high, which is something that you can detect.

 

The device is fitted with a Fresnel lens that focuses the infrared signals onto the sensing element.

 

The version of the device that I have is Parallax Part #555-28027, this device, once again, is safe to connect directly to the Raspberry Pi as it only outputs 3.3v. This is very important when selecting sensors for the Raspberry Pi as signals greater than 3.3 volts can damage the Pi.

 

So the first thing to do is to ensure that you have the python gpio libraries installed, this can be done as follows:

 

You just need to run the following commands at the command line

 

sudo apt-get update
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio

 

If you are not sure whether those things are installed just run them, it will either download the latest version or tell you that you have the latest version already installed. It may prompt you to answer 'Y' to confirm the installations.

 

Next, shutdown your pi and power it off.

 

Connect the + pin on the PIR sensor to the Raspberry Pi pin 2, the - Pin to the Raspberry Pi pin 6, and the Out pin to the Raspberry Pi Pin 11 (the pins are numbered in an alternating fashion, with pin 1 being closest to the red power LED, odd numbered pins are in one row, even numbers are in the next row).

 

Thats it!!! Just 3 pins!!!

 

Once the devices are connected you can power up the Raspberry Pi and dowload the attached code, pir.py, and perform the following command in the directory where you downloaded pir.py

 

chmod 755 pir.py

 

This should only be necessary right after you download the file, it sets the permissions of the file to allow it to be executed.

 

To run the file simply type the following in the same command window:

 

sudo ./pir.py

 

The sudo command is necessary to execute the command as the super user ensuring you have adequate permissions to access the GPIO pins. The ./ in the command simply indicates to the command window that the pir.py program is in the current directory.

 

The code is listed below:

 

#!/usr/bin/python
import time
import RPi.GPIO as GPIO

# Use board based pin numbering
GPIO.setmode(GPIO.BOARD)

pirPin = 11

# setup pirPin as input
GPIO.setup(pirPin, GPIO.IN)        

while True:
    if GPIO.input(pirPin):
        print("ACK!!! Someone's here!!!")
    time.sleep(0.5)

 

As you can see, it is very simple code, all it will do is print the message "ACK!!! Someone's here!!!" whenever the sensor determines someone is in the room. You can point the device towards the door and call someone into the room, when they appear in the sensors range the message will be printed to the screen.

 

What can you do with your new found knowledge? Well I have seen PIR sensors employed as power saving devices on vending machines. The external lights are turned off until the sensor determines someone is close enough to the vending machine to purchase something, then the front panel will light up telling you it is time to purchase a Coke.

 

In addition it could be used to signal when someone enters a room, or to control a nightlight when it senses someone is in the hallway, There are many uses for a Passive Infrared Motion Sensor.

 

image

Attachments:
pir.py.zip
  • Sign in to reply

Top Comments

  • DAB
    DAB over 10 years ago +2
    Nice simple way to check to see if someone is near your sensor. DAB
  • mcb1
    mcb1 over 10 years ago +2
    Nice work Michael You could use it to trigger your camera to see who's stealing your presents ...oh we did that last year. http://www.element14.com/community/roadTests/1220 Mark
  • mcb1
    mcb1 over 10 years ago in reply to mconners +2
    Did anyone use a PIR sensor in that challenge? Not to my knowledge/recollection. fvan used motion capture software, and I an modified outdoor PIR in my outdoor version for the magazine. http://www.element14…
Parents
  • mcb1
    mcb1 over 10 years ago

    Nice work Michael

     

    You could use it to trigger your camera to see who's stealing your presents ...oh we did that last year.

    http://www.element14.com/community/roadTests/1220

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mconners
    mconners over 10 years ago in reply to mcb1

    Yes, that would be a good application. Did anyone use a PIR sensor in that challenge? Because that really would be a great way to use it.

    I just glossed over them all and didn't see anything, but I may have missed it. Although, if I remember correctly, it's not that difficult to set up the camera to trigger when it senses motion, is it?

     

    Mike

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 10 years ago in reply to mconners

    Did anyone use a PIR sensor in that challenge?

    Not to my knowledge/recollection.

     

    fvan used motion capture software, and I an modified outdoor PIR in my outdoor version for the magazine.

    http://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2014/01/29/catch-santa-challenge

     

    The Catch Santa simply did time lapse, until it ran out of battery ...who knew power bricks wouldn't charge as well as provide output ...image

     

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • mcb1
    mcb1 over 10 years ago in reply to mconners

    Did anyone use a PIR sensor in that challenge?

    Not to my knowledge/recollection.

     

    fvan used motion capture software, and I an modified outdoor PIR in my outdoor version for the magazine.

    http://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2014/01/29/catch-santa-challenge

     

    The Catch Santa simply did time lapse, until it ran out of battery ...who knew power bricks wouldn't charge as well as provide output ...image

     

     

    Mark

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube