Fork me on GitHub
beagleboard.org

Demos

Demo: PIR Motion Sensor

The PIR Motion Sensor, or Passive Infrared Sensor, is a sensor that takes a snapshot of the room and sets the 'alarm' pin to 'LOW' if it detects changes in heat. Since this sensor is an open collector, it needs a pull-up resistor on the alarm pin, which allows multiple motion sensors to be connected on a single input pin. If motion is detected in this demo, it will output "Motion Detected" on the console and will turn on the LED.

Example

var b = require('bonescript');
var led = "P8_13";
b.pinMode(led, 'out');
b.pinMode('P8_19', b.INPUT);
setInterval(checkPIR, 2500); // Checks the Sensor Every 2.5 Seconds

function checkPIR(){
b.digitalRead('P8_19', printStatus);
}

function printStatus(x) {
    if(x.value === 0){
         b.digitalWrite(led, 1);
    console.log("Motion Detected");
    }
    else{
    console.log("No Motion Detected");
         b.digitalWrite(led, 0);
    }
}




Build and execute instructions

  • Connect the '+' pin from the sensor to 'P9_5' of the BeagleBoard in series with a 10kohm resistor as shown on the right.
  • Connect the '-' pin from the sensor to 'P9_1' of the BeagleBoard.
  • Connect the 'AL' pin from the sensor to 'P8_19' of the BeagleBoard in series with a 10kohm resistor as shown on the right.
  • Connect the LED with a 470ohm resistor as shown on the right
  • Click "Run" on the code. Every 2.5 seconds, the console will tell you if there was motion detected. If there was motion detected, the LED will also turn on.

See also

Related functions


Last updated by juan_cortez on Fri Aug 16 2013 11:15:59 GMT-0500 (CDT).