PiNoir Camera in a Nesting Box

Both the camera and the A+ were mounted underneath the roof. The light which reaches through the loophole in to the box isn’t enough for a decent picture quality. Therefore I mounted four standard IR LED around the PiNoir camera.

IMG_7097_1

Since each LED has an IF of 100 mA, they cannot be powered from the 3.3 V pin of the Raspberry. Instead, I used a LF33CV voltage converter and four BC547 transistors with 1 kΩ base resistors to drive the LEDs. The circuit was build on a small break-out board.

nistkasten_platine_Steckplatine

The LEDs have a VF of 1.3 V and thus require a 20 Ω series resistor each (on the board above I used 2 x 10 Ω for each LED; please note that the resistors are not correctly labeled). im_0001_20151024_150117_1

The IR LEDs can be controlled using a simple Python script. It is planned to add a switch to motioneye. Meanwhile it turned out that two LEDs are enough for illuminating the interior of the box.

A nesting box that “twitters”

In order to receive notifications upon arrival of birds, I connected the nesting box to my Twitter account, using the Tywython package. To get started, I registered my application at https://dev.twitter.com/apps and grabbed my Consumer Key and Consumer Secret.

Then, I installed Twython via pip

$ pip install twython

and imported Twython

<span class="pl-k">from</span> twython <span class="pl-k">import</span> Twython

Since birds can be very active, I limited the number of tweets to one per day. The Python script below twitters the latest picture taken by the PiNoir camera.

#!/usr/bin/env python
import os
import time
from twython import Twython
# API credentials
CONSUMER_KEY = 'INSERT CONSUMER KEY HERE'
CONSUMER_SECRET = 'INSERT CONSUMER SECRET HERE'
ACCESS_KEY = 'INSERT ACCESS KEY HERE'
ACCESS_SECRET = 'INSERT ACCESS SECRET HERE'
api = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
# write unixtime to file
def w_timestamp():
 filename = '/home/pi/tweet/timestamp'
 file = open(filename, "w")
 now = time.time()
 file.write(str(now))
 file.close()
# read unixtime from file
def r_timestamp():
 filename = '/home/pi/tweet/timestamp'
 file = open(filename, "r")
 for line in file:
 lasttweet = line.rstrip()
 file.close()
 return lasttweet
def autotweet():
 path = '/var/lib/motioneye/'
 directory = os.listdir(path)
 directory.sort()
 file = os.listdir(path + directory[-1])
 file.sort()
 photo = open(path + directory[-1] + '/' + file[-1],'rb')
 api.update_status_with_media(media=photo, status='BirdPi Twython Bot: A visitor has arrived to my #nestingbox')
 w_timestamp()
# limit tweets to 1 per day
def main():
 time.sleep(5)
 if ( int(time.time() - float(r_timestamp())) >= 86400 ):
 autotweet()
 else:
 return 0
if __name__ == '__main__':
 main()

The script is triggered each time when motioneye detects activity inside the box.  In order to avoid empty frames, I configured motioneye to skip frames before and after a motion events.

In 2016, my nesting box spent it’s first season outside and has recorded some nice pictures and movies which can be watched over here.

Leave a Reply

  Subscribe  
Notify of