Analysis and implementation

As usual, I like to try things myself: I needed a small interface board for the Raspberry Pi that would enable me to control appliances through the GPIOs of the Pi. So I set out to design and build one. Here's what I came up with, for others to use and abuse. Enjoy! It's all documented after the usual:


The information and methods described herein are provided "AS-IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED. Use the concepts, examples and information at your own risk. There may be errors and inaccuracies, that could be damaging to your devices. Proceed with caution, and although it is highly unlikely that accidents will happen because of following advice or procedures described in this document, the author does not take any responsibility for any damage claimed to be caused by doing so.

Design goals

My design goals were relatively simple:


Here's the schematic of my first design:


Schematic explanation

The design is quite self-explanatory. As usual, I kept the whole design very modular, working in "banks": 4 input banks, 4 output banks, each of which can be omitted in the final device without affecting functionality. Similarly, some parts of the banks can be omitted, in particular in the output stages: if the LED is not required, then it can go along with its accompanying R2x. If the relay is not needed, its accompanying diode Dx can also be removed. The circuit will remain functional anyway.

Output stage

I'm using your average NPN transistor (2N3904, any equivalent will do), with its base driven through a 2.2kΩ resistor (calculation shows that it should still work with even higher values) to trigger a LED (for visual feedback), which is driven through a 1kΩ resistor. That is also quite a high value, because I wanted to keep power usage to a bare minimum. I used Kingbright LEDs, they remained very visible even with such limited current (~3mA) flowing through them, but lower values can certainly be used to make them brighter.

The 1N4148 flyback diode protects the circuit from inductive kickback when the relay coil de-energize. A word about the relay: though the ones I used (IM03TS) admit up to 250V switching (specifically, 60W/62.5VA, max 2/5A, 220VDC/250VAC), I would advise for extra caution, the circuit is NOT designed with such voltages in mind. It is worth mentioning that the sensitive and ultra high sensitive versions (respectively IM13 and IM23) of these relays can also be used, for reduced current drain on the 5V line (and the 3V through adjustment of R11-14).

Finally, both sides of the relay are output to a DIL header, which can be replaced by any kind of connector with the same footprint, or even direct wire soldering.

The output banks are connected from left to right to RPI pins 22, 18, 16 and 12; corresponding to GPIOs 25, 24, 23 and 18.

Input stage

On the input stage, the switch is hooked to the GPIO pin through a 1kΩ resistor that limits current usage to about 3mA in case the GPIO pin is incorrectly driven as an output. I couldn't be bothered dealing with hardware debouncing the switch, since it's easily done in software and it's easier to get the RC filter wrong than to get it working for all desired situations. A well-designed Schmitt trigger would have required extra circuitry that would have been cumbersome and costlier. I didn't deem it worth the extra effort given the scope of this project. Those interested in valid solutions can take a look at this excellent article. A pull down 10kΩ resistor (that limits leakage to about 330µA when the switch is pressed) is used to tie the GPIO to the ground in the relaxed position.

The input banks are connected from left to right to RPI pins 7, 11, 13 and 15; corresponding on a revision 2 Pi board to GPIOs 4, 17, 27 and 22.

Remaining bits of interest

R0 is a 0 ohm resistor, a.k.a "jumper wire" ;)
Finally, I have gathered some of the remaining signals on two separate headers: GPIOs 14 and 15 on SV6, along with 0, 3.3 and 5V, and GPIOs 2 and 3 (revision 2 numbering) on SV5, along with ground. I plan to use some of them for e.g. a temperature probe, later on.

The RPI connector pinout is one-to-one with P1 on the Pi, and is meant to be connected to the Pi via a standard 26-pin ribbon cable.


Here's a very simple one-sided, hand-routed layout that fits on credit-card-sized PCB.


I'm providing:

Final words

Though it's certainly a quick and quite gross hack, I have built and tested this board (which I am using to remote control a heating furnace, maybe more on that later) on a Model A Raspberry Pi. That Pi was also fitted with a WiPi dongle plugged directly onto the board, and the operation of the rPi Ctrl did not impact the Pi in anyway, so my goals for reduced power use were satisfied: it's possible to run a 450mA USB device AND this interface at the same time.