Machine safety circuit with an E-stop
Wire an emergency stop through a dual-channel safety relay to a motor contactor, add start/stop from an Arduino, and show the state on a stack light.
Industrial · Advanced
In a real product: Industrial robot cell (Industrial): The E-stop cuts power through a safety relay.
On a real machine the emergency stop must work even when the program has crashed. So the E-stop never goes to a microcontroller pin: it goes to a safety relay, which cuts the power to the motor contactor's coil directly. The Arduino sits next to it. It adds the everyday start and stop, and reports what is happening, but it cannot overrule the safety circuit.
What you'll learn
- How a dual-channel safety relay watches an E-stop (S11-S12, S21-S22) and why it needs a reset
- The contactor's self-check: its NC auxiliary contact in the reset loop (feedback monitoring)
- Bringing 24 V buttons and signals into a 5 V board through an optocoupler module, read as active LOW
- Why safety goes in hardware, with the program only asking for a start
How it works
The 24 V supply powers the safety relay. Its two channels each run through one NC contact of the E-stop. Press RESET (blue) and, if both channels are closed, its safety output 13-14 closes. That output feeds the motor contactor's coil through the relay module's contact, which the Arduino controls. So the motor runs only when the safety relay and the program allow it.
- Press the E-stop (click it): both channels open, the safety relay drops its output and the contactor falls out at once, whatever the program is doing. The red tier lights from the safety relay's signal contact 31-32.
- Click the E-stop again to twist it free. Nothing restarts: press RESET, then START.
- The reset loop S33-S34 runs through the contactor's NC contact 21-22. If the contactor welded shut, that contact would stay open and the safety relay would refuse to reset.
The Arduino reads three 24 V signals through the optocoupler module (each OUT is LOW while its input is on): START (green, NO contact), STOP (red, its NC contact, so a broken wire also stops) and the safety relay's 31-32 ("stopped"). It switches the relay module's channel 1 (high-level trigger) to let the contactor pull in.
Try this
- Open the safety relay's settings and choose auto reset: now it restarts by itself when the E-stop is released. This is why E-stops need a manual reset.
- Put a guard-door limit switch's NC contact (21-22) in channel 2 only, and open it while running: one channel opens alone and the safety relay shows FAULT. It clears only after the E-stop has opened both channels.
- Add an amber tier that flashes while the machine is ready but not running.
sketch.ino
// Machine control next to a safety relay. The E-stop is wired to the safety relay, never to the Arduino: the
// program adds start and stop and reports, but the safety circuit stops the contactor on its own.
const int START = 2; // opto OUT1: LOW while START (green, NO) is pressed
const int STOP = 3; // opto OUT2: LOW while STOP's NC contact is closed (not pressed)
const int STOPPED = 4; // opto OUT3: LOW while the safety relay's 31-32 is closed (its outputs are off)
const int RUN = 7; // relay module IN1 (high-level trigger): HIGH lets the contactor pull in
bool running = false;
const char *shown = "";
void show(const char *state) {
if (strcmp(state, shown) != 0) {
Serial.println(state);
shown = state;
}
}
void setup() {
Serial.begin(9600);
pinMode(START, INPUT); // the module's outputs have their own pull-ups
pinMode(STOP, INPUT);
pinMode(STOPPED, INPUT);
pinMode(RUN, OUTPUT);
digitalWrite(RUN, LOW);
}
void loop() {
bool safe = digitalRead(STOPPED) == HIGH;
bool stopPressed = digitalRead(STOP) == HIGH; // NC contact open: pressed, or a broken wire
bool startPressed = digitalRead(START) == LOW;
if (!safe || stopPressed) running = false;
else if (startPressed) running = true;
digitalWrite(RUN, running ? HIGH : LOW);
if (!safe) show("Safety circuit open: release the E-stop and press RESET");
else if (running) show("Running");
else show("Ready: press START");
}