Project Sonic

Unexpected visitors

In the summer period, there’s often a bowl of cat food at our back door.

After some time however, we noticed that it attracted more than just cats. There was also a hedgehog that paid us a regular visit.

A bit later, he brought a friend. Later still, a mother brought her young, and after that another young.

The hedgehogs

This got us really curious about how many nightly visitors there actually were. Time for project Sonic!

Smile to the camera…

I recycled the Raspberry Pi setup of my previous Timer Button project, and I’ve added a Pi NoIr camera to it.

The Pi NoIr is similar to the normal Raspberry Pi camera, but it doesn’t have an infrared filter, making it suitable for night projects.

I’ve programmed the Pi to take pictures every 15 seconds.

…After a couple of tries

When I initially tested this setup, all the images were black.

After some googling, I quickly found the cause: the Pi NoIr is suitable for photo’s in the dark, but only with extra infrared lighting. Damn.

Since I didn’t have any infrared lights, I recycled an infrared led from an old remote. This gave a very faint light, but it wasn’t nearly enough for a good picture.

Next try: I bought some IR leds, but unfortunately the ultra bright ones were sold out. I added 4 leds this time, but again with the same results. A very faint glow, but not good enough.

After that, I tried with normal leds, but again with a brightness that was way too low.

Finally, I gave up. I just turned on my garden lights. It doesn’t scare the hedgehogs anyway. And now at least, the pictures were good!

Caught on Camera

And here you see the result:

Quite busy, right?

The Code

Here’s the code I’ve used for the camera:

from picamera import PiCamera
from time import sleep
from gpiozero import LED
import random
from fractions import Fraction

#Config
timeBetweenPics = 15 # amount of time between different pics, in seconds
totalPictureDuration = 5*60 # how long pictures should be taken, in minutes

# Camera
camera = PiCamera()
camera.rotation = 0
camera.resolution = (1920, 1080)
#camera.shutter_speed = 3000000
#camera.iso = 200
#camera.exposure_mode = 'night'
brightness = 50
previewTime = 5
amountOfPics = totalPictureDuration * 60 / timeBetweenPics # how many picture should be taken
randomString = str(random.randrange(100))+'X' # random number for image uniqueness

# Lights
topLed = LED(6) # clear IR 870mm
bottomLed = LED(19) # clear IR 870mm
leftLed = LED(26) # blue IR 925nm
rightLed = LED(13) # blue IR 925nm

def toggleLed(action):
    if action == "off":
        topLed.off()
        bottomLed.off()
        leftLed.off()
        rightLed.off()
    elif action == "top":
        topLed.on()
        bottomLed.off()
        leftLed.off()
        rightLed.off()
    elif action == "bottom":
        topLed.off()
        bottomLed.on()
        leftLed.off()
        rightLed.off()
    elif action == "left":
        topLed.off()
        bottomLed.off()
        leftLed.on()
        rightLed.off()
    elif action == "right":
        topLed.off()
        bottomLed.off()
        leftLed.off()
        rightLed.on()
    elif action == "clear":
        topLed.on()
        bottomLed.on()
        leftLed.off()
        rightLed.off()
    elif action == "blue":
        topLed.off()
        bottomLed.off()
        leftLed.on()
        rightLed.on()
    else: # action == "all":
        topLed.on()
        bottomLed.on()
        leftLed.on()
        rightLed.on()
    return;


# Action!
sleep(60) # wait a bit before starting

for i in range(int(amountOfPics)):
    toggleLed("off")
    camera.start_preview(alpha=150)
    sleep(previewTime)
    camera.capture('/home/pi/Documents/Programs/PiCam/Capture/Image'+randomString+'%s.jpg' % i)
    camera.stop_preview()
    toggleLed("off")
    sleep(timeBetweenPics - previewTime)

As you can see, the coding for the leds is still there, but the leds are switched off at all times. 

3 thoughts on “Project Sonic

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s