PIR from a BBBW and Python

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

Categories: Beginner


I would be lying to you if I told you I was using this software to test if I was sleeping and moving around while sleeping. But…

This PIR Sensor could be used for this type of testing, e.g. "Did I move while sleeping between a specific interval during the night?"

import Adafruit_BBIO.GPIO as GPIO

import time


GPIO.setup("P8_12", GPIO.OUT)

PIR_PIN = "P8_8"


GPIO.add_event_detect(PIR_PIN, GPIO.RISING)


while True:


   if GPIO.event_detected("P8_8"):

       GPIO.output("P8_12", GPIO.HIGH)

       print("Motion Detected!")




       GPIO.output("P8_12", GPIO.LOW) 

       print("You are not moving while sleeping!")



This is free software that I use while researching ideas and using an if/else statement.

First…assemble the PIR Sensor and the LED.

On your PIR Sensor:

  • You have three pins if purchased from Adafruit at
  • One is GND, another is OUT, and the last one is 5v. These three pins are situated like this to the BBB.
  • PIR OUT to BBB P8_08
  • PIR 5v to BBB vdd_5v (this vdd_5v pin needs the 2A power adapter to be plugged in while testing this software)

Now…we need to set up our LED.

  • BBB GPIO (P8_12) to Anode of the LED
  • Cathode of the LED to 1K ohm resistor to GND on the BBB

Sort of like this idea from Fritzing:

LED Action

Second…try the source to attempt to make your LED light once the PIR Sensor has detected your movement.

If the PIR sensor is not detecting your movement, try to use the 2A adapter like this one:

If you want, from what I have learned, you can also use sys_5v on pin P9_7 or P9_8. vdd_5v is P9_5 and P9_6.


Comments are not currently available for this post.