Night Vision Camera for Raspberry Pi

Charles Chan
The Startup
Published in
4 min readOct 8, 2020

Have you ever wonder what goes on in your backyard when you are sound asleep? This simple setup will reveal everything to you.

Maybe it’s just out of curiosity. Maybe you are a nature lover and don’t want to miss out on the nocturnals. Whatever it is, I am glad to tell you that it’s inexpensive to set up a night vision camera and discover everything you are dying to know.

For this project, you will need:

  1. A working Raspberry Pi. I use a Raspberry Pi 4 but I believe anything other than Pi Zero would do. Pi Zero needs a different kind of cable. Cost: about USD 35
  2. A night vision camera from AliExpress. I use one that has IR-CUT, which automatically switches the camera from day mode to night mode. It would take better pictures if you are keeping the camera on during the day. Another good thing about this camera is that you can adjust its focus manually. Cost: about USD 10

Raspberry Pi setup

There are many instructions online. You should follow the one that is specific to your model: https://projects.raspberrypi.org/en/projects/raspberry-pi-setting-up

NOTE: Enable Wifi for extra convenience. However, straightly speaking, it is not required for this setup.

Camera Setup

Make sure your Raspberry Pi is turned off.

Plug in your camera cable like below. Gently lift the black plastic part with your finger and your thumb. The black plastic won’t separate but the opening will allow you to insert the camera cable. The cable’s silver (unprinted) side should be facing the USB ports (see below). After the cable is inserted, gently push the black plastic back into the socket and make sure it’s secured.

Camera cable. Notice how the silver side of the cable is facing towards the USB ports.

Once the camera cable is in, you can turn on the Raspberry Pi again.

SSH into your Raspberry Pi and enable the Camera module. This can be done under the Interface Options menu within the raspi-config command. Once the camera is enabled, restart your Raspberry Pi to take effect.

Testing the Camera

Before we proceed, it’s best to test the camera to make sure it can take still images. SSH into your Raspberry Pi and execute the following command:

raspistill -v -o test.jpg

This will take a still image using the camera. You can use scp or any other means to view the picture. The test image should be exactly like a picture you’d have taken with a digital camera.

Pause for a moment here. Think about how amazing this is. With less than USD 50 and a few commands, you have created an intelligent camera.

Time lapse/Motion Capture

Of course we won’t stop here. Now that you can take still images, it’s not hard to extend that to take time lapse images. In fact, a simple shell script would probably suffice. However, instead of writing scripts ourselves, it’s better to stand on the shoulders of giants. In this case, the giant I am referring to is Pi-Timolo.

The Pi-Timolo project is a wonderful collection of python scripts that work together to bring you time lapsed images, motion capture, and low light capabilities. Installation is straightforward. Once you have it installed, it pretty much works out of the box.

The two main scripts you will need to run are:

  1. pi-timolo.sh
  2. webserver.sh

The first one starts the main program and begins time lapse captures, and motion captures. The second one starts a web server (port 8080 by default) which allows you to view the captured images without using scp or ftp .

For convenience, I put these two commands into my /etc/rc.local script as below (before the exit 0 line. This way, my camera and my web server are started automatically every time my Raspberry Pi reboots.

/home/pi/pi-timolo/pi-timolo.sh start
/home/pi/pi-timolo/webserver.sh start

Pi-Timolo offers a lot more functionalities than what I have shown here, e.g. turning the captured images into a video, cloning the images into Google Drive, etc. I will leave those for you to discover.

Enclosure

After we have setup the hardware and the software, we need to prepare for the outdoor elements.

There are water resistance case for Raspberry Pi and its camera module. However, I find that an old tupperware works just fine. All you need to do is to cut a small hole for the camera and drill some ventilation holes on the side. Make sure you monitor your Pi temperature to ensure you have enough ventilation. The CPU temperature should not exceed 85C.

My Pi Camera resting inside a tupperware container. Obviously, I will put a lid on when it’s outside.

Finding the perfect spot for your camera is always tough. So, before I find a permanent location for my camera, I rest my tupperware on top of a tripod so that I can make adjustment easily. Drill a small hole in a piece of unused wood would let you create a small platform for your camera.

Using a tripod is very versatile when you are still finding the perfect location for your Pi Camera

Conclusion

I have done Kubernetes and Docker on Pi, Spotify on Pi, and now a Night Vision Camera on Pi. I have to say that this is the most fun project I have done with my Pi so far and it’s exciting to see how easy it is to setup and all the possibilities it offers.

I cannot wait to see what it will capture tonight!

--

--

Charles Chan
The Startup

A seasoned consultant specialized in Software Development and Architecture. Charles also loves to tavel, follow him on https://www.gorestrepeat.com/