Git Product home page Git Product logo

pir-sensor's Introduction

Pir-Sensor

Works with pi3 and 4, has visual as a module on screen and MUCH easier to setup and configure!!

If not then proceed:

NOW WORKS WITH PI4 (HDMI0) AND RPI3 [PLEASE READ THIS ENTIRE README!]

1st in a terminal window:

sudo apt-get install wiringpi

Download and put all files in your root directory on your Raspberry Pi

chmod all files:

From a terminal window in your root directoy (Where the files are):

sudo chmod +x pir.py
sudo chmod +x monitor_off.sh
sudo chmod +x monitor_on.sh

Editing pir.py

GO TO THIS LINE

For RIP3 from PIR DATA PIN: PIR_PIN = 17       - Pin 11 on the RPI3
For RPI4 from PIR DATA PIN: PIR_PIN = 27       - Pin 13 on the RPI4

IF you want to change PIR_PIN for some reason:

You will need to change this to the pin you're using on the pi for your sensor, to make it easy I would just use it the way it's setup. Remember that what the pi reads and what the actual pin number is not the same.

FROM PIR SENSOR

VCC to 5V on either board
GROUND TO GROUND on either board
No matter which 5v or Ground you use!  

RPI3 Pinout RPI4 Pinout


Last step:

In a terminal window from your root directory enter:

sudo crontab -e

On the last line enter:

@reboot python /home/pi/pir.py &

Hit CRTL-O to save then exit

Reboot your pi


OTHER ADJUSTMENTS:

In the pir.py go to the line:

SHUTOFF_DELAY = 20 # seconds

That's how long if NO motion is dectected the pi will shut off the screen. Change it to your desired number of seconds.

Other things: If you don't want to put this in your home directory then you can clone to the directory of your choice BUT remember to adjust your path in crontab... or it won't work!

pir-sensor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pir-sensor's Issues

Version for Pi4

Launch pir.py with sudo python3 pir.py

For pir.py add from subprocess import run
and changed 'def turn_on():' and 'def turn_off():' to

def turn_on():
    run('vcgencmd display_power 1',shell=True)

def turn_off():
    run('vcgencmd display_power 0',shell=True)

This works for me

Error after Python update?

My PIR process has started hanging following a Python update on my RPI3b, I suspect. The issue reappears after restarting, and I can't quite figure out what causes the initial error.

I run the pir process via PM2, which logged the following:

Traceback (most recent call last):
  File "/home/pi/pir.py", line 6, in <module>
    import subprocess
  File "/usr/lib/python2.7/subprocess.py", line 430, in <module>
    import pickle
  File "/usr/lib/python2.7/pickle.py", line 171, in <module>
    class Pickler:
  File "/usr/lib/python2.7/pickle.py", line 728, in Pickler
    dispatch[InstanceType] = save_inst
KeyboardInterrupt

I'm running GPIO v 2.44 and everything else on my Pi appears to be updated and in order. I know this is likely a simple issue, but I'm not a Python guy.

My lightly edited version of the pir.py code follows.

#!/usr/bin/env python
 
import sys
import time
import RPi.GPIO as io
import subprocess
 
io.setmode(io.BCM)
SHUTOFF_DELAY = 300  # seconds
PIR_PIN = 14        # Pin 8 on the board
 
def main():
    io.setup(PIR_PIN, io.IN)
    turned_off = False
    last_motion_time = time.time()
 
    while True:
        if io.input(PIR_PIN):
            last_motion_time = time.time()
            sys.stdout.flush()
            if turned_off:
                turned_off = False
                turn_on()
        else:
            if not turned_off and time.time() > (last_motion_time + SHUTOFF_DELAY):
                turned_off = True
                turn_off()
        time.sleep(5)
 
def turn_on():
    subprocess.call("sh monitor_on.sh", shell=True)

def turn_off():
    subprocess.call("sh monitor_off.sh", shell=True)

if __name__ == '__main__':
    try:
        main()
    except KeyboardInterrupt:
        io.cleanup()

Asus Tinker Board

How would I be able to get this to work on an Asus Tinkerboard since it doesn't use tvservice like the RPI?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.