Category Archives: garden

Trailcam – 5. I.R. Filter

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.

I bought the filter from an EBay seller in China. It took a while to arrive but was extremely cheap and pretty good quality. It comprises of a main body with an electrical connection coming out of it and works by sliding a tiny IR filter in front of the camera, replacing the missing filter on the pi noIR camera to give a better colour reproduction under natural light.

To get it to work the wires need to receive a brief current, when this is reversed (i/e the previous +ve connection becomes –ve) it goes the other way. I needed to find something that could reverse the polarity on a pair of wires and came across this description about a motor controller. http://computers.tutsplus.com/tutorials/controlling-dc-motors-using-python-with-a-raspberry-pi–cms-20051

I built this one using the diagram provided by Envatotuts+ on to a lovely adafruit permaproto board.

filter board

IC

Mount to cam

The IR filter is clearly from some sort of CCTV camera and so comes with a couple of mounting holes. These almost line up with the mounting holes on the camera board and pimoroni camera holder so I’ve bolted them together with some nylon nuts and bolts.

I tried to fit the camera unit behind the clear plastic of the box but the result was disappointing with a very noticeable blue / grey tinge so I ended up cutting a hole through it and pushing the camera assembly through. I’m not too happy about the camera position in relation to the filter housing and intend to jiggle it about a bit in the future.

In order to prevent water getting in I’ve put a clear lens over the outside. This is from a go-pro and was a very cheap pattern part. A bit of tape and some blu-tak and it’s firmly in position.

Automatic switching.

In order to use the camera as both a night time trail cam and a daytime birdfeeder camera I needed to get the IR filter to switch automatically. This will also help to give a better picture on the trailcam in the summer when full darkness is brief.

I’ve looked at putting in an LDR (and may still do in the future) however for the time being I’ve set up cron to run the on / off program at specific times. Pikrellcam also has the facility to run scripts and I will investigate this in the future also.

Python script (taken from the Envatotuts+ blog)

filter off

import RPi.GPIO as GPIO
from time import sleep
 
GPIO.setmode(GPIO.BOARD)
 
Motor1A = 16
Motor1B = 18
Motor1E = 22
 
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
 
print "Sending signal"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(0.1)
 
print "Filter off"
GPIO.output(Motor1E,GPIO.LOW)
 
GPIO.cleanup()

filter on

import RPi.GPIO as GPIO
from time import sleep
 
GPIO.setmode(GPIO.BOARD)
 
Motor1A = 16
Motor1B = 18
Motor1E = 22
 
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
 
print "Sending signal"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(0.1)
 
print "Filter on"
GPIO.output(Motor1E,GPIO.LOW)
 
GPIO.cleanup()

Addition to the cron

00 16 * * * /usr/bin/python /home/pi/filteroff.py

Trailcam – 6. Control buttons

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.

When the camera is put out in the garden it often drops the Wi-Fi link on the way so I wanted to fit the facility for a hardware button so that I could press it when the camera is positioned outside and re-establish the link.

buttons
The buttons on a small breadboard taken from my Pumoroni explorer hat (main). Buttons in place during “indoors mode” inset

When indoors & for testing I can use simple buttons however anything put outside stands the chance of being chewed so I’d like to be able to fit a waterproof button at a later date.

I’ve taken the button control straight from the main breakout board and it has the pull up resistors fitted before the male connector pegs, so it is simply a case of getting the new buttons fixed in the case and wiring on to them. I also added an LED that flashes (1, 2 or 3 times) depending upon which button is pressed.

main board

The button wiring has been a huge pain. The single core wires regularly snap at the join with the board resulting it a confusing mess of soldering and bodging. The board and wires perform perfectly and it is all an issue with my workmanship – this are would really benefit from having a custom PCM made.

The following basic python script monitors and controls the buttons / LED and is run at startup via my new favourite thing – cron!

Python prog

#! /usr/bin/python
 
import RPi.GPIO as GPIO
import os
import sys
import time
 
# set up button references
BUTTON1 = 18
BUTTON2 = 4
BUTTON3 = 7
GREEN = 3
 
 # set up buttons
GPIO.setmode(GPIO.BCM)
GPIO.setup(BUTTON1, GPIO.IN)
GPIO.setup(BUTTON2, GPIO.IN)
GPIO.setup(BUTTON3, GPIO.IN)
GPIO.setup(GREEN, GPIO.OUT)
# button 1 = green - reboot
# button 2 = yellow - restart wifi
# button 3 = red -
# turn light off
GPIO.output(GREEN,GPIO.LOW)
 
while True:
 if GPIO.input(BUTTON1) == GPIO.HIGH:
 print("button 1")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 os.system("sudo reboot")
 elif GPIO.input(BUTTON2) == GPIO.HIGH:
 print("button 2")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 os.system("sudo ifup --force wlan0")
 elif GPIO.input(BUTTON3) == GPIO.HIGH:
 print("button 3")
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.HIGH)
 time.sleep(.5)
 GPIO.output(GREEN,GPIO.LOW)
 time.sleep(.5)
 else:
 print("pin is low")
 time.sleep(2)

Trailcam – 7. Completion

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

 

Box / case

I’ve built the camera to be modular which helps when tinkering about with it but does take up a lot of space, hence the rather cramped appearance.

Camera in window cill mode
Camera in window cill mode
inside the camera
The tangly, wirey mess inside the trailcam. Generally, sensing on the front front piece, switches to the right of the main section and wi-fi on the left. 9v battery to the top with the switched tucked away from squirrely teeth.
inside front of camera
Inside of the front section with the IR lamp (top), camera and filter, PIR sensor. All held on with non committal bl-tak and gaffer tape! – it’s the future.
front view
Front (animal eye) view. I shall call him HAL and he shall sing nursery rhymes while he looses his mind.

Component list & suppliers

 

Item supplier Link
Battery – Easy Acc 1200mAh power bank. Amazon UK http://www.amazon.co.uk/gp/product/B008YRG5JQ?keywords=EasyAcc%2012000mAh%20Power%20Bank&qid=1452114498&ref_=sr_1_1&sr=8-1
Raspberry pi A RS Bought together but no longer available
Pi noIR camera RS
Wi-Fi adaptor Modmypi http://www.modmypi.com/raspberry-pi/accessories/wifi-dongles/wifi-dongle-ultra-long-range-high-gain-w-5dbi-antenna/?search=wifi
Relay Ciesco – now wirelessthings https://www.wirelessthings.net/3v-relay-board-supports-logic-level-kit
Lamp Maplin http://www.maplin.co.uk/p/infrared-spotlight-module-a23jn
IR filter eBay http://www.ebay.co.uk/itm/381270484479
Filter controller IC Modmypi http://www.modmypi.com/electronics/integrated-circuits-ics/l293dne-dual-h-bridge-ic-solenoid,-dc-and-stepper-motor-driver/?search=ADAS-807
Circuit board

Adafruit permaproto pi

Modmypi https://www.modmypi.com/search/?search=ADAS-1148
Circuit boards

Adafruit permaproto ½ size boards

Modmypi http://www.modmypi.com/raspberry-pi/breakout-boards/adafruit/adafruit-perma-proto-half-sized-breadboard-pcb-3-pack/?search=adafruit%20board
Buttons Modmypi http://www.modmypi.com/electronics/buttons-and-switches/colorful-tactile-button-switch-assortment-square-15-pack
PIR sensor Tandy  http://www.tandyonline.co.uk/pir-motion-sensor-module.html
Wires and other bits pimoroni https://shop.pimoroni.com/
Camera software pikrellcam http://billw2.github.io/pikrellcam/pikrellcam.html

GPIO Pin summary

Board

(physical)

BCM

(logic)

Use
12 18 Button 1 (green) – reboot
7 4 Button 2 (yellow) – restart wi-fi
26 7 Button 3 (red)
5 3 LED
16 23 Motor 1A
18 24 Motor 1B
22 25 Motor 1C
11 17 IR Lamp (connection to relay)
15 22 PIR sensor

Examples

Filmed through glass and saved as an mp4

Filmed outside running on batteries. Video has been cut down in length using windows movie maker so is saved as a wmv

 

Now using adobe elements and with the interesting vids cut together

Improvements

Now that the weather has given me the chance to run the project outside, there are a couple of areas that I’m not happy with:

  1. reflection – there looks to be a noticeable reflection from the light on the lens (not helped by the badger nosing it!. I need to find some way of keeping it waterproof whilst stopping the reflection – also might try and find a way to stop the IR filter cutting off the corners of the image.
  2. Brightness of image – the image is too dark and noticeably darker than the previous version. I think that this is partly due to the camera being set as “auto” (hence it brightening up after the bager nosed it) and partly due to the lamp
  3. Lamp connection – The hardware weak point is the connection to the lamp. At every opportunity the wires fall off to such an extent that the solder pads on the lamp have fallen apart.