Relays

This article describes mechanical and electronic relays.

The Solenoid

A solenoid is a very simple device. Take a coil of wire, wrapped around something so that it keeps its shape. Now, stick a piece of metal inside the coil. When you put electricity through the coil, the metal will be attracted to the center of the coil. This device is called a solenoid.

A solenoid as described above is useful, but sometimes you want to push on things instead of pull. In this case, you simply attach a small bar to the big piece of metal, so that when the big piece of metal is pulled towards the center of the coil, the small bar pushes out the other side.

Relay

A relay is simply a solenoid with a switch attached to it. If you look at a real world relay, it usually is packaged in a somewhat squarish box, and has a bunch of leads sticking out the bottom. Two of these leads will be for the coil, which is the same as the coil for a simple solenoid. The switch will usually have normally closed and normally open contacts. There will be one contact (lead) which is connected to the normally closed contact when the relay is off. When the relay is turned on (when power is applied to the coil), the contact will be disconnected from the normally closed contact and will connect to the normally open contact. Remember that normally closed means that when the relay is not powered, the circuit is closed or connected, and normally open means that the circuit is open or disconnected.

Relays with Diodes and Capacitors?

A relay's coil is just a coil of wire, which is exactly what an inductor is, too. So, a relay coil has some inductance, which means that it is an energy storage device. What happens to all of that energy when the relay is turned off? Well, it goes somewhere. Where, you ask? Well, that depends on your circuit. If you are powering the relay from a computer, it could easily back feed into the computer and fry the entire system (yikes!).

What can we do to prevent this? The answer is to stick a diode across the terminals of the coil. The diode is reverse biased, which means that you put it in the direction so that current does not normally flow through it. When the relay is turned off, any energy in the coil will flow safely through the diode, and will be disippated as heat.

You will often see capacitors placed across the coil contacts of a relay. A capacitor takes some time to charge up, so it can be used to make a time delay relay. Warning: A capacitor and a relay coil (which is basically an inductor) are both energy storage devices. Under just the right circumstances, you can end up with "ringing." This means that energy from the capacitor will be discharged into the inductor, then the inductor will discharge into the capacitor, etc. back and forth until the resistor disippates enough energy that the circuit stops ringing. Unfortunately, determining whether or not the relay will ring means solving a differential equation, and most hobbyists don't really want to do that much calculus. The quick and dirty hobbyist method is to just build the circuit and see if it rings. If it does, change to a different value capacitor.

Relay Specs

A relay is basically a coil and a switch. In order to select the right relay for your project, you have to select the relay with the right specs for each part.

The coil will usually be specified to work at a certain voltage, which will be either AC or DC. An AC relay has what is called a shading coil in it, which prevents the magnetic field from collapsing when the AC input is around the zero portion of the sine wave. Since AC basically turns on and off 60 times a second (or 50, depening on what section of the world you are in), the shading coil prevents the relay from "chattering", since the coil would otherwise also turn on and off.

The coil will draw a certain amount of current. This may be stated as a current, or it may be given as a coil resistance value, in which case you can determine the current using Ohm's law. Your circuit must be able to supply this amount of current (plus a good safety factor) when the relay is turned on. You can use transistors to increase the amount of current your circuit can handle, and you can use a smaller relay to turn on a larger one if necessary (this is done quite often in power systems, since the relay required to switch high voltage and high current circuits is often the size of a washing machine).

The coil will also have an inductance spec. This is useful for determining whether or not the circuit will ring (see above), but hobbyists do not need to be overly concerned with it.

The relay will also often have a maximum switching time. A relay can't turn on and off instantly. If you try to turn it on and off too fast, you will have problems (however, pulse width modulation of a solenoid controlled valve is possible, and does have some interesting applications).

The switch side of the relay will also have some specs, just like an ordinary hand operated switch. It will have a maximum current and a maximum voltage, both of which should not be exceeded. As a general rule, the bigger the relay, the more current it can switch. This often means that you choose your relay based on its current capabilities, and then you have to design a driver circuit capable of providing the coil with enough current when it is energized.

Powering a relay from a digital circuit

Before digital circuits came around, relays were used all over the place in control systems. You can make some very complicated control circuits using relays, but it's a pain in the backside to re-wire all of those relays when you change the control algorithm. Relays are also relatively large and take up quite a bit of space and power.

Digital circuits are more often used for control these days. However, a digital circuit does not easily switch a high power device, so quite often a relay will be used for the final output stage. Transistors of various types are also often used, but relays still have their uses.

The following circuit shows how to power a relay from a digital circuit. This circuit uses a transistor to provide more current capability to drive the coil. When the digital output is turned on, the transistor conducts, and current flows through the coil (which then turns the relay on). When the digital output is turned off, the energy in the coil is safely disippated in the diode. R1 limits the current coming out of the digital output (otherwise it would see a short ciruit, which could damage the output). The value of R1 depends on the current required for the opto-isolator to turn on, which is typically about 5 mA or so.

R2 limits the base current of the transistor. Its value is not critical, as long as it allows the transistor to go into saturation (to turn on completely).

The diode should be rated to handle at least as much current as the relay coil draws when it is turned on (plus a good safety factor).

Solid State Relays

A solid state relay is really a semiconductor device. It has an advantage in that it has no moving parts, but it does have some drawbacks. A solid state relay is never completely on or off, but instead is always somewhere in between. Usually this is good enough, but for some circuits, the fact that the relay still conducts even when it is off (this is called the leakage current) will cause the circuit to misbehave. Solid state relays should not be used to switch very low current devices, since the leakage current is often enough to power these devices, so that the device appears to be switched on even though the relay is turned off.

Ladder Logic

Ladder logic isn't used much by hobbyists, but you might run across a schematic using it, so I will present a brief explanation here.

It's kind of confusing, but control circuits used to draw relay coils as circles and the relay switch as two parallel lines, very similar to the symbols used for a volage source and a capacitor respectively. It is quite common to draw a line down the left side of the paper, and use that as the voltage supply, and a line down the right side of the paper as ground. The relay circuit would then be drawn in between these two lines, forming what looks like a big ladder. This has become known as ladder logic, and is still used in control systems. Modern computerized programmable logic controllers (PLC) are programmed via ladder logic, although it's entered with a computer now instead of being drawn out by hand.

On a computer, most PLCs use -()- to represent a coil, and -||- to represent a contact (the switch). A typical rung of ladder logic might look like the following:

        |   IN1          R1      |
        |---||-----------()------|
        |   IN2          R2      |
        |---||-----------()------|
        |   R1    R2     OUT     |
        |---||----||-----()------|
        |                        |

This circuit has two inputs, IN1 and IN2 (IN1 might be a key switch, and IN2 might be a limit switch activated when something moves into a certain position). It has two relays, R1 and R2. Note that the coils for R1 and R2 are on different rungs than the contacts for R1 and R2. Relay R1 is turned on whenever switch IN1 is closed. If this doesn't make sense, remember that the left bar is power and the right bar is ground. When the switch is closed, current flows through the switch and the coil.

R2 is turned on whenever IN2 is closed. The output (OUT might be a relay or some sort of motor control) is only energized when R1 and R2 are both turned on (this is basically a relay AND gate).