Atlas Robotics
Electronic ComponentsBasic

What is a relay? An electrically controlled mechanical switch that isolates 2 circuits

Atlasbot · 20/8/2026 · 9 min read

What is a relay? An electrically controlled mechanical switch that isolates 2 circuits
Relay uses electromagnetic force to open/close mechanical contacts

Transistors and MOSFETs (2 previous articles) are electronic switches, suitable for moderate current DC loads — but when it is necessary to turn on/off the 220V AC grid (eg: turn on/off a household appliance) or need complete electrical isolation between the control circuit and the load circuit, relay is a more suitable choice.

What is Relay and how does it work?

Relay is a mechanical switch that is opened/closed by electromagnetic force, consisting of 2 separate parts:

  • Electromagnetic coil (coil) — control side, when current flows through it creates a magnetic field.
  • Contact (contact) — load side, are metal foils that actually open/close mechanically, conducting the current of the load circuit.

When the coil is energized, the generated magnetic field attracts a metal bar (armature), causing the contact to change state. Because the contact is a purely mechanical metal connection, the load circuit (e.g. 220V AC) is completely electrically isolated from the control circuit (e.g. 5V DC from the MCU) — there are no semiconductor electronics in direct contact between the two.

NO and NC — two types of contacts

  • NO (Normally Open — normally open): contact is open when the relay has no power, closed when the relay is energized. This is the most common type of use — if you want to turn on the device, supply power to the relay.
  • NC (Normally Closed — normally closed): contact is closed when the relay has no power, open when the relay is energized — used when reverse logic is needed (eg: safety circuit needs to be automatically disconnected if control power is lost).

In short: Relay = mechanical switch controlled by electromagnetics, completely isolating the control circuit and load circuit — unlike transistors/MOSFETs, which still have a direct electronic connection between the two sides.

Why do we still need a transistor to control the relay from GPIO?

Relay coils typically require about 50-200mA to create a sufficient magnetic field — which exceeds the safe maximum current of most GPIO pins (typically 20-40mA). This is the reason why almost every relay control circuit from a microcontroller needs an intermediate transistor or MOSFET (mentioned in 2 previous articles) — GPIO controls the small current into the Base/Gate of the transistor/MOSFET, the new transistor/MOSFET actually supplies enough current to the relay coil.

Technical details

Formulas

The relay coil is essentially a resistor (winding resistance) - the current through the coil is calculated using the familiar Ohm's law, used to check whether the control transistor/MOSFET is capable of supplying current or not:

I(coil) = V(coil) / R(coil)

For example: a 5V relay has a coil resistance of 70Ω
I = 5V / 70Ω ≈ 71mA
→ The control transistor needs to withstand at least ~71mA at the Collector

Parameters

Coil resistance and contact rating vary according to supply voltage and relay model — always check the parameters printed on the relay case or datasheet:

Relay typeCoil resistanceCoil consumption currentTolerable contact current
Relay 5V (common module)~70-100Ω~50-70mA~10A @ 250VAC / 10A @ 30VDC
Relay 12V (common module)~360-400Ω~30-35mA~10A @ 250VAC / 10A @ 30VDC

Practical applications

Relays are often used on AMR robots to turn on/off high-power loads or voltages that are different from the control circuit — for example, turning on/off indicator lights, sirens, or switching the battery charging source when the robot automatically returns to the charging station. Because the relay contact is completely electrically isolated from the MCU circuit, using a relay here is much safer than connecting other voltage loads (eg, 220V AC for lights) directly into the same circuit as the sensitive 5V/3.3V microcontroller.

Most commercially available relay modules for Arduino/ESP32 have built-in control transistors and protection diodes on the board — just need to be powered and controlled with a regular GPIO pin:

const int RELAY_PIN = 7;

void setup() {
  pinMode(RELAY_PIN, OUTPUT);
}

void loop() {
  digitalWrite(RELAY_PIN, HIGH);  // Turn on the relay (depending on the module: HIGH or LOW will turn on, see more below)
  delay(1000);
  digitalWrite(RELAY_PIN, LOW);   // turn off the relay
  delay(1000);
}

Some cheap relay modules use active-low logic (the control pin is LOW to turn on the relay, contrary to common belief) — always check the documentation/actual testing of the correct module in use before assuming HIGH = on logic.

Common mistakes

  • Make your own separate relay circuit but forget the protection diode — the relay coil still creates a reverse voltage pulse when the current is interrupted like any other coil, see the article Diode — necessary if not using the built-in module.
  • Mistaken NO and NC pins when connecting the load — Wrong connection causes the on/off logic to be reversed compared to expectations, or the load is always on even when thought to be in the off state.
  • Use relays for applications that require high frequency switching — relays have mechanical delay (usually a few to a few tens of milliseconds) and a limited lifespan according to number of on/off times (usually hundreds of thousands to millions of times depending on the type) — not suitable for high frequency PWM or applications that need to continuously turn on/off thousands of times/second, should be used MOSFET/transistor for this case.
  • Mistake in the active-low logic of some cheap relay modules — the code is written correctly in the logic HIGH=on but the relay operates in reverse, easily mistakenly thinking the module is faulty when it's just a different logic convention.

Conclusion

Relays are the right choice when complete electrical isolation or switching on/off high voltage/AC loads is required — the trade-off is slower switching speed and limited mechanical life compared to purely electronic transistors/MOSFETs. The next article in the column is about the Optocoupler — another way to electrically isolate two circuits, but using light instead of mechanics, suitable for much higher switching frequencies.

Get new articles and lessons by email

When a new technical article or course module is published, Atlas Robotics sends you a short email. No spam.

Unsubscribe any time with the link in each email. See our Privacy policy.

What is a relay? An electrically controlled mechanical switch that isolates 2 circuits — Atlas Robotics