Building the phototrap. Part 2: The control unit electronics

In part one of this series I documented the requirements for my phototrap project and chose the major components that I will use. This article will document the electronics used inside the control unit.

The camera triggers

When a sensor (or sensors) is triggered we are going to allow the user to fire the shutter or autofocus function of the camera and at the same time we will light up an indicator LED on the front panel to give some visual feedback.

Canon DSLR cameras and flashes are really simple to trigger. There are three terminals for ground, shutter and auto-focus respectively. Flashes don’t have the auto-focus contact. To activate the shutter or autofocus function you just need to ground it.

The above image shows the pinout of the two types of connector used by Canon in their cameras. Lower end rebel cameras have the TRS connector on the left, higher end cameras use the proprietary N3 connector on the right.

Here is the circuit that we will use to control the cameras and flashes.

The circuit shows the wiring required to control two cameras or flashes. Camera one is controlled by signals from Arduino pins 46 (shutter) and 47 (focus). Camera two is controlled by pins 48 and 49. Since our design calls for four camera outputs this circuit will be repeated once again.

IC1 is an optoisolator. We use it to electrically isolate the camera’s circuitry from the trigger, preventing us from causing any damage to the camera. The optoisolator is implemented internally as an LED positioned to be directly facing a phototransistor. When we activate that internal LED it switches the phototransistor on, allowing current to flow on the ‘other side’ of the isolator.

ILQ74 from Vishay is a quad optoisolator (it contains four independent isolators) designed for TTL level circuitry. In our circuit we chain the output from the trigger side of the optoisolator into the appropriate indicator LED (amber for AF, green for shoot).

Very Important!

Quite a large number of old flash units pass far more than 5V through their connectors – upwards of 100V is quite common. Apart from being dangerous for your health attempting to use these old units could destroy the optoisolator and maybe the rest of the circuit too. If you have an old flash then be certain of the voltage across its terminals before you use it. At the time of writing there is a very good reference page that you can use to check your flash.

The joystick

Sparkfun produce an extremely useful breakout board for the PS3 joystick that we are going to use to control our user interface.

Not only does this board provide contact points for our circuit, it also provides four 3mm mounting holes. We will use these holes to mount the joystick to our front panel.

This is the circuit that we will use to control the joystick. Inputs from the two axes go to the Arduino analog inputs and the push-button goes to digital #35. The axes are designed to read 50% when centered and will move up and down when the stick is moved, giving a resolution of 512 units in each direction.

The button in our circuit is normally HIGH and will read LOW when pressed


The JHD204A 20×4 LCD that we are going to use will be wired up as shown in the following diagram.

We are going to use the 4-bit interface supported by the LiquidCrystal Arduino library. This requires a total of 6 pins which we will connect to digital 22-27. We allow the user to adjust the strength of the backlight from the software and this is achieved by sending a PWM signal out of digital #2 to the base of a transistor that is used to regulate the current to the LED backlight.

In common with all character LCD panels connected through a HD44780 controller we have the option of adjusting what they call the display contrast. This is actually the LCD driving voltage and it’s controlled by adjusting the voltage to the Vee pin.

This particular panel is at its optimum driving voltage when Vee is tied to ground, and that’s what I’ve done here. If you are using a different panel then you may need to experiment with different value resistors between Vee and ground, or maybe even install a potentiometer so you can adjust it on the fly. Refer to your panel’s datasheet for guidance.

The 3mm indicator LEDs

Well this is about as basic as it gets but I’ll include the circuit here anyway for completeness.

I’m using 470Ω resistors to regulate the current mainly because I’ve got a lot of them but also because at a current of a mere 10mA they are very bright while being frugal with power at the same time.

The ‘back’ button

The final user input component in our circuit is a ‘back’ button. With up/down/left/right, action and back buttons we have enough controls to give a user interface experience that users will be familiar with and should learn quickly.

The circuit consists of a simple switch sampled by the Arduino on digital pin #34. It is normally LOW and will read HIGH when pressed.

The power button LED

Our power button has a built-in blue LED that we can control independently of the position of the button. This allows us to switch it on and off in software.

As you can see from the circuit we are using the output from a PWM pin to drive a transistor that will regulate the current, and therefore the brightness, of the power LED.

We will use this ability to do cool stuff in software like fade the button in and out and give it a pulsing ‘heartbeat’ effect when the unit is in power-saving mode.

The USB connector

The USB ‘A’ connector (the big flat one) on the side of our case allows me to flash new versions of the operating system without unscrewing the case and fiddling around with connectors inside. Strictly speaking according to the standard I should be fitting a ‘B’ connector but hey, it’s my project and A-A cables are readily and cheaply available.

What this circuit is doing is inserting a DPDT switch that allows us to switch between powering the Arduino from our battery via a 5V regulated supply (normal mode) and from the computer’s USB cable power supply (flashing mode). As you will see from the next article in this series we do this by hacking a USB cable and using it to supply power and data to the Arduino using the above circuit.

Building the circuit board

The Arduino inside our controller needs the support of a circuit board that will perform many of the functions documented above. One of the aims of this project is to allow anyone to build it without custom PCB manufacturing facilities and so we’re going to use commonly available stripboard.

Here’s the stripboard layout.

Click for larger, or here for a printable PDF.

Nearly all of the parts of the stripboard circuit are covered in the sections above, but there is one part that deserves a mention. The TS2940 and the two 10µF capacitors at the bottom constitute the 5V regulated power supply. The Arduino provides a 5V output pin but it has a maximum load of 250mA so we will power the Arduino and our peripherals and sensors from our own regulated supply bypassing the Arduino’s on-board regulator entirely.

There’s no need to go out of your way to try to find a TS2940, I just happened to have one so I used it. In fact, any LM7805 regulator will work. Just check the datasheet for the ‘application circuit’ because the manufacturer will probably recommend suitable values for the input and output decoupling capacitors. Try and get a model that supports a load of at least 1A. Hopefully we won’t be drawing this much from it but these devices run cooler when you’re well within the maximum output.

Parts list

Part Quantity
stripboard 26 strips, length 16
470Ω resistors 8
4.7KΩ resistors 2
220Ω resistors 2
BC549 transistors 2
ILQ74 quad optocoupler 2
10µF capacitors (as required) 2
TS2940 (or equivalent) 1
interconnect wire 8 lengths
SIL headers (male) 47 total pins
16 pin DIP socket (flat pins) 2
Pencil eraser (for the feet) 1
Superglue (cyanoacrylate) a tube

Preparing the stripboard

Click for larger

Cut the stripboard to the correct size (I included an extra row in mine because it happened to be on the end of the piece I was cutting and was useless due to a cut in it). You can use a hacksaw to cut the board but it will need a very thin blade. I used a dremel which takes a little longer but does the job perfectly.

Using a marker pen, mark on the plain side where the cuts are going to go by referring to the circuit plan. When each hole needs to be cut, poke something through the marked holes so that you are sure you got the correct hole.

Turn the board over and make the cuts using a spot face cutter. If you don’t have a spot-face cutter then don’t rush out and buy one. They are nothing more than a 3.5mm HSS drill bit with a handle glued on. If you have a set of drill bits then just use one of them hand-held. It will do the job just as well as the spot face cutter.

Test the electrical resistance across every break with a multimeter to ensure that you did not leave any microscopic traces

Wiring, sockets, headers

Click for larger

Mark the holes that need to have interconnecting wires using a marker pen, cut some wire to size and solder them in place. I find that solid core wire is best for this job and I’ve included suggested cut lengths in the circuit plan.

Test the electrical resistance of every interconnect with a multimeter to ensure that all your joints are sound.

With the wire in place you can now solder the IC sockets. After you’re done, test your joints with a multimeter. It may seem like we’re doing a lot of testing here, and we are. It’s because problems found at the early stages are a million times easier to diagnose and fix than when the whole board is assembled.

Cut the SIL headers into rows long enough to completely cover adjacent blocks. Solder them into place with the short end under the board and the long end sticking up ready to mate with a connector.


Click for larger

Start off by soldering the resistors, then the transistors and finally the capacitors. Test each resistor with your multimeter before you fit it to ensure it’s performing within spec and afterwards check the resistance of your joint to ensure you soldered it well.

Take great care with the orientation of the BC549 transistors. The circuit plan shows the correct location for the base(b), collector(c) and emitter(e). Refer to the manufacturer’s datasheet for the correct orientation because the same transistor model may have different pinouts depending on the manufacturer. My multimeter has a transistor test function that I always use to ensure that the orientation in the datasheet matches the part that I have in hand.

Voltage regulator and feet

Click for larger

Solder the voltage regulator into place. The stripboard layout is specifically designed so that the back plate of the TO-220 case faces over the edge of the board. This is so that you can fix on a heatsink. While not strictly necessary, allowing heat to be efficiently removed from the component will prolong its life.

You can buy specific TO-220 heatsinks but they are expensive for what you get so I bought a set of 10 self-adhesive heatsinks on ebay that are advertised as being for video card RAM and they fit perfectly. They cost me 99 pence for the set.

Now flip the board over and cut four cubes from the pencil eraser so that they are sized to cover a 4×4 grid of holes and are of equal height when resting on the board. These cubes will be the ‘feet’ for the board and will allow us to mount it into place.

Using a single drop of superglue per foot, glue a foot into each corner of the board and allow it to set. You will notice from the circuit plan that I have kept each 4×4 corner of the board free from components. Superglue binds in seconds but I chose to do it last thing in the day and I left it overnight to be sure.

Finally you can gently insert the optocoupler IC’s into their sockets being careful to align pin 1 with the top left of the socket. You will probably have to carefully bend each row of pins inwards a little bit so that they line up with the socket. This is best done by holding the IC and pressing a whole side of pins evenly down against a flat surface, repeating for the opposite side.

That’s it!

Well done, you’ve built the control board. In the next part of this series we’ll tackle the box wiring and assembly of the hardware. Better warm up the drill and dremel…

Article series index

Use the following links to navigate through this series of articles.

Part 1: Design
Part 2: The control unit electronics You are here.
Part 3: Control unit assembly
Part 4: The operating system Coming soon!
Part 5: The infra-red beam sensor
Part 6: The X-band radar sensor Coming soon!
Part 7: The PIR infra-red sensor Coming soon!
Part 8: The lightning trigger Coming soon!
Part 9: The ultrasonic trigger Coming soon!
Part 10: The sonic trigger Coming soon!
Part 11: The laser trigger Coming soon!