Working with Relays: an Introduction and Example

The objectives of this tutorial are to familiarize members with relays; produce an example solderless breadboard circuit using a relay and a DIP switch; and provide an example using a PCB board, DIP switch, and Darlington array to control the relays semiautonomously.


So first what is a relay - a relay is most simply an electronically controlled switch.  Switches come in all types of forms and so do relays.  Relays like switches can exist in SPST, SPDT, DPDT,  styles, and so forth.  The first part of the word SP tells how many poles there are.  SP is single pole, DP is double pole, and you can have multiple poles.  The next part is the throws.  Again ST is single throw, DT is double throw.  I like to say that you have a control line in for the pole and the number of outputs is the throw.


SPST switches are the simpliest and the best example is a light switch.  SPDT is like a single switch that controls a fan and a light.  DPDT is a switch that can control two lines with a throw of the switch for instance a motor on a DPDT switch can be reversed clockwise and counterclockwise.  An important note is that you can combine two SPDT switches to form a DPDT switch and similarly do the same with SPST to form a DPST switch.  When costing your robot's parts, sometimes its better to buy one part in volume and change the design.


The next part of the discussion is a discussion about why use a relay?  An indication that you may need relays in your design are your applications include the need for voltages/amperages that your microcontroller organically cannot provide by itself.  Like motor drivers - a relay circuit (which can be a motor driver in special cases) can pulse motors on and off but without some complexity, would only control them in one direction at a time but in some cases when you just need a simple application to go one direction, it might be a viable solution.  Usually you use relays to power high power items from an external source of power such as a heater, a high amperage motor or fan, a chiller, a floodlight, large LED arrays, solenoids, or objects you want to either fail open or closed such as heaters or chiller applications if you run low on power (batteries are drained). 


Relays provide the option to have devices either connected as normally open or normally closed.  This means that when power is connected to your circuit by default the gate is either closed or open.  Where the 'normally' indicates whether the relay state is tripped as true.  The device will be in its normally closed state if the power to the relay still persists if a signal is lost to the relay.A good example of the case of a use of a failure case would be if you ran out of battery power in your submarine, you'd want one of its last things to do would be to drop ballast of any kind to rise to the surface. 



This tutorial will focus on a simple single relay in a breadboard circuit, focus on a COTS kit, then take a look at a real application of a relay board used to power bilge pumps in my submarine.


The example initial circuit that we'll breadboard includes the following parts:


(1) 3 Pole terminal block

(2) 1500 Ohm resistors 1/4 W, 5%

(2) LED,RED,635nm,T-1(3mm)

(1) 18 pin IC dual wipe socket

(1) 8 position DIP switch

(1) RELAY,[email protected],SPDT

(1) small signal diode switching

(2) solderless breadboards

(1) 12VDC regulated power supply

(1) 470 micro-Farad capacitor 25V

Various connection wires


 The test circuit works by providing an indicator light for power first, then the user controls the DIP switch position 1 manually to actuate the relay.  This also turns on the LED indicator light and powers the signal diode in parallel with the relay.  Note the hazards in this design are the orientation of the IC, switch, capacitor, relay, LEDs, and diode. This circuit can be assembled and tested in about 15 minutes.


Solderless Breadboard Version


The relay itself in this configuration is not connected to a device or an external power source.  This is due to the very difficult fact that this type of relay does not fit on a breadboard with the exception of in the IC slot.  This also means that you will have to customize your protoboard to account for this at the next step in design.  The future design will also integrate the Darlington array on the IC slot.  As a preventative measure it shouldn't be included on the board in the first go around.  The circuit works by simply changing the position of the first DIP switch (#1).  Turning it on and off toggles the relay on and off something that is both an audible switch for this type of relay and visual with the LED.  Some will consider the DIP switch to be an overly redundant part of this design.  As I am a very large advocate of testing in stages, the DIP switch design provides that initial phase to evaluate the circuit validity.  You can use the DIP to toggle the relays at approximately the same rate you might in a real applicationa and determine whether your voltage outputs are satisfied by that pulse rate of switching.  If not, you might need to add several larger capacitors to the mix and calculate a recharge rate that limits your pulse rate.


After you're comfortable with how this circuit works - you can build the complete design.  In this case I had ordered a Velleman K6714 universal relay card kit.  This kit is pretty large and won't fit well with any typical robotics project, but it's a good testbed for end-use testing on a bench.  This kit includes a AC/DC transformer which was not included in the build.  The kit included 8 relays and a lot of jumpers... these were replaced by the Darlington array from the breadboard concept and the 8-pos DIP switch (shown).  Note you see some capacitors (blue) above the relays - these were used with resistors for filtered output of the signal.  Each relay can be bridged either normally open or closed with this filter depending on which side of the relay you place the resistor.  This kit can be assembled in several hours.  Soldering is pretty intense with the number of connections and depending on your skill you can finish it quickly.  I finished off different sections at a time over a few different nights to complete the entire system.  I have provided the user manual for the kit in the attachments section which shows all the components, some upgrades, and provides a wiring diagram for this circuit.  You can also review the tracings shown on the back of the board (shown below).








The next part of the design is to insert the Darlington IC into the design and then to hook it into a MCU.  The MCU part is very simple and just involves taking a simple pin-out and commanding it high and low to drive the Darlington IC (shown in Nuts and Volts of BASIC Stamps NV6.pdf).  This can be done either autonomously or commanded through a GUI window.  I preferred to command my relay firings through a serial connection initially in the Arduino platform.  This is accomplished by a simple serial in command where the MCU waits for inputs in a while loop and updates the state of the pins.  Using a switch structure to identify each pin-out with a state, this was easily coded but multiple solutions are possible.



The relay card can then be used to test high amp drawing devices manually (using the 8-pos DIP) or using a MCU (shown here is the Arduino) through the Darlington array.  The relays are hooked up to bilge pumps (> 1 AMP @ 12VDC).  You can hook up any device from an array of LEDs or... well whatever.  Three bilge pumps are hooked into the relay cards in this instance with a 12 VDC test power source hooked into the card and a power supply hooked into the relays.  You can chose to wire the relays to the power source if your design calls for a similar level of voltage.  The relays however have a minimum voltage in which that they can function and you need to understand what that level is for proper operation.



Here are some alternative applications of the relay card and why I selected this particular kit in the first place.  Shown is one of the Virginia Tech Spacecraft Systems Simulation Lab's simulators (a.k.a. the TIE Fighter).  Relays were used to pulse cold gas thrusters (simulated as solenoids).  A test bench setup was used as well as the operational units.  The MCU was substituted here by a PC-104.  8 thrusters were mounted on a single panel and controlled wirelessly or internally via the relay card.




With each application one can take the kit of course only so far before you need to put it into your own design space.  In my most recent case I needed to fit it into a 4" ID PVC Sch 40 pipe for my Squidlian ROV.  Shown here is the matured design of a custom built relay card.  It features 8 relays (in the bottom of the stack) with connections through the top.  Power is provided to the central set of terminal blocks and the relays output to the terminal blocks at the ends.  Each relay has its own LED to indicate power.  This is a big factor in debugging circuits and the complexity is a lot greater just with the number of wiring involved and the choice to build two separate stacks of protoboards to fit.  This type of design required a week and a half to get the layout established, wiring setup, the boards drilled out, and so forth.  With the biggest issues in the wiring across different nodes using 14 AWG wire to support the amperages (in the middle section).  Another problem is keeping the wires well screwed into the terminal connections.  An improvement to this design could be to build a screw down type (where you wrap the wire around the screw and tighten vice using the screw only as a clamp) terminal strip instead of these type of connections.



Finally here's an example of it in action.This YouTube video shows a Visual Basic.NET GUI interface with the Arduino used to setup which relays are to turn on and off.   The example also shows a compass in play (not applicable to the overall relay concept) but was a general system test of some of the core functionality of the GUI serial connection from the Arduino to the relay card.  I hope this helped show some of the applications of a relay card and you make use of the multiple attached references for further growth.




20080822_relaytest.jpg247.47 KB
20080726_squidlianMCUrelay5.jpg99.53 KB
relaycard_initialbuild.jpg189.44 KB
relaycard_initialbuild2.jpg100.03 KB
20080726_squidlianMCUrelay4.jpg101.09 KB
20080911_digitalrelayview.jpg92.83 KB
relay_card_data.pdf565.71 KB
nv6.pdf374.08 KB
relayapplicationsYPSE2008.jpg46.24 KB