PIR Based Security Camera

Thread Starter


Joined Sep 16, 2012
Well, I finally finished a project! So many projects start out - but never finish in my home... either due to complexity or I lose interest - or both. This time I got thru an entire project though and want to share with the world.

This project is released freely under the General Public Licensing Agreement found here: http://www.gnu.org/licenses/gpl-3.0.en.html

This code uses a Odroid C1+, wiringPi API, guvcview, a USB based webcam, and a PIR sensor to detect occupancy and to record a video locally and transfer it to a remote server somewhere. Optionally, a LED (or other 3.3V device) can be hooked up to a GPIO output to give visual indication that the PIR sensor has tripped. The code should be easily adaptable to the RaspberryPi - although I have not tried it personally.

The device uses the typical PIR sensor available from amazon for hobbyist electronics with three pins PWR, GND, and Trip Status. It's important to note that PWR is typically 5V, and Trip Status is usually 3.3V logic.

I used an old USB enabled webcam from Logitech that I had laying around from a previous laptop I no longer use.

Here's what you need to do to get the program running
  1. Install guvcview here: http://guvcview.sourceforge.net/downloads.html
    sudo add-apt-repository ppa:pj-assis/ppa
    sudo apt-get update
    sudo apt-get install guvcview
  2. Install wiringPi
    git clone https://github.com/hardkernel/wiringPi
    cd wiringPi
  3. Download attached source code and place in it's own directory - possibly ~/Code/OccSensorTrigVid
  4. Connect sensor and LED to Odroid GPIO header as follows:
    • PIR PWR to Odroid pin 2
    • PIR Status to Odroid pin 7
    • PIR GND to Odroid pin 9
    • LED-Anode to Odroid pin 18
    • LED-Cathode (thru a resistor) to Ordoid pin 20
  5. Mount a drive to /mnt/guvcview. I can't be much help here because it's extreamly device dependant - however take a look at this link: http://ubuntuhandbook.org/index.php/2014/08/map-network-drive-onto-ubuntu-14-04/
  6. Make the following directory ~/Video/guvcview
  7. Compile and run source code
    sudo gcc -o OccSensorTrigVid OccSensorTrigVid.c VideoRecord.c -lwiringPi -lwiringPiDev -lpthread
    sudo ./OccSensorTrigVid
    Note : pressing 'q <return>' will cleanly exit out of the program.
Video Description:

Captured Video:

Potential future development (I.E. Let me know what you'd like to see and I'll try to accommodate you):
  • Write a program that occasionally removes files older than ~2 weeks old from the server location.
  • Verify operation on a RaspberryPi
  • I have noticed that occasionally on startup the mounted drive does not mount properly and the files are saved to a local /mnt drive
  • Move occupancy specific code to the main program and make the video capture code more universal.
  • Incorporate a IR capable video camera
  • Add ambient light detector to auto adjust exposure. Or get the camera auto adjusting the exposure.
  • Build a housing to hold everything.

See attached source code