Electromechanical Relays
Part 1: Electromechanical Relays
There are plenty of articles online that do a fantastic job explaining the basics of relays. I will complement this article with some links on the reference section.
However, the goal with this article is to provide a bit more information and sometimes present some of the concepts with a different perspective. There are sections with some theoretical concepts that can be intimidating at first. Don't get overwhelm, you can always digest those advance concepts later as you get comfortable with the subject. You can also skip sections and read just the parts that are relevant to you.
Different Types of Relays
There are a lot of different types of relays. The picture below, shows some types of relays grouped by how they are constructed:

However, we can also group the relays by their functionality in a circuit:

This article is going to focus on electromechanical relays used as signal (to interface with a microprocessor) and power (to interface with motors) relays in a circuit.
Brief Introduction
The schematic of a electromechanical relay is below. Briefly, it has two parts, a coil one one side (primary circuit) and a switch on the other side (secondary circuit). When the coil is energized (red color) it creates a magnetic field that attracts the switch. When there is no energize (black color) on the coil, the switch goes back to it's initial position.

You can see a transparent relay working below. Pretty cool 🙂

Functions of Relays
- Galvanic separation of the primary circuit (actuator) and secondary circuit (load)
- Separation of different load circuits for different types of secondary circuits (different types of switches)
- Separation of AC and DC circuits
- Interface between electronic and power circuits
- Multiple switch operations (e.g.: time delays, signal condition)

According to the schematic above, this electromechanical relay will have a total of 5 pins. 2 pins for the control side (the coil) and 3 pins for the other side (the switch). However relays might have more or less pins depending on the type of switch used.
Secondary Circuit (Switch Side)
There are 4 types of switches:
- SPST (Single Pole Single Throw)
- SPDT (Single Pole Double Throw)
- DPST (Double Pole Single Throw)
- DPDT (Double Pole Double Throw)

Recognizing the type of switch that the relay is using, helps understanding the pinout and how the relay works. It also helps selecting the right relay for your application.
For example, for the relay presented in the introduction section we are dealing with a SPDT relay.

Since the switch side is normally connected to a higher voltage, when selecting a relay make sure that this part of the relay can handle the required maximum voltage and current otherwise you will destroy the switch.
Mechanical relays are the oldest type of relays, but they are still being used.
Advantages
- They are simple in construction
- They are reliable
- No specific programming device is required
- People can understand these relays easily
Disadvantages
- This type of relays require to be maintained periodically. Over time, the springs and the linkages inside the relay grow weak which can result in maloperation and false trips.
- No directional feature
- The speed of operation is limited by the mechanical inertia of the moving components
Speed of Operation
To understand the speed of operation of a mechanical relay, let's study a common electrotechnical relay used with a lot of microprocessors online (in specific with Arduino boards).

To make things simple, I am going to simplify the switch diagram of the relay and represent it as SPST instead of a SPDT.

How fast can you toggle the primary circuit (S1) which in turn controls the secondary circuit (S2)?
According to the datasheet the max on/off switching times are 5Hz mechanically and 0.5Hz electrically. So we are limited electrically how fast we can turn on/off this switch.
Note: 300 operation/min = 300/60 = 5 operation/sec = 5Hz

What if the datasheet doesn't give any switching values or you would like to model your circuit in a bigger schematic and include these switching times in the circuit? We need to model the circuit.
Nominal Current (at DC)
Since coils are made of wires, they have an internal resistance associate with it. Let's model the primary side of the relay with the following circuit:

For this relay, the coil has different resistances depending on the operating voltage.

When the switch is closed for a long period of time (DC conditions), the inductor acts like a short circuit.

The circuit becomes a simple resistor in series with the voltage source. Applying ohm's law to find the current in the circuit you get the nominal current values on Table 6 of the datasheet.
Example: with a coil voltage of 12V, you have a 320 ohm resistance. The nominal current in the circuit at DC is
Switching Times (Transient)
Ok, at DC things are easy to calculate but how do we model the transient of this circuit (opening and closing of the switch).
The model that we are using is a simple RL circuit. An RL circuit as the mathematical expression below, where t is going to be related with the switching times that we are trying to model.
i(t)=i(\infty)+(i(0)-i(\infty))*e^{-\frac{t}{\tau}}
Note: If you are curious where this equation is coming from, you can find that information in any circuits book or on this online course under "Write the differential equation governing RC and RL circuits".
is the current in the circuit after closing the switch and waiting for the circuit to be steady. In this case will match the value that we calculated for the nominal current before = 37.5 mA.
is the current in the circuit before closing the switch, which in this case will be equal to zero.
is called time constant and it is equal to
.
Let's plug the values that we have so far and see what parameters are we missing:
i(t)=37.5+(0-37.5)*e^{-\frac{320t}{L}} (mA)
Simplifying the equation to:
i(t)=37.5(1-e^{-\frac{320t}{L}}) (mA)
Remember that we are trying to find a value of t that relates with how fast the relay can operate. We can't plot this equation yet because we are missing 3 parameters, i(t), t and L. However, if we find the value of L, we can plot and i(t) and start understanding the dynamics of the relay.
Unfortunately, there is no L information on the datasheet but we can try and measure the L using an RCL meter. There is a lot that goes into measuring inductors, but we are going to keep things simple for now and get a value to work with.
In the lab, we have two RCL meters, a vintage Fluke PM6303 and the Keysight E4980AL.
Fluke PM6303
- The vintage meter is very easy to use but it has the limitation that the user cannot apply different voltages or frequencies to the externals components, in this case the coil of the relay.
- From the datasheet, this meter measures everything at 1kHz and 2V rms.

- Measuring the coil of the relay with this meter we get an L = 61.64 mH.

Keysight E4980AL
- On the other hand, the Keysight meter is a bit more complex to operate but the user has a lot more control on what it can measure.
- Setting the same frequency and voltage used with the Fluke meter, we get an L = 64.42 mH.

I am going to use the average value between these two measurements (L = 63 mH) and plug that value in the equation below:
i(t)=37.5(1-e^{-\frac{320t}{0.063}}) (mA)
Let's plot i(t) and see what we get:
Ok, we have a plot now but which value of current is important to us? Normally, we would look at when the current in the coil is at 90% of the final value (33.75 mA) which will give us a t = 0.4425 ms. However, the datasheet actually provides a minimum amount of current i(t) needed to trigger the switch.
If you go to Table 3 on the datasheet, you can find a coil sensitivity parameter.

We can use the power equation to find the minimum amount of current needed to trigger the coil at 12V.
P=V*i(t) \longrightarrow i(t)=\frac{0.36}{12}=30 mA
According to the plot, the relay takes t = 0.32 ms to reach 30 mA. This is super fast (around 3.125 kHz), way higher than the 0.5 Hz switching electrical time from the datasheet.
Some of the reasons why the manufacture recommends operating at much lower switching rates is because:
- Mechanically the switch can't switch that fast;
- And the mechanical parts of the switch will ware and tare over time, so if we operate at much lower speeds the relay can be used for longer.
Primary Circuit (Coil Side)
If you are connecting a relay to a microprocessor, you need to pay attention to the amount of voltage and current needed to operate the coil on the primary side of the relay.
Typically, microprocessors pinouts output voltages between 3.3 to 5V and around 20 mA of max current per output pin (best case scenario).
For example, the relay used during the "Speed of Operation" section can work at 3 and 5V. At these voltages the minimum current to trigger the coil is 120 mA and 72 mA respectively.
Note:
A microprocessor will not be able to handle this task. This is not TTL friendly relay.

Even if, the relay is TTL friendly and can provide the required voltage and current, you need to pay attention to something called back EMF. Back EMF can destroy your microprocessor or electronics around the relay. Avoid connecting the relay directly to the microprocessor pins without including an important component - a diode.

If the relay needs more current to activate the coil than the microprocessor pinout can give, or the voltage is higher than 5V, we need to build a logic level driver to interface between the microprocessor and relay.

Back EMF
In the previous section we saw that we need to pay attention to something called back EMF and we should include a diode in the circuit. Let's explore this back EMF a bit more and understand what is going on with coils that have energy and the current gets interrupted abruptly.
Back EMF stands for back electromotive force and it is present in any system that has inductors (e.g.: coils, relays, motors, RLC circuits). Before talking about back EMF let's briefly cover some fundamental concepts of electromagnetism first that will help understand back EMF later.
Fundamental Concepts
Electric and Magnetic Field
Every time you have an electric field you induce a magnetic field and vice versa.

You can verify this statement with a simple experiment. Place a compass under a wire, and close that wire in a loop with a battery. As soon as you close the circuit, there is a magnetic field induced in the wire that makes the needled in the compass move. The "Current-carrying straight wire" diagram above is the abstract representation of this experiment.

Falstad has a wonderful 3-D Magnetostatics Fields Applet that I am going to use to help visualize and understand some of these concepts from now on 🙂
I can use the applet to visualize this "Current-carrying straight wire" diagram (Link).

Inductors
If you pick up a wire and you start coiling the wire, you create an inductor. You can coil the wire around a central core (iron) or air. To abstract this representation we use the "Solenoid" diagram

Note: All solenoids are inductors, but not all inductors are solenoids. Typically, solenoids are used to create a magnetic fields, and inductors are used to regulated current and store magnetic energy. For this article I will use those two terms interchangeably but have in mind that there are differences between them.
How is a wire storing energy just by coiling it?
Let's use the applet to visualize this "Solenoid" diagram. First I am selecting the solenoid model and make the solenoid as a straight line as I can (Link). The magnetic fields around the wire are not as perfect as "Current-carrying straight wire" diagram but good enough to show that this representation is close to the straight wire diagram.

Let's start by coiling the wire to have # 1 turn (Link) and see what happens to the magnetic field around the wire. All I am doing is to decrease the height of the wire and increase the diameter of the coil, keeping the # of turns = 1.

We see that the magnetic fields around the wire start affecting each other and the overall magnetic field is taking a new shape. We also see that the magnetic fields that were spread around the wire start to concentrate around the coil.
If we now increase the # of turns, we will get the final result of a magnetic field around a solenoid (Link). We see that the magnetic fields that were spread along the straight wire are now concentrated around the loops.

And that is how a solenoid or inductor stores energy in a magnetic field. The more turns you have, the more magnetic fields are concentrated around the loops, the more energy you can store.
There is another way to visualize this same concept. If we pick up the straight line and instead of coiling it, we make a close loop with it, we create the "Current Loop" diagram (Link)

When we start bringing more current loops together, we can see the magnetic fields combining and getting stronger.

If we add more loops we strengthen the magnetic field and we the same final result.

Faraday's Law - EMF
Now that we understand the magnetic fields around an inductor, there is a way to relate all these concepts in a mathematical way.
Faraday's law of induction is a basic law of electromagnetism predicting how a magnetic field will interact with an electric field to produce an electromotive force (EMF), a phenomenon know as electromagnetic induction.
If we go back to the "Current Loop" diagram, that contains a wire in a closed loop and respective magnetic field lines, with set of experiments Faraday was able to relate the electric with the magnetic field in an elegant way.

The equation below, seems intimidating at first, but if you take the time to relate the equation to the abstraction diagram, things start to make sense.

The left side of the equation looks at the electrical field.
- Adds all the electrical fields over a closed path. The closed path is represented with the line integration symbol
. - The electrical fields of interest are the ones perpendicular to the closed path, represented by the dot product between E and dl.
- The result of this integration is also called voltage (V) and if the magnetic field is being generated by a varying magnet, than it is traditionally called an electromotive force (EMF).

The right side of the equation looks at the magnetic field.
- Adds all the magnetic fields over a surface, created by the closed loop. The surface of the closed loop is represented with the integration symbol
. - The magnetic fields of interest are the ones perpendicular to the surface, represented by the dot product between B and unit vector n.
- The derivative is there to indicate that you only get a result if there is a change on the magnetic field. If the magnetic field is not moving, this side of the equation is zero.
- The result of this integration gives you a negative result of the left side of the equation, in this case a negative EMF, or the famous back EMF.
Faraday's Law can be written in an alternative form:

We are now in good shape to start understanding why is back EMF important in circuits that have inductors.
On the "Faraday's Law - EMF" section, I explained the equation that relates the magnetic and electrical field on a closed loop wire.

We know that:
\oint_{C}^{}\overrightarrow{E}\circ d\overrightarrow{l}=EMF
Then
EMF=-EMF
Let's go back to the relay circuit that we have been studying in this article. When we close switch S1 the EMF on the relay is the voltage around the coil, which in turns creates a back EMF that will be stored in the magnetic field of the coil

EMF=V_L=L*\frac{d}{dt}i_L(t)
We can rewrite Faraday's Law as:
V_L=-EMF

Note:
, where


Since you interrupt the circuit that energy needs to go somewhere. Now I hope you understand why the connection below is not recommended.

When the microprocessor stops energizing the coil, the back EMF stored in the coil needs to go somewhere. Since back EMF reverses the polarity of the initial voltage, you have a negative potential connected to the microprocessor pinout. Recipe for disaster.
Common Circuit Protection
One way to protect your circuit is to connect a diode in parallel with the coil, in a way that when the microprocessor turns on the coil, the diode is not conducting, and when you turn off the coil the back EMF flows through the diode. That is a basic protection mechanism when you have inductors in your circuits

Relay Drivers
I think we have all the necessary knowledge to either build or go online and look at some schematics that have relays and understand how they work.
Custom Relay Driver (with BJT)
We can build our own relay driver and keep things relatively simple. If the nominal current on the coil is less than 100mA (assuming that the relay is operating at 12V), you can use an off the shelf transistor like the 2N2222A (datasheet) that can handle a continuous collector current of 600mA. However, you should pay attention if you need heatsinks around or not to dissipate the heat.

Example
The Songle SRD-SL-C model relay has a nominal current of 37.5mA at 12V, the total power dissipated by the transistor will be

On the 2N2222A datasheet we see that the transistor, operating at ambient temperature of 25 degrees Celsius, can handle up to 625mW (outside the package) and 1.5W (inside the package). In this case we are safe to use the transistor without heatsinks.
Simulation (Link)

Note: the relay circuit on the simulation, is not the Songle SRD-SL-C model. It is a random relay from Falstad to show the concept of operation.
Custom Relay Driver (with MOSFET)
If your relay uses a continuous current that makes the BJT require a heatsink, you should use a power MOSFET instead (for example the IRF630). The driver circuit is relatively identical, with some minor adjustments, since the MOSFET operates with voltage rather than current. The power MOSFET should also be TTL friendly, meaning the voltage to turn on/off the MOSFET should be between 3V to 5V.
You also need to pay attention if the power MOSFET needs heatsink or not. You can follow an example on how to perform those calculations on this article under the "Design" section.
Simulation (Link)

HiLetgo Relay
The HiLetgo relay uses the Songle SRD-SL-C model that I introduced during the "Speed of Operation" section. Since this relay can operate between 3V to 12V, the PCB board includes a level circuit driver to make the module flexible to interact with.


Relay Circuit:
The PCB board includes a diode (D1) across the primary circuit of the relay to protect the rest of the circuit from back EMF. The secondary circuit is a SPDT switch. The LED (D3) indicates when the coil is energized or not.

Driver Circuit:
The driver circuit has an optocoupler that allows turn on the relay with a high or with a low IN voltage. It has a PNP transistor to drive the coil with the required current and the LED (D2) indicates if you have power in the circuit.

Connection with a microprocessor:

On the secondary side of the relay circuit, connect your load according to the desired behavior:
- If you want the load to start with a open circuit, connect the load to the NO pin
- If you want the load to start with a closed circuit, connect the load to the NC pin.
On the microprocessor side, you need to pay attention to how the driver circuit works.
Driver Circuit Simulation
In order to understand the behavior of the driver circuit, let's simulate the optocoupler with the jumper and the microprocessor. I will simulate the full circuit later.

Falstad as an optocoupler module but it has only one LED inside, rather than two. But since we are just try to understand which of the LED's is working for different jumper configurations, using two diodes is sufficient to understand concept of operation.
Jumper on the High Setting (Link)
There is only one diode conducting at the time. On this setting, the diode on the left is going to turn on/off depending on the output pin state of the microprocessor. In this setting, the D+ pin can be connected to 12V and have the relay working at a higher voltage.

Jumper on the Low Setting (Link)
On this setting, we need be more careful on which voltages we pick for D+. For example, if D+ is left connected to 12V, the diode on the right will always be on.

For this setting, D+ needs to be always equal to the output voltage of you microprocessor, otherwise the diode will never turn off.

Full Simulation (Link)
Since the optocoupler in Falstad only has one LED, I will be setting the jumper to the low side so we can simulate the full circuit accordingly.

Gravity: Digital 5A Relay
References
- [REF 1] "Interface One Channel Relay Module with Arduino", Last Minute Engineers [Article]
- [REF 2] "Types of Switches – Special Applications by Touch Control", Wat Electronics [Article]
- [REF 3] "Different Types of Relays, Their Construction, Operation & Applications", Electrical Technology [Article]
- [REF 4] "A Student's Guide to Maxwell's Equations", Daniel Fleisch [Book]