The Mortal (Relay) Coil
Last time, I mentioned that there are still some applications where a relay might make more sense than a solid state switching element. Granted, relays aren't (and shouldn't be) as ubiquitous as they once were, but there are still a few reasons you might need to put a relay in a modern circuit.
White PapersMore >>
- Intrusion Prevention Systems: What to Look for in a Solution
- Catch the Security Breach Before It’s Out of Reach
A basic relay has two major parts: a coil and a set of contacts. When you energize the coil, the magic of magnetism makes the contacts go from their normal position to an alternate position. Some relays will have normally open or normally closed contacts. Others will have one set for each. Like a switch, you can have multiple poles of contacts and you often hear about a relay's "form" when talking about the contact arrangement.
Given the paragraph above, it would seem that using relays is a piece of cake, right? Energize the coil somehow and wire the contacts like you would a mechanical switch. Great theory, but the apparent ease of use of relays, in my opinion, is one of the things that has contributed to relays getting a bad name for being unreliable.
The relay coil is an inductor, and driving it from a microcontroller has certain considerations. Those are well known, for the most part, and not what causes the problem. The problem is in the switch contacts. You can buy relays with different types of contact material and each one is made to switch different kinds of circuits. I am always surprised how many people just assume any relay will switch anything. For the most part, though, any relay will switch almost anything for awhile. As long as the contacts can handle the voltage and the current, the real cost will be in long-term reliability and degraded performance.
Driving the coil is not a big deal, although since a coil is just a length of wire, you will only find a few you could directly drive from a microcontroller. Even if you can, I don't like to subject my I/O ports to that much stress, so I almost always use a circuit like the one seen below. The L1 component represents a relay coil (for a Teledyne 412-12 relay).
The diode in the circuit is very important. If you look at it, it appears to be "backwards"—that is, current shouldn't flow through the diode. Normally, that's true. The problem is the relay coil is an inductor. One of the properties of an inductor is that it generates an opposing voltage when it sees a change in voltage and the amount of voltage it generates is mostly determined by the rate of change.
I once again used CircuitLab to model what would happen if you omitted the diode. As you can see in the plot below, the peak voltage applied to the transistor can exceed 150V! This is probably a little pessimistic since CircuitLab generates impossibly steep square waves on the input. However, since the transistor has a rated Vceo of 40V, even if that estimate is off by half, the transistor will lead a short brutal life. On the other hand, the same circuit modeled in Spice with a 1 nanosecond rise and fall time showed a 7,000 volt spike! So maybe CircuitLab is actually optimistic. Either way, that transistor is going to blow.
The addition of D1 clamps the voltage to just a little higher than V2 (you can see the effect in the plot below). This is a very common design. So much so that you can actually buy your relays with this diode built into them, if you like.
That leaves one other piece of the puzzle: the contacts. Some relays are made to switch dry, for example. That means the contacts are optimized to switch with no current flowing through them. Others are made to switch high currents.
The reason this is important is that life isn't as neat and clean as our schematic diagrams. Conceptually, the contacts don't touch and then they do. Case closed. But the reality is different. As the contacts get close to each other, they eventually will draw a little spark between them as the electricity charges the capacitor temporarily formed by the contacts and the air (or other gas) between them.
The spark is a good thing and a bad thing. Over time, contacts will oxidize (rust) and the resistance of the contacts will go up. A little spark (or arc) can clean that film off, resulting in lower contact resistance. However, it can also pit the contact, literally disintegrating the metal. When the contact's surface area is impaired, resistance will go up and eventually the contact will fail.
Next time, I will talk more about selecting relay contacts before we get back to some more 21st century technologies.