Built-in project · Arduino Uno R3

Solid-state relay on 24 V AC, on an Arduino Uno

An SSR-25DA on pin 7 switches two 12 V lamps on 24 V AC, on two seconds and off two: it turns on at a zero of the AC and off at the next current zero. The whole build, an Arduino Uno and 4 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Teaching? Assign it to your class in one click.

Intermediate About 20 minutes to build and run. Runs in your browser. Free, and no account needed.

The parts retail for about $34. On Mokxi they're free.

The circuit runs here once the page has loaded.

What you'll learn

  • Solid-state relays and how they switch AC
  • TRIACs turn off only when current crosses zero
  • Driving a relay input straight from a pin
  • Why an AC relay cannot switch DC
  • Wiring the load side separately from the control side
  • Difficulty: Intermediate
  • Time: About 20 minutes
  • Board: Arduino Uno R3
  • Parts: 4

How it works

A solid-state relay is a switch with no moving parts. Pin 7 drives its input directly, since the input is an LED that needs only about 7.5 mA. Its output side is a TRIAC that switches two 12 V lamps on a 24 V AC supply.

The sketch turns pin 7 on for two seconds and off for two seconds. A TRIAC turns on near a zero of the AC wave and only lets go at the next current zero, so there can be a short delay each way. That is also why this relay cannot switch DC.

Parts list

4 parts, plus the jumper wires and a bench instrument. The parts retail for about $34; on Mokxi they're free, and so are the instruments.

Wiring table

Every connection, pin by pin, read from the circuit itself. Each row joins the pin on the left to the pin on the right, by a jumper wire or a breadboard strip.

Part and pinConnects to
Solid-state relay, SSR-25DA / G3MB-202P pin 4Arduino Uno R3 pin GND
Solid-state relay, SSR-25DA / G3MB-202P pin 3Arduino Uno R3 pin 7
Filament lamp (2) pin 2Solid-state relay, SSR-25DA / G3MB-202P pin 1
Solid-state relay, SSR-25DA / G3MB-202P pin 2Ground
Signal generator pin GNDGround
Filament lamp (1) pin 1Signal generator pin OUT
Filament lamp (2) pin 1Filament lamp (1) pin 2

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Uno R3
// Solid-state relay: an Uno switches two 12 V lamps on a 24 V AC supply
// through an SSR-25DA, on for two seconds and off for two.
//
//   7       the SSR's input + (terminal 3), the Uno's GND to its - (4)
//   24 V AC the signal generator, a 60 Hz sine of 34 V peak (24 V RMS, a
//           sprinkler or doorbell transformer): OUT through the two lamps to
//           terminal 1, terminal 2 back to the generator's GND
//
// The SSR's input is an LED behind a current limiter, about 7.5 mA from
// 3 to 32 V, so a pin drives it with nothing in between. Its output is a
// TRIAC, and a TRIAC follows rules a relay contact does not:
//
// * it turns on only near a zero of the AC voltage, so it may wait up to a
//   half cycle (8.3 ms at 60 Hz) after the pin goes high;
// * once on it stays on until its current passes through zero, so it lets
//   go at the end of the half cycle it is in, not when the pin goes low.
//
// That second rule is why an SSR-25DA must not switch DC: a DC current never
// passes through zero, so once it is on it never turns off. Try it: replace
// the generator with a 12 V supply and watch the lamps stay lit.
//
// Press Run and watch the lamps and the serial monitor.

const int SSR_PIN = 7;
const unsigned long ON_MS = 2000;
const unsigned long OFF_MS = 2000;

void setup() {
  pinMode(SSR_PIN, OUTPUT);
  digitalWrite(SSR_PIN, LOW);
  Serial.begin(9600);
  Serial.println("SSR lamp switch");
}

void loop() {
  digitalWrite(SSR_PIN, HIGH);
  Serial.println("input on: the lamps light at the next zero");
  delay(ON_MS);
  digitalWrite(SSR_PIN, LOW);
  Serial.println("input off: the lamps go out at the next current zero");
  delay(OFF_MS);
}

Code walkthrough

The key functions of the sketch, and what each one does.

setup sketch.ino

Makes SSR_PIN an output and sets it LOW so the lamps start off. Then it opens the serial port and prints a title.

void setup() {
  pinMode(SSR_PIN, OUTPUT);
  digitalWrite(SSR_PIN, LOW);
  Serial.begin(9600);
  Serial.println("SSR lamp switch");
}

loop sketch.ino

Sets the pin HIGH and prints that the lamps light at the next zero. It waits ON_MS, 2000 ms, then sets the pin LOW and prints that they go out at the next current zero. It waits OFF_MS and repeats.

void loop() {
  digitalWrite(SSR_PIN, HIGH);
  Serial.println("input on: the lamps light at the next zero");
  delay(ON_MS);
  digitalWrite(SSR_PIN, LOW);
  Serial.println("input off: the lamps go out at the next current zero");
  delay(OFF_MS);
}

Troubleshooting

The usual mistakes with this circuit, and the fix for each.

  • The lamps never light This project
    The input uses terminals 3 and 4, and the AC supply and lamps go in series on terminals 1 and 2.
  • The lamps stay on with a DC supply This project
    This relay cannot switch DC. A DC current never crosses zero, so the TRIAC never lets go. Use an AC source.
  • The load stays on when the control signal is removed. Solid-state relay
    AC solid-state relays turn off only at a zero current crossing. On a DC load they never turn off. Use a DC output SSR (a MOSFET type) for DC.
  • The SSR does not switch. Solid-state relay
    Check the input polarity and voltage (for an SSR-25DA about 3 V to 32 V DC). Do not drive it straight from a pin if it needs more current. Mains is dangerous: keep it enclosed, and add a heat sink at high current.
  • The circuit under test shows clipped or distorted signals. Signal generator
    A sine swinging below zero can exceed what an input allows. Add a DC offset or bias so the signal stays inside the supply range of the part.
  • Measurements are off or noisy. Signal generator
    Join the generator's ground to the circuit ground. Keep amplitude and frequency within what the connected parts can handle.
  • The lamp is dim or does not light when driven from a board pin. Filament lamp
    A lamp needs far more current than a pin gives (a pin is limited to about 20 mA). Switch it with a transistor or MOSFET from its own supply that matches the lamp's voltage rating.
  • The lamp's brightness lags or it burns out the switch when it first turns on. Filament lamp
    A cold filament draws several times its running current at first. Size the switch for that surge, not just the steady current.

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.