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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • 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
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • 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
Raspberry Pi Projects
  • Products
  • Raspberry Pi
  • Raspberry Pi Projects
  • More
  • Cancel
Raspberry Pi Projects
Blog testing workaround for Foginator 2000 PIR
  • Blog
  • Documents
  • Events
  • Polls
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Former Member
  • Date Created: 30 Oct 2015 6:24 AM Date Created
  • Views 517 views
  • Likes 0 likes
  • Comments 0 comments
  • raspberry_pi_projects
  • pumpkinpi2015
Related
Recommended

testing workaround for Foginator 2000 PIR

Former Member
Former Member
30 Oct 2015

  This is my second blog entry about this project.  I must have saved the first one to the wrong area on Element14, and I'll work on moving it after I finish this entry.  As I mentioned in part 1, I could not get the special pin extender in time to mount the PIR detector on the Raspberry Pi with the Sense Hat.  So, I elected to add another Raspberry Pi to the project and connect all devices other than the Sense Hat to it.  It is a Raspnerry Pi B+, which I had as a spare.I connected the HC-SR501 PIR module using 3 pins.  I first tried using 3.3V on the Raspberry Pi to go to the HC-SR501 module.  I had read a couple of places that the module worked better at that voltage.  Well, not for me.  I connected Vcc on the HC-SR501(henceforth referred to as PIR) to 5Von the Pi, out on the PIR to GPIO7 on the PI, and ground on the PIR to ground on the PI.  I turned the sensitivity down a bit(counter clockwise on the left pot).

 

  I then setup samba on the Raspberry Pi 2 B.  I am going to use a simple method to communicate.  When motion is detected on the B+, it will create a file in the directory the 2B is sharing.  The 2 B runs a script that watches that directory and when the file is created, the fog machine gets turned on, and the notification file is deleted, so we can get the next notification.

 

  Here are the two programs I used for my PIR communications.  I have not figured out how to make them look right on the blog, and I apologize for that  The B+ has the PIR device and has the samba share mounted in a directory called /lee/lemonpi.  The workgroup name I use for samba is lee and the Raspberry Pi 2B has a hostname of lemonpi.  Th Pi B+ runs the following Python script(pir-trigger.py).

from subprocess import call

import RPi.GPIO as GPIO                           #Import GPIO library

import time                                       #Import time library

GPIO.setmode(GPIO.BOARD)                          #Set GPIO pin numbering

pir = 7                                          #Associate pin 26 to pir

GPIO.setup(pir, GPIO.IN)                          #Set pin as GPIO in

print "Waiting for sensor to settle"

time.sleep(2)                                     #Waiting 2 seconds for the sensor to initiate

print "Detecting motion"

while True:

   if GPIO.input(pir):                            #Check whether pir is HIGH

      nice_time = time.strftime('%l:%M%p %Z on %b %d, %Y') # ' 1:36PM EDT on Oct 18, 2010'

      print "Motion Detected at", nice_time

      call(["touch","/lee/lemonpi/notice"])

      time.sleep(2)                               #D1- Delay to avoid multiple detection

   time.sleep(0.1)    

 

  The Raspberry Pi 2B is running samba.  It is sharing a directory called /public and the last few lines of /etc/samba/smb.conf look like this:

[public]

   comment = Lemon Pi's public area

   path = /public

   guest ok = yes

   browseable = yes

   create mask = 0775

   directory mask = 0775

   read only = no

 

  The Raspberry Pi 2 B is running the following Python script(turn_on_fog.py):

import pyinotify

from sense_hat import SenseHat

import time

from subprocess import call

 

sense = SenseHat()

start_time = 0     # start at 0 so first pir event will trigger

 

class EventHandler(pyinotify.ProcessEvent):

    def process_IN_CLOSE_WRITE(self, event):

        global start_time

        elapsed_time = time.time() - start_time

        if elapsed_time > 60:   # Only trigger once per this many seconds

            start_time = time.time()        # reset timer

            sense.show_message("Fog envelops you")  # or start fog machine here

            print "Triggered by closing file name " + event.pathname

       # if you want to see when ignored events come in, uncomment this block

       # else:

       #       print "ignoring pir notice", elapsed_time

        # if a second trigger comes in while I was busy processing the first, an

        # error message will be printed.  It may safely be ignored.

        call(["sudo","rm", event.pathname])

 

def watch(filename):

    wm = pyinotify.WatchManager()

    mask = pyinotify.IN_CLOSE_WRITE

    wm.add_watch(filename, mask)

 

    eh = EventHandler()

    notifier = pyinotify.Notifier(wm, eh)

    notifier.loop()

 

if __name__ == '__main__':

    watch('/public')  # trigger on any new file in this directory

 

  The only thing you may not recognize there is import pynotify.  If you don't have that installed, you can just do a "sudo pip install pynotify".  If you don't have pip installed, just do a "sudo apt-get install python-pip"

 

This all proves my idea for using 2 PIs should work.  I'll have to modify Charles Hantt's programs to incorporate similar logic.

Attachments:
turn_on_fog.py.zip
pir-trigger.py.zip
  • Sign in to reply
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 © 2026 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