Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Seth
Published © CC BY-SA

PIR from a BBBW and Python

Did you ever want to know if you were moving while you slept?

BeginnerProtip1 hour1,801
PIR from a BBBW and Python

Things used in this project

Hardware components

BeagleBone Black Wireless
BeagleBoard.org BeagleBone Black Wireless
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Python
Adafruit_BBIO

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Finally...the PIR Sensor in Fritzing from Adafruit and the LED all in One!

https://github.com/adafruit/Fritzing-Library/tree/master/parts

LED Schematic

This is a schematic of P8_12 on the BBB to the Anode of a LED to the Cathode of the LED to a 1K resistor to the GND on the BBB (P9_01).

Code

PIR Sensors for Everyone!

Python
This software makes it so you can detect your motion in your sleep at different intervals.
import Adafruit_BBIO.GPIO as GPIO # import the Adafruit Library for GPIO
import time # import the time module so we can use time.sleep
  
GPIO.setup("P8_12", GPIO.OUT) # set up the pin as an outward pin
PIR_PIN = "P8_8" # make an alias for this pin number
GPIO.setup(PIR_PIN, GPIO.IN) # set up this pin for inward communication
GPIO.add_event_detect(PIR_PIN, GPIO.RISING) # in between HIGH and LOW, GPIOs    have an edge. This edge can be rising or falling or both. We here are using   interrupts or edge detection. So, for RISING, like in our example, the        interrupted edge we catch is from LOW to HIGH or RISING.
  
while True: # use a while loop "while" it is True
  
   if GPIO.event_detected("P8_8"): # if the event is detected from the PIR       # Sensor, do something.
       GPIO.output("P8_12", GPIO.HIGH) # This is what we "do." The LED goes          # HIGH/On.
       print("Motion Detected!") # print to the console.
       time.sleep(10) # wait 10 seconds until another "task" takes place.
  
   else: # or maybe something else is going on.
       GPIO.output("P8_12", GPIO.LOW) # The LED goes off/LOW and stays off           # while nothing is being caught moving on our edge.
       print("You are not moving while sleeping!")
       time.sleep(10)

Credits

Seth

Seth

32 projects • 13 followers
Stay there and someone will find you...

Comments