Wednesday, April 30, 2014
On 4:20 PM by Anonymous
OVERVIEW
Nobody move! Grrrrr..This simple alarm project hires a "watch dog" to keep an eye on intruders, or monitor occupancy of your home or office. The tutorial shows you how to interface commonly available low cost PIR (Passive InfraRed) sensors to the BeagleBone to detect occupancy or an intruder.
(This project can be combined with the ALARM1 tutorial to send you an email).
What you will need
- BeagleBone Black
- BeagleBone expandable case Orange or Black (recommended)
- AC adapter 5 Volts, 2 Amp (optional)
- Mini Breadboard
- Jumper Wire Pack
- Prototype Parts Kit
- (2) 330 Ohms resistor included in parts kit
- (1) red LED included in parts kit
- Proto Cape (optional)
- PIR motion sensor (example: HC-SR501)
- A network connection to the BeagleBone (optional)
Steps to follow
The PIR sensor detects body heat, and through the use of a special "Fresnel" lens, can detect motion as a change in 'heat energy' on its sensor surface. The sensor requires three connections. +5 volts for power, ground return and its 3 volts signal output (to the BeagleBone).
STEP 1
Identify the connections (be careful to wire the correct pins).
STEP 2
Make sure the BeagleBone power is OFF. Make the connections as shown.
STEP 3
Enter this BoneScript program in Cloud 9/IDE. With the USB cable connected to your BeagleBone, point your browser to
192.168.7.2:3000
Download Alarm2-Motion .js File
Program Listing
// Logic Supply Inc // Alarm with PIR Motion Demo Program for the BeagleBone Black ARM Cortex A8 // // Version : 0.0 Apr 30, 2014 Initial creation with parts kit (PTK-027). var b = require('bonescript'); // define pins and variables var LED_Red = "P9_14"; // with 330 Ohms series resistor var Sensor_pin = "P8_26"; // Push Button // === Define pin direction === b.pinMode(LED_Red, b.OUTPUT); b.pinMode(Sensor_pin, b.INPUT); // === Set initial pin state === b.digitalWrite(LED_Red, b.LOW); console.log('PIR Motion Alarm Demo Program'); //=== Sample inputs at given rate === setInterval (inputHandler, 1000); //=== Handle input when called === function inputHandler() { // detect alarm or test button push b.digitalRead(Sensor_pin, activate); function activate(x){ if (x.value == '1') { // pin is high - alarm condition b.digitalWrite(LED_Red,b.HIGH); console.log("ALARM: Motion detected"); } else{ // pin is low - turn OFF LED b.digitalWrite(LED_Red,b.LOW); } } }
Program Description
The first line requests the use of the bonescript library of functions. We then declare variables that make it easier for us to remember. Then, we need to set-up the pins and signals as input or outputs so that the BeagleBone knows what to do with the signals. Next, we establish a loop that calls-back a function, at regular intervals, to monitors the output signal of the motion sensor. Finally, if the sensor is triggered we display a console message, and turn ON the Led.STEP 4
Click the Cloud9 IDE RUN button to start the program.STEP 5
Finally the fun part! Test the circuit by moving in front of the sensor! Watch the Cloud 9 console and the red LED as the sensor is triggered. (some sensors have sensitivity and delay duration adjustments).
You can expand on this tutorial. Use your imagination as to the many possible ways this could be used. If you enjoy these tutorials, or would like to suggest new topics... send us feedback! Have fun!