> For the complete documentation index, see [llms.txt](https://monasheng.gitbook.io/zerotohero/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://monasheng.gitbook.io/zerotohero/arduino-zero-to-hero/advanced-skills/relays.md).

# Relays

While Arduinos can directly switch loads on and off using `digitalWrite()`, they can only handle those which have reasonable small current draws (i.e. $$10-20;\text{mA}$$ per pin continuously).

For larger draw devices, you will need an additional interfacing component to handle programmatic switching.

## Relays

Electronic relays (sometimes called *contractors*) are electromagnetic devices which allow you to operate a switch indirectly.

Relays have to separate and (usually) physically isolated sections:

1. An aptly-named *coil*, which consists of a large coil of wire, and,
2. A *contact*, which is a switch that can pivot to make or break a connection.

When a voltage is applied to the *coil* of a relay, current flows through it and it induces a magnetic field sufficient to attract or repel the *contact*. This means that the contact then can be used to make or break a circuit.

<figure><img src="/files/8B0lFeHcJC6PEiSmOYXn" alt=""><figcaption><p>When a voltage is applied to the coil (left), the induced magnetic field attracts and closes the contact (right). From: <a href="https://www.circuitgeeks.com/arduino-relay-tutorial/">https://www.circuitgeeks.com/arduino-relay-tutorial/</a></p></figcaption></figure>

Relays are quite useful as:

1. They provide a physical, *galvanic* isolation between the coil and the contact, meaning that the coil switching circuitry (including, potentially an MCU, or human-interface components) can be separated from the contact, which might contain dangerous high voltage or alternating current, and,
2. Potentially large currents seen by the contact need never be carried by the coil. This is useful where the coil switching circuitry (i.e. an MCU) is only capable of supplying small currents.

The current required to drive a relay *coil* depends on it's inherent resistance, and this varies depending on the amount of magnetism required to move the contact. For ordinary applications, is it possible to use relays with in the order $$\approx100;\text{mA}$$ coil current to switch up to $$\approx20;\text{A}$$ contact loads.

<figure><img src="/files/HfNjQGsONYRFWBysFdS1" alt=""><figcaption><p>The large-current-draw DC motor shown is connected to the 9 V battery via the contact of a relay. This contact is magnetically actuated when the current flows through the coil of the relay - achieved here by a <code>digitalWrite()</code> on the Arduino. In effect, the Arduino is switching the motor with no physical contact to it!</p></figcaption></figure>
