Atom Feed
Comments Atom Feed

Similar Articles

2009-09-19 20:14
CCTV IR Illuminators on the cheap
2017-04-23 14:21
Raspberry Pi SD Card Test
2009-05-10 13:24
Waiting for Panny
2008-11-23 09:11
Photography HOWTO 2: Understanding Exposure
2015-01-04 14:50
DBPower (MayGion) 720p P2P IP Camera with Linux & Zoneminder

Recent Articles

2019-07-28 16:35
git http with Nginx via Flask wsgi application (git4nginx)
2018-05-15 16:48
Raspberry Pi Camera, IR Lights and more
2017-04-23 14:21
Raspberry Pi SD Card Test
2017-04-07 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
2017-03-28 13:07
Kubernetes to learn Part 4

Glen Pitt-Pladdy :: Blog

Raspberry Pi Camera, IR Lights and more

I've been building up some Raspberry Pi based IP cameras using motionEyeOS which makes it easy to have a much better IP cam than you will get most places without the cost of high-end cams. Most important, it's maintainable which reduces the risks many IOT devices have.

When it comes to hardware, having an IR-Cut camera is nice. These have a solenoid activated IR filter that can be used for good colour in bright conditions, but in low light allows the broadest spectrum for maximum visibility as well as IR lights to be used.

IR Lights

The basic IR lights (LED based) that seem to be widely sold are a small module with an LDR, pot to adjust sensitivity and an LED with a lens to disperse the light.

Raspberry Pi Camera IR Light

The lens pulls off revealing the LED below. Also note that there is an IR filter over the LDR which will help stop the light reflecting back from causing it to turn off again, as well as suppressing other IR sources.

Raspberry Pi Camera IR Light, Lens off

The schematic (roughly traced) is simple:

Raspberry Pi Camera IR Light, rough schematic


But at the same time this has some problems as noted on many sites / videos:

  • Gain is limited (especially with so far as I can tell, using the first stage in this configuration which is best suited to low impedance/saturation rather than high gain), so the brightness depends a lot on enough current through the 47K pot. This means if you back it off (turn-on in darker conditions) it also can't push the LED as hard.
  • It runs from the 3.3V supply from the Raspberry Pi board - this has limited spare capacity and with two of these modules pushing the LEDs hard people have had trouble with it pulling down the supply / current limiting.
  • Cameras can operate down to light conditions where the LDR could be hundreds of K ohm, but that means the LDR can only shunt 1-2uA to shut off the lights in these conditionas, and even when the pot is backed off completely, there will be about 40uA supplied via the pot to the base of the first transistor. That means that it will take much higher light levels to turn the LED off. With the low gain, this means you don't have a chance of a decent switching level while maintaining brightness. This is demonstrated on some videos people have posted where the pot acts largely as a brightness control for the light and the LDR can only shut off the light in very bright conditions.
  • It uses a 2.4V regulator which seems to limit at about 250mA and control the overall output, assuming everything is turned up enough to reach this operating point. Since this drops the supply when it limits, the whole circuit changes operating point as this happens. This makes things less consistent and less clear the exact behaviour over the transition as multiple variables change at once.
  • Lack of current limiting for the first stage which could have that transistor pushing harder than is healthy if adjusted wrong. There is also nothing to limit the current through the POT so it can push the whole supply through the base of the transistor at minimum resistance.

So, to solve this I cobbled together a quick drive circuit of my own:

  • Runs directly from 5V input, so plenty of juice on tap without impacting supplies on the Pi board
  • Drives two LEDs in series for more efficiency (same current as one, but the higher supply voltage allows two to be driven).
  • Useful adjustment range on light level.
  • Rapid turn on and enough gain not to depend on turn-on adjustment for output.
  • Stabilises output current on it's own (no need for regulators etc.)
  • Has an output to drive GPIO to tell if the light is on.
  • One LDR controls everything.
  • Capable of enough power dissipation (with small heatsink) to drive a single LED (with two the voltage drop on the output transistor is low enough that minimal power is dissipated, but the heatsink may still be useful as a safety mechanism if things go wrong or you just want less stress on components).
  • Can be built out of readily available components.

Raspberry Pi Camera IR Light, alternate driver

How it works:

  • BD140 (or similar medium-power PNP) provides the power output and can screwed to a small heatsink if it runs too hot. Adjacent BC327 (or similar low-power PNP) provides lots of gain with 100R resistor for safety (current limiting) and 4K7 to absorb leakage and help for a cleaner turn-on.
  • A 1R2 emitter resistor on the BD140 provides a current measurement point and BC327 on the left will turn on when this voltage reaches ~0.6V and reduce the drive, hence stabilising the output current around 0.5A
  • Front end is a BC337 (or similar low-power NPN) with a 2k2 resistor in the collector to limit current. The 47k resistor deals with leakage from this transistor before it comes fully into bias and hence again helps with cleaner turn-on.
  • Two diodes provide a ~1.2V supply to put the turn-on threshold about half way and bring the adjustment into practical range without less common high-value pots which would be needed with almost 10x the voltage if we went directly to the supply. At the same time the 4k7 ensures that current is always limited (safe) irrespective of the pot adjustment.
  • A 4u7 cap filters the input to avoid problems from glitches, flickering light sources (eg. fluorescent or other lights that flicker). This also means that turn-on smooth and takes longer (several seconds), thus less likely to cause false triggering of motion detection algorithms processing the image.
  • On the output two 10k resistors provide a pull-down and a current limit for driving GPIO.

This can be easily put together on a small piece of strip-board or similar and fits easily with the rest of the bits:

Raspberry Pi Camera with IR Light and custom driver

To build this all the components except the LED were removed from the IR Light boards and then wired onto the driver board. A small piece of aluminium provides heatsinking, though in this (two-LED) configuration it's more safety if anything goes wrong than necessary.

Operating IR-Cut

A small script started at boot (see Tweaks in motionEyeOS for how to launch this) checks the GPIO and provides some timing on activating IR-Cut. In low light (IR on) it removes IR-Cut immediately, but when it gets bright it requires minutes before it puts in IR-Cut. This avoids excessive switching in marginal light conditions.

Other approaches

It did occur to me to add hysteresis, however this requires higher gain to work properly and the sharp turn-on/off (fully on or off) might also result in false triggering of motion detection algorithms processing the image unless it is set to come on in much lower light conditions where the IR would be a negligible contribution to the total illumination. Hysteresis would however be an advantage where flickering light sources are strong enough to cause unwanted switching which the filter is not sufficient to combat.