Thursday, 25 September 2014

PIR to control USB camera

One of the things I want to try out is automatic recording of birds which visit the bird bath so the idea was to use a passive IR movement detector to tell the RPi when to record a photo from a USB camera.

It took a couple of hours scouring the net to find all the information I needed along with lots of failed coding attempts but eventually I got the idea to work just as a test layout in the kitchen. Very few components are needed - the Raspberry Pi (B+ in my case), the USB camera and the PIR:
(clicking on a photo will open a larger copy)

IMG_0126

Of course a screen, mouse and keyboard were attached while coding.

Cobbling together several pieces of code from different sources resulted in:

IMG_0124

modules loaded:
GPIO to acces the pins
time to be able to add delays where needed
os to give access to fswebcam code

N is a numerical counter which increments each time a photo is saved and added as a four digit number to the file name.

IMG_0125

IMG_0127

Next will be to get the photos saved on a USB stick instead of the micro SD card.



6 comments:

  1. You have an image with a bad link. It does show on Flikr.
    This is impressive. Not for me it's too complicated but it's good to see what can be achieved.

    ReplyDelete
    Replies
    1. Adrian: They all seem OK here with Safari and Firefox. Maybe you hit a Flickr glitch. I like the fact that I am coding on the Pi unlike with the Arduino where the coding is done separately on the PC first. Makes it quicker to see what alterations do.

      Delete
    2. I like the Arduino. I don't bother at the moment as I am trying to get my head around Python. Blender uses it and allows me to write simple code to speed up the bits I use. I find it really hard. Blender is very difficult.

      Delete
    3. Aha. That makes two of us battling with Python as that is what this project was written in.

      Delete
  2. PS. I got some thumb drives a month ago from Tesco 8GB for £4.99p each. Maplin probably do them cheaper.

    ReplyDelete
    Replies
    1. Adrian: They are amazingly cheap these days.

      Delete