Tag Archives: trailcam

Trailcam – 1. Introduction

Other sections

  1. Introduction
  2. Basic setup & Power
  3. PIR sensor
  4. IR lamp
  5. IR filter
  6. Buttons
  7. Completed pics, improvements and parts list
  8. Updates

 

Camera in window cill mode
Camera in window cill mode

Description

The intention is to create an animal camera to video the wildlife of the garden and the window cill bird feeder. The idea is that the camera could be used outside (night or day) powered by battery then be moved indoors to the window cill to record the bird feeder where it can be powered by mains.

Previous versions

This is the 3rd version of the animalcam / trailcam with the older versions showing the progression and further useful information. Previous versions can be found here:

Version 2

Version 1 

General construction

To create this I’ve used a raspberry pi A,* powered by battery (which can be disconnected when connected to the mains) along with a pi noIR camera that has a moveable IR filter to give reasonable colour in the day and respond to IR light in the dark.

*: now using a pi zero – see here

The trailcam comprises of a main breakout board with the other elements attached separately – this helped me to construct the project in sections and allows for a level of upgrade later on. I ran in to issues on the previous version where the female to female jumpers kept coming off, resulting in a bunch of wires that I had no idea where they went, so this time I’ve soldered on JST connectors and colour coded them.

inside the camera

Overall concept:

In its current form, the trailcam simply uses pikrellcam to record video when it detects motion.  In the dark, a PIR sensor is activated which turns on an I.R. lamp, pikrellcam then records the motion event as if it were daylight. A switchable I.R. filter is fitted to the camera which enables good quality day time video and I.R. sensitive night time video.

The facility for bypassing the software motion detection is built in so that the recording of video can be triggered by the PIR if required.

Useful links:

I’ve cobbled this together using the how-to’s, programs, diagrams and general knowledge of some very clever and generous people that have taken the time to make their information public knowledge online. Despite my limited skill level it actually works!

The following are the main personal blogs and websites that I’ve used for help. In addition, the suppliers as noted in section 7 have really useful websites and blogs to go with their products.

South Somerset Weather

This was the original inspiration and also has some great videos.

http://www.afraidofsunlight.co.uk/weather/index.php?page=trailcam

 

Pikrellcam

The motion detection software used for this trailcam

http://billw2.github.io/pikrellcam/pikrellcam.html

 

Envatotuts+

Description, diagrams and python prog to control the L293D chip that operates the IR filter

http://computers.tutsplus.com/tutorials/controlling-dc-motors-using-python-with-a-raspberry-pi–cms-20051

 

Trevor Appleton

Handy guide for explaining cron

http://trevorappleton.blogspot.co.uk/2014/06/scheduling-python-programs-using-cron.html

 

Raspberry pi spy

Lots of useful tutorials

http://www.raspberrypi-spy.co.uk/

 

This description has been split down in to the following sections:

  1. Introduction
  2. Basic setup & Power
  3. PIR sensor
  4. IR lamp
  5. IR filter
  6. Buttons
  7. Completed pics, improvements and parts list

Trailcam – 2. Basic setup & power

Other sections

  1. Introduction
  2. Basic setup & Power
  3. PIR sensor
  4. IR lamp
  5. IR filter
  6. Buttons
  7. Completed pics, improvements and parts list
  8. Updates

 

Rpi basic setup

  • Raspbian o.s. on SD card*
  • Wi-Fi
  • Ssh
  • Pi noIR Camera

*: The pi runs the now superseded raspbian wheezy – I’ve had no issues with it so haven’t upgraded to Jessie on this particular pi.

The above is set up and confirmed working as described on the raspberry pi foundation website and numerous blogs and websites.

  • Video (pikrellcam)

This excellent piece of software is described in detail by its creator here: http://billw2.github.io/pikrellcam/pikrellcam.html where it can also be downloaded.

A further description & discussion is on the foundation website here:  https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=115583

Power

The first step is to provide power to the Rpi.

I’ve used a rechargeable battery from Amazon that is designed to provide emergency power to phones etc.

It’s a huge lump in terms of capacity, physical size and weight however it has performed flawlessly in the last couple of years. It takes a while to charge but holds it really well and lasts long enough to power the pi all night as well as for an hour or so to get the videos off of it in the morning.

It needs a pretty hefty power supply and I went with the recommended, branded one – this is also really handy for powering a pi2 with Wi-Fi when not charging the battery.

 

Trailcam – 3. PIR sensor

Other sections

  1. Introduction
  2. Basic setup & Power
  3. PIR sensor
  4. IR lamp
  5. IR filter
  6. Buttons
  7. Completed pics, improvements and parts list
  8. Updates

 

Description

The PIR sensor is a pretty standard piece of kit – I got mine from Tandy however they’re really common and stocked by the usual suspects (adafruit, pimoroni, Modmypi,maplin)

In the first version I had the PIR sensor triggering the recording however for this version I’ve altered it so that it just turns the IR lamp on leaving the motion detection in the software to do its thing..

Install

Camera in window cill mode
PIR at bottom of trailcam

I had hoped that the PIR would “see” through the plastic on the box however it wasn’t happening so I ended up removing the defractor / lens, drilling a hole through the box to push the sensor through then stick the lens on the outside. It does increase the chance of letting water through however there isn’t really much choice and a big chunk of gaffer tape should sort it out.

PIR
Dismantled PIR sensor (main). I cut a hole and pushed the sensor section through it, then fixed the diffuser on the outside (insert)

Control programme

I modified the control program from raspberry pi spy to run the previous version of the trail cam however this version only needs to turn the light on an off, hence why it is a bit of a mess.

EDIT: Revised version here

#!/usr/bin/python
# Original
# By : Raspberry Pi Spy
# Author : Matt Hawkins
# Date : 21/01/2013
# Modification
# By : G
# Date : 24/04/2016


# Import required Python libraries
import RPi.GPIO as GPIO
import time
import subprocess

# Use BCM GPIO references
# instead of physical pin numbers
GPIO.setmode(GPIO.BCM)

# Define PIR GPIO to use on Pi
GPIO_PIR = 22

print "PIR Running (CTRL-C to exit)"

# Set PIR pin as input
GPIO.setup(GPIO_PIR,GPIO.IN) # Echo

Current_State = 0
Previous_State = 0

# Define GPIO for lamp control
GPIO_LIGHT_ON = 17

# Set lamp on GPIO as output
GPIO.setup(GPIO_LIGHT_ON,GPIO.OUT) # Echo

try:

 print "Waiting for PIR to settle ..."

 # Loop until PIR output is 0
 while GPIO.input(GPIO_PIR)==1:
 Current_State = 0 

 print " Ready" 
 
 # Loop until users quits with CTRL-C
 while True :
 
 # Read PIR state
 Current_State = GPIO.input(GPIO_PIR)
 if Current_State==1 and Previous_State==0:
 # PIR is triggered
 print " Motion detected!"
 GPIO.output (GPIO_LIGHT_ON,1)
 print " Light on"
 # Capture a 5 second video
 # print " Record start"
 time.sleep(20)
 # Record previous state
 Previous_State=1
 elif Current_State==0 and Previous_State==1:
 # PIR has returned to ready state
 GPIO.output (GPIO_LIGHT_ON,0) 
 print " Light off" 
 print " Ready"
 Previous_State=0
 
 # Wait for 10 milliseconds
 time.sleep(0.01) 
 
except KeyboardInterrupt:
 print " Quit" 
 GPIO.output (GPIO_LIGHT_ON,0)
 # Reset GPIO settings
 GPIO.cleanup()