How to turn a Raspberry Pi Zero into a Night Time Camera

Or: The Electronics and Electromagnetism Concerning a Baby Monitor

Sander van Dijk
11 min readJun 6, 2021

--

Babies are expensive additions to your household. If you want to keep an eye on their every twitch and turn when they aren’t near you, you can easily dish out anywhere up to $300 and beyond for a baby monitor. The latest and greatest in intelligent baby surveillance technology basically consists of smart cameras that can stream a live feed to your mobile device and do a bit of video processing on top.

Surely it is possible to create something similar for less money yourself, while having a bit of maker fun along the way! So that’s what I set out to do, and I will explain here the steps in doing so, while touching on some physics used to decide what parts to use. Let’s get started!

Note: this story contains some affiliate links.

The Foundation: the Raspberry Pi Zero W

The baby monitor must be small, cheap and efficient, but should be powerful enough to perform some processing of the video; at the least it should be capable of doing some motion detection to trigger notifications or make a recording of your baby’s night time activities. Plus, it must be able to connect to Wi-Fi to minimise cables in the nursery.

There is a popular single board computer that ticks all these boxes: the Raspberry Pi Zero W. There is still a little bit of a question how much processing it will actually be able to do — I’d like to try running some neural nets on it — but it turns out it is definitely sufficient as a base for this project.

The Raspberry Pi + NoIR camera kit available at the PiHut

I found the perfect kit at the PiHut that included an RPi Zero W, the official red-and-white case, which looks pretty sleek so that other halves can accept having it near their baby, and the NoIR camera module. This camera is ideal for our current use case where the baby monitor also needs to operate at night, because it does not have a filter for infrared (IR) light. This will allow us to get night vision if we add some IR illumination.

There are other specific night vision modules you could use, that have IR lighting integrated, and you can find other tutorials that create baby monitors using those, but I wanted something more compact. A solution similar to one from Raspberry Coulis was the most appealing to me, though it seemed a bit underpowered. So I have adapted it to make sure the little bundle of joy will always be clearly visible.

Finding the Right Illumination

By default the NoIR camera is still useless in a dark room, because there is no light of any sort, not even infrared. So we will have to add some illumination, and IR LEDs are perfect for that: they are very energy efficient and emit light at wavelengths that humans cannot see. However, there are many types of IR LEDs out there, with a very wide price range, so how do we pick which to use?

Firstly, of course we just want the LEDs with the highest base intensity. There are two measures at play here, and confusingly they are not always available for all LEDs: the ‘radiant flux (or ‘radiant power’) and the ‘radiant intensity. The first is the amount of energy emitted per time (watts), and the second is the flux per angle (watts per steradian). To illuminate the same amount of area more brightly independent of the beam width (see below), the radiant intensity is what matters. Unfortunately sometimes you can’t find either, and then all you can hope to refer to is the current rating: the higher the brighter (assuming equal efficiency and voltage, which is not always the case…)

Secondly, we want to have light for which the camera is most sensitive. For this point it is important to realise that there is a wide range of wavelengths emitted by the LEDs to choose from: anywhere between 700 nanometre and 1 millimetre is classified as infrared, but typical IR LEDs have peak wavelengths closer to the 850–950 nanometre range. As shown below, typical camera sensors are sensitive in this range and beyond (black curve), but the sensitivity drops with larger wavelengths. So we prefer LEDs with shorter wavelengths such as 850nm.

Typical camera sensor sensitivity (IR-Photo.net CC BY-NC-SA 3.0)

Next, the LED can spread out the light over a wide area, or focus it more strongly within a tighter beam. This is usually measured by the ‘angle of half intensity’. The camera we use has a maximum horizontal field of view of roughly 60 degrees, so just 30 degrees left and right. This means it should be fine to go for LEDs with a tighter beam that illuminate a smaller area more brightly (have higher intensity for the same flux).

Finally, LEDs come in a range of shapes and sizes, from tiny ones that can be soldered straight onto a PCB, to ready-made multi-LED matrices. The most familiar package is probably the 5mm through-hole variant, which would do for our use case, but I wanted to save space where possible, so I sought out good LEDs in a 3mm through-hole package.

Now, with all these specs you can go out and find some great, but expensive LEDs, like these Vishay ones for over $1.50 each. If we’d go for a 5mm package after all, the PiHut has some interesting options as well for $0.69 each. However, as mentioned I wanted something smaller (and cheaper), and I found a good candidate at Amazon: a bag of 100 Chanzon 850nm LEDs. They have a good short wavelength, a nice beam width at 30 degrees, and are only 3mm in diameter. The intensity or flux is not given, though for comparison the maximum rating at 20mA is a good amount less than the 100mA of the Vishay and PiHut options, but tests show that they are still good and bright, especially when using 4 of them as I planned. And finally, they are pretty cheap at less than $0.10 each!

You can make so many baby monitors with a bag of these Chanzon LEDs!

The Wiring Bit

Now that we have found our LEDs, we have to figure out how to wire them up. As mentioned I wanted to install 4 LEDs to ensure plenty of light. We could hook each to its own IO pin and control them all separately. However, the amount of current that the IO pins can provide is limited:

The GPIO pins can draw 50mA safely, distributed across all the pins; an individual GPIO pin can only safely draw 16mA.

I don’t want to run the LEDs at their max rating of 20mA anyway, but even at half that we’re getting too close to these safety ratings for my comfort. Especially if we want to maybe add some more bits in the future, like additional sensors. So instead, we will run the LEDs off of the Pi’s 5V power and switch them using transistors. With the forward voltage rating of 1.4V-1.6V for the LEDs we could run three in series on 5V, but for nicer symmetry we will run 2 series of 2 in parallel. Off to Fritzing and the breadboard to put things together!

The above shows the schematics of one of the two pairs of LEDs. It consists of the following components:

  • The two LEDs, placed in series one after the other
  • A current-limiting series resistor (R1) that prevents the LEDs from blowing up. To find the correct resistance we use Ohm’s law: V=I×R, where ‘V’ is the voltage difference over the resistor, ‘I’ the desired current, and ‘R’ the resistance.
    From a bit of testing I determined that a current of I=10mA gave sufficient illumination while staying well clear of the maximum rating, hopefully ensuring a long life for the LEDs. At that current, the forward voltages over each LED turned out to be 1.4V.
    That means that the voltage over the resistor, the ‘V’ in Ohm’s law, comes to 5V − 2×1.4V = 2.2V. Plugging this into the law gives a resistance of R = V/I = 2.2/0.01 = 220Ω.
  • A transistor for switching the LEDs on and off. I used a 2N2222A, which is a very common and cheap NPN transistor. Because it is an NPN transistor, it should be placed in so called ‘grounded-emitter’, or ‘common-emitter’ configuration, meaning that its emitter (in the schematic denoted with the arrow) should be connected to the ground and the collector to the components we want to switch. In our case that means the LEDs, which are placed ‘before’ the transistor.
  • A base resistor (R2) to limit the current through the transistor’s base. We can use Ohm’s law again to find a suitable value. A transistor has a characteristic called ‘current gain’, denoted with ‘hFE’. We can roughly say that the maximum current through the transistor’s collector (and thus through the LEDs) is this number times the current through its base.
    We want the transistor to be able to drive at least 10mA, and the 2N2222A transistor has a documented gain of hFE=100, which means we need a base current of at least 0.1mA.
    The GPIO pins provide 3.3V signals, so we get R = V/I = 3.3/0.0001 = 33kΩ. In the end I chose a 30kΩ resistor to be sure that the 10mA is reached, and my multimeter told me my transistors actually have a gain closer to 280 anyway, so that gives plenty of buffer.

After taking all that and sticking it into a breadboard (twice) and hooking it up to the Raspberry Pi…

Tada! We’ve got light. To the human eye only a slight reddish glow is visible, but my phone’s camera clearly picks up the infrared light emitted by the two LEDs on the left. This will definitely work for the NoIR camera then.

Time to squeeze it all into a tiny case.

Putting It All Together

As mentioned, I wanted to put everything into the official Raspberry Pi Zero case, to keep it nice and small and unobtrusive. At this point I just hoped it would all fit…

The first step is to make the holes for the LEDs to poke through. The lid of the case happened to have four nicely placed fabrication marks on the inside that made it easy to position the holes. Here I have just created the first two pilot holes:

The material of the case is very easy to get through with any battery operated drill.

Next up, soldering all the components. There is no space for an additional PCB inside of the case, so I just soldered the components together, with some wires in between them:

Many hands make light work

There were a few things that really helped with this and keeping it tidy:

  • Silicone insulated wire, from BNTECHGO. I had never used silicone wire before and it’s amazing. It is super flexible, plus it does not shrink when heated. That means you don’t end up with the insulation retracting and exposing much more wire than you’d want, like PVC insulation would. These properties make it great for this kind of circuitries in small spaces, and I think definitely worth its slightly higher price.
  • Magnetic, flexible helping hands with circuit board pillars. This again was a world of change compared to the traditional alternative: one of those black metal clumps with rigid arms and joints with too many thumb screws that would always end up toppling over.

With a bunch of fiddling and a steady hand, I finally managed to get everything together, into the lid and connected to the Pi:

Dual double LED switching circuitry packed together

I did not use any heat shrink to insulate the exposed leads, which were minimal thanks to the silicone wire, but instead just covered them with some goops of hot glue that also kept everything in place.

And… Squeeze!

Finally, the moment of truth: will it fit? After connecting the camera to the Pi, squishing everything in and putting the lid on…

The end result in all its glory

It fits! Well, kinda. A but of pushing was needed to close it all, and the lid didn’t feel like it really clicked into place very securely any more. So I ended up just superglueing the lid on, to make 100% sure it would not fall apart over a little baby’s head.

As a finishing touch I glued on a 3/8" to 1/4" adapter screw so that the contraption could be mounted on a tripod, and I connected it to a power bank to keep it mobile.

And then of course the final question: does it work at night? You can see the difference with the LEDs off and on at night here:

Difference of night and.. night with night vision

Even with the camera several feet away on a tripod on a chest of drawers, the illumination still travels the distance to have a clear enough view, with the infrared light nicely focused on the main subject of interest. I am pretty pleased with that!

As you can see, I run motionEye to perform the actual capturing and serving to be able to view the live video on a mobile device. I might write up more on getting that up and running, and perhaps on other bits of software and extensions that I am planning, in a future post.

There is Always Room for Improvement

To close off, some quick points where things could be improved:

  • By now I have switched from a tripod to a Gooseneck holder to hold the Raspberry Pi. This allows for some more flexible positioning of the camera to get the best view.
  • Although I thought it would be nice to be able to select between two levels of illumination by switching the two pairs of LEDs separately, for instance at dusk or dawn, in practice just having all four LEDs on works fine. Even during the day, there is no problem with over-saturation. So if I would build another one I would just build it with a single transistor, which would reduce the number of components having to pack in and make it all fit just that bit nicer.
  • At the moment the monitor does not have much of the ‘intelligence’ I talked about at the start; with motionEye it could report on some basic motion detection, but I’d like to do a bit more, perhaps with some of the additional computer vision compute power I have written about before.
  • In the same vein, I have purchased a USB microphone that I would like to add to the mix to be able to monitor any of that melodic crying.

So perhaps more on this in the future!

--

--