Raspberry Pi PIR Motion Sensor Detector

Posted on December 13, 2013 at 5:55 pm

This is the PIR (Motion) Sensor Detector to add to your Raspberry Pi:

Pinpir-p1

Pinpir-p2

Pinpir-p3

Create a script named sensor.bash in /root/ directory:

#!/bin/bash
 
#Define the GPIO path
GPIO="/usr/local/bin/gpio"
#Define raspistill path
RASPISTILL="/usr/bin/raspistill"
#Define sleep path
SLEEP="/bin/sleep"
#Set GPIO mode
$GPIO mode 0 input
 
while true; do
 
    $SLEEP 1
 
    #Wait until a movement is detected
    while [ `$GPIO read 0` = 1 ]; do
 
        #Save images to a folder with a numeric system
 
        INT=1
        PATH="/root/"
 
        while true; do
            if [ -f "$PATH"image"$INT".jpg ]; then
                INT=$((INT + 1))
                else
                break
            fi
        done
 
        echo "DEBUG: Movement detected... Creating image..."
        $RASPISTILL -v -q 100 -t 500 -o "$PATH"image"$INT".jpg
 
    $SLEEP 1
 
    done
 
done

Set the right permissions:

chmod +x /root/sensor.bash

Run the script:

cd /root
./sensor.bash

Now walk in front of the sensor and then check the /root/ directory.

You should see an image file named image1.jpg 🙂

Updated on December 14, 2013 at 6:21 pm

Receive updates via email

Other Posts

Updated Posts