Controlling an AC Load from a Microcontroller: An Introduction to Relays
Songle 5V Relay Available in LCSC

Controlling an AC Load from a Microcontroller: An Introduction to Relays

Picture this, you have a great idea for an IOT project which involves making your electronically challenged home appliance smarter. However, you come across an obstacle, your microcontroller's 5V or 3.3V DC output is incompatible with mains 110VAC or 230VAC. You need a component that can somehow interface between the two while providing isolation between AC and DC voltages. This component is known as the relay which comes in two main varieties, electromechanical and solid-state relays.

Solid State Relays

Article content
Figure 1: A solid State Relay from Finder
Article content
Figure 2: Schematic symbol of a solid state relay

Solid state relays (SSR) operate on the same principle as optocouplers, they contain an infrared LED which is turned on by the low voltage side (the microcontroller). This LED activates a photodiode or a photo transistor which switches on the high voltage circuit. This kind of setup benefits from the galvanic isolation between the low voltage and high voltage sides. SSRs are beyond the scope of this article. Feel free to learn about them here.

Electromechanical Relays

Article content
Figure 3: A popular electromechanical relay
Article content
Figure 4: Schematic symbol of an electromechanical relay

Electromechanical relays on the other hand are electromagnetism-based. A coil wound around an iron core creates an electromagnet when energized by a low current. The resultant magnetic force moves a contact which closes or opens the high voltage circuit. Electromechanical relays are typically cheaper than SSRs but SSRs are smaller and, due to lack of moving components, live longer (Storr, 2022b). Electromechanical relays are susceptible to the arcing effect especially with inductive loads. The arcing effect not only degrades the connectivity of contacts overtime, but it can also weld them.

Article content
Figure 5: An example of arcing effect on a relay's contact (TE Connectivity, 2020b)

Parameters:

Relay G5LE-1 DC5 will be used as an example throughout this article. To choose a relay for our application, we must understand the relay's parameters.

Mounting Style and Size:

Relays come in a variety of mounting styles. Two popular styles are DIN rail mounted relays which are mostly used in control panels and systems, and PCB relays such as the example relay. Some are designed to be mounted on sockets. Remember to ensure that the size fits your application.

Environmental ratings:

To ensure reliability, the relay must be selected to withstand the weather conditions in its installation site. The first environmental rating is the maximum or minimum operating temperature. Our example relay can be operated between -25C and 85C making it suitable for outdoor use if enclosed properly. The second environmental rating is humidity. Care must be taken to protect the PCB or the system as a whole from humidity because even if the relay can withstand it, it might cause short circuits between the pins.

Coil Ratings:

The coil's voltage rating is the voltage it is meant to be operated at. Typical voltages are 3V, 5V, 12V, and 24V. Some relays are designed with AC coils, they are typically more expensive and are usually used for indication purposes. The coil's power/current rating or resistance is used to determine the energy required to operate the coil. The example relay has a current rating of 79.4 mA. Quite strangely, the datasheet neglects to mention an existing model which is G5LE-1 DC3 however, the current requirement can be easily obtained using the coil's power consumption of 400 mW which is constant across all models to obtain a current rating of 133mA.

Article content
Figure 6: Temperature derating chart in the datasheet (Omron Corporation, n.d.)

Note how the datasheet includes a chart illustrating how temperature derates the maximum coil voltage. At 60C, the coil voltage may not go above 150% of the coil's voltage rating even if for a short duration.

Contact Ratings

Article content
Figure 7: Current and durability derating with contact voltage (Omron Corporation, n.d.)

The contact's voltage and current ratings are not to be exceeded when connecting an AC power supply. In fact, according to figure 7, the contact's current rating derates as the contact's voltage increases. Operation cycles also derate with increasing voltage. The example relay is not suitable for use with 220-230V which is common in many countries. It is worth noting that relays include two different current ratings. One is for resistive loads which is higher, and the other for inductive loads such as motors.

Relay Circuit Design

Circuit 1

Article content
Figure 8: The GPIO pin directly powers the coil

Illustrated above in figure 8 is a circuit in which the microcontroller's GPIO pin directly powers the relay's coil. Our example relay draws approximately 80mA of current at 5V. Typical microcontroller GPIO pins supply no more than 20mA of current. The best-case scenario in this circuit is that the relay will not operate. while the worst-case scenario is that the GPIO pin if not the whole microcontroller will be fried.

It is apparent that another component is needed to interface between the microcontroller and the relay. A component which can operate with the little current that a GPIO pin can provide and switch a higher current. This component is either a transistor or a an optocoupler.

Circuit 2

Article content
Figure 9: A transistor drives the relay.

In this circuit, the transistor acts as an electronic switch to drive the relay. The transistor must be sized such that the following:

  • Its voltage rating is at least double the coil's voltage rating.
  • Its current rating is also double the coil's operating current.
  • Its gate/base can be operated by the microcontroller. The gate in an N-channel MOSFET must have a minimum threshold voltage much less than the GPIO pin's output voltage. If the transistor is a BJT, the base current provided by the microcontroller must be enough to saturate the transistor.

Assume that the transistor was enabled by the GPIO pin then switched off. What will the transistor's current state be? Will the gate's charge remain leaving the transistor switched on? or will the gate discharge switching off the transistor. This is the purpose of adding a pull-down resistor connected to the gate. It ensures that the transistor is always at a known state. (Storr, 2022a)

What if the coil is switched off while it is energized. The relay's coil is essentially an inductor, it stores energy in its magnetic field. If the circuit is switched off abruptly. The coil will attempt to push current through thereby increasing its voltage which may break the transistor. A surge protection component must be added to the driver circuit to safely discharge the coil's energy without damaging the transistor. This component is a flyback diode.

Circuit 3

Article content
Figure 10: A flyback diode is added parallel to the coil.

Just like the transistor, the diode must be sized appropriately with respect to the coil:

  • The diode must be reverse bias with respect to VCC. This creates a path for the current to flow in the same direction after the transistor is switched off.
  • The diode's voltage rating must be higher than the coil's voltage rating. The recommended value is twice the coil's voltage.
  • The diode's current should also be double the coil current rating or at least higher.

How does the diode affect the relay besides adding the aforementioned path? Relay contacts will experience the arcing effect during de-energization and small tack welds may form intermittently. If the contact's movement is fast enough, these welds may be broken off easily. The observed effect of adding diodes for surge protection is that they slow down discharging the coil. This in turn slows down the contact's movement which prolongs the arcing effect and suppresses the contact's ability to break the tack welds. At some point, this may lead to permanently welding the contacts as discussed earlier. This situation can be improved with the addition of a single component to the driver circuit.

Note: The negative effects above apply to normally open contacts only, normally closed contacts benefit from slow contact speed because it reduces contacts bouncing while closing.

Circuit 4

Article content
Figure 11: Zener diode added in series with the flyback diode.

Adding a Zener diode can improve the speed of discharging the coil's energy. The diode's purpose in this case is to avoid forward biasing the Zener diode thus restricting the current flow to one direction. Another option is to have the Zener diode parallel to the transistor, but the first option is better because the Zener diode is closer to the coil.

  • The Zener diode's working or nominal voltage must be slightly higher than the coil's voltage rating.
  • The Zener diode's current rating must be higher than the coil's current.

Other surge protection mechanisms exist such as using a varistor parallel to the coil or a diode in series with a resistor, but the solution presented in circuit 4 was cited as a good balance between performance and cost. (TE Connectivity, 2021)

Note: The solution in circuit 4 applies to DC coils. For AC coils, using a varistor is recommended. (TE Connectivity, 2021)

PCB Layout

Proper placement and routing of the relay is as important as designing its circuit. The following recommendations must be considered:

  • Assuming that the relay's contact switches mains AC voltage, ensure that the board is segregated into AC and DC sections. This minimizes potential interference with the DC side and eases complying with creepage requirements.
  • Place the relay such that its coil is in the DC section while its contact is in the AC section.
  • Avoid extending the ground plane underneath the AC section of the PCB. This violates the creepage requirements resulting in the AC voltage arcing into the ground plane. (Altium Designer, 2017)

Article content
Figure 12: Notice how pin 1 is located beyond the coil's pins 2 and 5.


Some SPDT relays are packaged oddly such that one of their contact pins is on the coil's side. This makes PCB layout challenging because the pin is within the DC section. Avoid these relays if possible and ensure enough clearance between the contact pin and other DC circuitry.

Safety

Considering that relays are typically used to control AC loads. Exercise great caution while installing the relay. Ensure that power is isolated while working on your electronic device and insulate the AC conductors to avoid shock. Follow IPC-2221 with regards to PCB design and IEC-60950-1 for power supply safety requirements. (Altium Designer, 2017)

Contactors

Article content
Figure 13; Schneider modular contactor

It can be deduced from the information above that relay's performance worsens with high power inductive loads such as pumps or compressors. It is recommended to use contactors instead in these applications. Contactors are essentially rugged relays with stronger contacts built to withstand higher powers (RS, 2021). Contactors are commonly found in DIN rail mounted packages such as the one in figure 13 or chassis mounted varieties. Contactors typically require higher coil voltages than relays thus, you may need a relay, an SSR or at the very least a transistor to operate a contactor. At the time of writing this article, no PCB mounted varieties were found.

Conclusion

With this article, you, hopefully, learned how to select a relay for your application, how to design a circuit around it, and other considerations that drive your decisions. SSRs generally follow similar principles in selecting and designing them but they deserve their own article. Please, consider sharing this article if you found it useful.

References

Altium Designer. (2017, August 11). High voltage PCB design: Creepage and clearance distances for high voltage. Altium. https://resources.altium.com/p/high-voltage-pcb-design-creepage-and-clearance-distance#creepage-vs-clearance

Gust, B. (2020, August 5). Component options for relay coil surge suppression. TechForum │ Digi-Key. https://forum.digikey.com/t/component-options-for-relay-coil-surge-suppression/7789

Omron Corporation. (n.d.). Cubic, Single pole 10A Power Relay Datasheet. Omron. https://components.omron.com/us-en/sites/components.omron.com.us/files/datasheet_pdf/K100-E1.pdf

Panasonic Industry. (2020, April 15). Protecting a Relay Coil from a Surge. https://ac-blog.panasonic.com/relay/protecting-a-relay-coil-from-a-surge

RS. (2021, October). A Complete Guide to Contactors. RS. Retrieved September 2, 2023, from https://uk.rs-online.com/web/content/discovery/ideas-and-advice/contactors-guide

Storr, W. (2022a). Relay Switch circuit. Basic Electronics Tutorials. https://www.electronics-tutorials.ws/blog/relay-switch-circuit.html

Storr, W. (2022b, August 2). Solid state relay. Basic Electronics Tutorials. Retrieved September 2, 2023, from https://www.electronics-tutorials.ws/power/solid-state-relay.html

TE Connectivity. (2020a, September). Coil Suppression Can Reduce Relay Life. Retrieved September 2, 2023, from https://www.te.com/commerce/DocumentDelivery/DDEController?Action=srchrtrv&DocNm=13C3264_AppNote&DocType=CS&DocLang=EN

TE Connectivity. (2020b, September). Contact arc phenomenon. Retrieved September 2, 2023, from https://www.te.com/usa-en/products/relays-contactors-switches/relays/intersection/contact-arc-phenomenon.html?tab=pgp-story

TE Connectivity. (2021, September). Relay Coil Suppression with DC Relays. https://www.te.com/usa-en/products/relays-contactors-switches/relays/intersection/relay-coil-suppression-dc-relays.html?tab=pgp-story

We often give relays to our customers and use them more.

Like
Reply

And do not that DC voltage is often limited to 30Vdc if you want to do some serious currents.

Boa tarde! Show de bola, você é excepcional.

Here important point is Which type of load you connect to relay so Relay rating decide.

To view or add a comment, sign in

More articles by Kadhem Alabdulmuhsin, CPCD

Others also viewed

Explore content categories