Back to Sensors & Actuators Series

Relays: Mechanical, SSR & Contactors

April 10, 2026 Wasil Zafar 17 min read

The essential power switching actuator — safely controlling high-voltage loads from low-voltage microcontrollers. Master relay types, driver circuits, safety practices, and practical embedded code.

Contents

  1. Overview & Types
  2. Working Principle
  3. Electrical & Mechanical Specs
  4. Driver Circuits
  5. Control Methods
  6. Code Example — Arduino & ESP32
  7. Real-World Applications
  8. Advantages vs. Alternatives
  9. Limitations & Considerations

Overview & Types

Relays are electrically-operated switches that use a small control signal to switch much larger loads. They provide galvanic isolation between the control circuit (microcontroller) and the power circuit (motors, heaters, mains voltage), making them essential safety components in any embedded system that controls high-power devices.

Key Insight: A relay is essentially a solenoid-operated switch. The control coil creates a magnetic field that mechanically moves a contact arm, connecting or disconnecting the load circuit. This physical separation means a 3.3 V microcontroller can safely control a 240 V appliance.

Types

  • Electromagnetic Relay (EMR): Traditional mechanical relay with a coil, armature, and metal contacts. Audible click, handles AC or DC, withstands surges. Typical: SRD-05VDC-SL-C (5 V coil, 10 A contacts).
  • Solid State Relay (SSR): Uses semiconductor switching (TRIAC for AC, MOSFET for DC). No moving parts → silent, no contact bounce, millions of cycles. Typical: SSR-40DA (40 A, 3–32 V control, 24–380 V AC load).
  • Reed Relay: Glass-enclosed reed contacts activated by an external coil or permanent magnet. Very small, fast switching, low contact current (0.5–1 A). Used in test equipment and signal routing.
  • Contactor: Heavy-duty relay for high-power switching (10–1000+ A). Used in motor starters, EV battery disconnects, and industrial power distribution.
  • Latching Relay: Maintains contact position after the control signal is removed. A pulse sets, a reverse pulse resets. Zero holding power — ideal for battery-powered applications.

Working Principle

Electromagnetic Relay

  1. Coil Energized: Current through the coil creates a magnetic field that attracts the armature (pivoting metal arm).
  2. Contact Closure: The armature moves, pressing the NO (Normally Open) contacts together and separating the NC (Normally Closed) contacts.
  3. Load Circuit Complete: Current flows through the closed contacts to the load.
  4. Coil De-energized: Spring returns the armature, NO contacts open, NC contacts close.

Solid State Relay

  1. Control Signal: A small DC voltage (3–32 V) activates an internal LED inside an optocoupler.
  2. Optical Isolation: The LED light triggers a photodetector, providing galvanic isolation (typically 4 kV).
  3. Load Switching: The photodetector drives a TRIAC (for AC) or MOSFET (for DC) that connects the load circuit.
  4. Zero-Cross Switching: AC SSRs typically switch at the zero-crossing point of the AC waveform, minimizing electromagnetic interference.

Contact Configurations

TypeAbbreviationDescriptionUse Case
SPST-NOForm A1 pole, normally openSimple on/off switching
SPST-NCForm B1 pole, normally closedFail-safe circuits
SPDTForm C1 pole, NO + NC (changeover)Most common; select between 2 circuits
DPDT2 × Form C2 independent SPDTMotor direction reversal, dual-circuit switching

Electrical & Mechanical Specifications

ParameterEMR (5V module)SSR (AC)SSR (DC)Contactor
Coil/Control Voltage5 V DC3–32 V DC3–32 V DC24–240 V AC/DC
Coil Current70–90 mA7–20 mA7–20 mA50–500 mA
Contact Rating10 A @ 250 VAC10–100 A @ 380 VAC10–60 A @ 60 VDC9–1000 A
Switching Speed5–20 ms<1 ms (at zero-cross)<1 ms30–100 ms
Isolation1.5–5 kV2.5–4 kV2.5–4 kV2–5 kV
Contact Bounce1–5 msNoneNone5–20 ms
Lifespan (cycles)100K mechanical / 10K electricalUnlimited (no contacts)Unlimited1M mechanical
Quiescent Power350–450 mW~50 mW~50 mW5–50 W

Driver Circuits

Relay Module (Plug-and-Play)

Most hobby relay modules include the driver transistor, flyback diode, LED indicator, and screw terminals. Just connect VCC (5 V), GND, and signal pin (active LOW on most modules).

Discrete Driver (NPN + Flyback)

For bare relays: NPN transistor (2N2222 or BC547) or N-channel MOSFET, base/gate resistor (1k–10k), and flyback diode across the coil.

SSR Wiring

SSRs have 4 terminals: control + and − (DC input), load terminals (AC/DC output). Wire in series with the load. No flyback diode needed.

Mains Voltage Safety: When switching mains voltage (120/240 VAC), use proper insulation, creepage distances, and enclosed housing. Never touch connections when powered. Use fuses and test with low voltage first. Consider SSRs for sealed, safe operation.

Heat Sinking for SSRs

SSRs have a voltage drop across the switching element (1–1.6 V for TRIAC, 0.1–0.5 V for MOSFET). Power dissipation = Vdrop × Iload. At high currents, this requires a heat sink. A 40 A SSR at 30 A load dissipates ~48 W!

Control Methods

Direct GPIO Drive (Relay Module)

Most relay modules are active LOW — connect control pin directly to GPIO. Pull-up during boot to prevent relay toggling during microcontroller reset.

PWM Dimming (SSR + AC)

Zero-cross SSRs can implement phase-angle control for AC dimming (heaters, incandescent lights). Cycle-skipping at low frequencies controls average power.

Multi-Relay Sequencing

When switching multiple relays, stagger activation to avoid simultaneous inrush current. Add 50–100 ms delays between relay activations.

Watchdog / Fail-Safe

For critical applications, use NC contacts so the load is energized by default and the relay de-energizes (opens) only when the controller is active. If the controller crashes, the relay returns to the safe (NC) state.

Code Example — Arduino & ESP32

Arduino: 4-Channel Relay Control

// 4-channel relay module control on Arduino
// Wiring: Relay IN1-IN4 → D4-D7 (active LOW), VCC→5V, GND→GND

const int RELAY_PINS[] = {4, 5, 6, 7};
const int NUM_RELAYS = 4;
const char* labels[] = {"Light", "Fan", "Heater", "Pump"};

void setup() {
    Serial.begin(9600);
    for (int i = 0; i < NUM_RELAYS; i++) {
        pinMode(RELAY_PINS[i], OUTPUT);
        digitalWrite(RELAY_PINS[i], HIGH); // HIGH = OFF (active LOW)
    }
    Serial.println("Relay Controller Ready");
    Serial.println("Send: 1-4 to toggle relay");
}

void setRelay(int index, bool on) {
    if (index < 0 || index >= NUM_RELAYS) return;
    // Active LOW: LOW = ON, HIGH = OFF
    digitalWrite(RELAY_PINS[index], on ? LOW : HIGH);
    Serial.print(labels[index]);
    Serial.println(on ? ": ON" : ": OFF");
}

void loop() {
    if (Serial.available()) {
        int cmd = Serial.parseInt();
        if (cmd >= 1 && cmd <= 4) {
            int idx = cmd - 1;
            // Toggle current state
            bool currentState = (digitalRead(RELAY_PINS[idx]) == LOW);
            setRelay(idx, !currentState);
        }
    }
}

ESP32: SSR with Temperature-Based Control

// ESP32 controlling SSR for heater with temperature feedback
// Wiring: SSR control→GPIO25, Thermistor→GPIO34(ADC)

#include <Arduino.h>

#define SSR_PIN       25
#define THERM_PIN     34
#define TARGET_TEMP   60.0  // Target temperature in Celsius
#define HYSTERESIS    2.0   // ±2°C hysteresis band

// Thermistor parameters (NTC 10k, B=3950)
const float SERIES_R = 10000.0;
const float NOMINAL_R = 10000.0;
const float NOMINAL_T = 25.0;
const float B_COEFF = 3950.0;

void setup() {
    Serial.begin(115200);
    pinMode(SSR_PIN, OUTPUT);
    digitalWrite(SSR_PIN, LOW); // Heater off
    analogReadResolution(12);
    Serial.println("SSR Heater Controller");
    Serial.printf("Target: %.1f°C ± %.1f°C\n",
                  TARGET_TEMP, HYSTERESIS);
}

float readTemperature() {
    int raw = analogRead(THERM_PIN);
    float resistance = SERIES_R / ((4095.0 / raw) - 1.0);
    float tempK = 1.0 / (
        (1.0 / (NOMINAL_T + 273.15)) +
        (1.0 / B_COEFF) * log(resistance / NOMINAL_R)
    );
    return tempK - 273.15;
}

void loop() {
    float temp = readTemperature();
    bool heaterOn = digitalRead(SSR_PIN);

    // Hysteresis control
    if (temp < TARGET_TEMP - HYSTERESIS && !heaterOn) {
        digitalWrite(SSR_PIN, HIGH);
        Serial.printf("HEATER ON  | Temp: %.1f°C\n", temp);
    } else if (temp > TARGET_TEMP + HYSTERESIS && heaterOn) {
        digitalWrite(SSR_PIN, LOW);
        Serial.printf("HEATER OFF | Temp: %.1f°C\n", temp);
    }

    Serial.printf("Temp: %.1f°C | Heater: %s\n",
                  temp, heaterOn ? "ON" : "OFF");
    delay(1000);
}

Real-World Applications

Home Automation

  • Smart light switches
  • Appliance control (fans, heaters)
  • Irrigation valve control
  • Garage door openers

Industrial & Automotive

  • Motor starters (contactors)
  • PLC output stages
  • Automotive starter motor relay
  • Battery management disconnect

Advantages vs. Alternatives

vs. ActuatorRelay AdvantageRelay Disadvantage
MOSFET (direct)Galvanic isolation, handles AC, surge tolerantSlower switching, contact wear (EMR), larger
SolenoidPure electrical switching, no mechanical outputCannot perform physical actuation
SSR vs EMREMR: zero on-resistance, handles surges, cheaper; SSR: silent, no bounce, longer lifeEMR: bounce, wear, noise; SSR: leakage current, heat, cost
Contactor vs RelayContactor handles 10–1000 A loadsLarger, more expensive, slower, louder

Limitations & Considerations

  • Contact Wear (EMR): Arcing at contact surfaces erodes material. Rated lifespan is typically 100,000 electrical operations. Exceeding rated load accelerates wear.
  • Contact Bounce (EMR): Mechanical contacts bounce for 1–5 ms when closing, causing brief on/off pulses. Not an issue for motors/heaters but can cause problems for logic circuits.
  • Coil Power (EMR): Standard 5V relay coils draw 70–90 mA — too much for direct GPIO drive on most 3.3V MCUs. Use driver transistor or relay module.
  • Leakage Current (SSR): SSRs have small leakage current (1–10 mA) when “off.” This can keep LED lights dimly lit or prevent full shutdown of sensitive loads.
  • Heat Dissipation (SSR): At high currents, SSR voltage drop creates significant heat. Derate current or add heat sink.
  • Inductive Load Suppression: When switching inductive loads (motors, solenoids), add snubber circuits (RC network across contacts) to suppress arcing and extend contact life.