Raspberry Pi Night Camera - Part 2: Power and Lights

Last week, I wrote about a project that I started involving a Raspberry Pi Zero, a night camera and a motion sensor.

This week I will show how I solved the 2 more problems: lighting and power.

Lighting

Night vision cameras can't actually see in the dark. Like all other cameras, they still need light. But the light they can see is infra red light which is what separates them from the rest.

So most night vision cameras, have an infra red light that is invisible to human eye, but lights up an area perfectly for a camera to see.

For this project, I decided to use the IllumiPi kit, which provided all of the power cables and components hook up most IR lights. I also bought this light which is compatible with the camera and IllumiPi.

It needs 12V to power it and I originally bought a battery pack for 8 AA batteries. More on this in the next section.

So I followed the instructions and when I finished plugging it all in, it looked like this, roughly:

The black cables are ground and red live. The light and battery live cables actually join together on the breadboard.

You can see that the live cable plugs in the Pi at GPIO 24. This will become important when we do the code.

The way that I understand it works, is that the voltage regulator (that black thing) completes the circuit and is sort of a switch depending on if GPIO 24 is on or off.

Next I had to add code.

Last week I went through the code that uses the motion sensor to trigger the camera.

To this, I added the lights.

As I said above, the circuit is completed by the cable plugged into GPIO 24. So first I set this pin up for output:

LIGHT_PIN = 24
GPIO.setup(LIGHT_PIN, GPIO.OUT)

Next, inside my while loop all I had to do, was turn the light pin on and then off:

while True:
    if GPIO.input(PIR_PIN):
        filename = time.strftime("%d_%m_%Y_%H_%M_%S")
        GPIO.output(LIGHT_PIN, GPIO.HIGH)
        time.sleep(1)
        camera.capture('/home/pi/pic_'+filename+'.jpg')
        GPIO.output(LIGHT_PIN, GPIO.LOW)
        print "Picture Taken"
        time.sleep(3)

The key line here is:

GPIO.output(LIGHT_PIN, GPIO.HIGH)

Which turns in on. And then after the picture is taken:

GPIO.output(LIGHT_PIN, GPIO.LOW)

To turn it off.

I added a delay of 1 second in between turning it on and taking the picture as I found it took the picture too quickly after it was barely on.

Also it should be noted that the light array I am using has a built in sensor so that it won't switch on if it is too light around it.

And that is it! That is all it took to add the lights!

Powering Up

As I previously mentioned, my biggest blocker was figuring out how to power everything without mains electricity.

The lights require its own 12 volts of power. I originally bought a pack that held 8 AA batteries to achieve this. But I was pretty disappointed with this solution as it was very big.

One of the reasons for doing this project with the Raspberry Pi Zero was because of its tiny size. The 8 AAs negated this.

Upon revisiting this project this year, however, I discovered that you could get a single, fairly small battery that provides the required power! They are called 23A batteries.

I bought this from E-Bay which also had the holder for it to plug in. I am delighted with how small it is!

The Pi itself, I am powering with a Lithium Ion battery. I bought this one from Pimoroni. I also bought the Zero LiPo which provides the interface to plug it into the Raspberry Pi and is designed to be small enough to use with the Pi Zero. I had to also buy a charger for the battery so chose this one.

It would be nice if one day I figure out a way to have only one battery powering both AND the charger built in. But for now, this will do.

Summary

So that's it really! The last thing to do is solder it altogether and find suitable housing for it. I may do another blog post in future to show the finished product and the results I got from it.

I funded a Kickstarter a while back to get this protoboard which will allow me to solder it all together and keep it small. As for the housing, it seems I will have to make some home made. We will see.

I am quite excited to finally get this finished in the next couple weeks! I hope the last couple of blog post have been enough to get you started on similar projects.


© 2012-2017