relais_securise.ino

Arduino Opta (micro PLC, STM32H747) · File : relais_securise.ino · Language : Arduino · Use case : Piloter les sorties à relais intégrées avec témoin

Opta's two relay outputs drive in one line through PLCContainer: this sketch alternates them every 3 s, like an audible/visual alarm or a run/stop inverter. The relay is a dry contact, accepting 24 V or mains 230 V loads.

Hardware

An STMicroelectronics Opta PLC (real-time STM32H747 + secure i.MX RT1052 companion) programmed with the Arduino PLC environment, 24 V DIN-rail supply. Opta alone (built-in relays); 24 V DC or 230 V AC load on the RO1/RO2 terminals.

Wiring

Load between the ROx terminal and common; respect the relay breaking rating from the datasheet. 24 V DC is recommended to start.

How it works

PLC.begin() sets up the peripherals; Relay[n].on/off closes or opens the dry contact. The RGB status LED mirrors the state for remote troubleshooting.

Running it

Install the Arduino PLC boards manager, select “Opta PLC”, wire USB/DFU and upload. The sketch runs on the real-time STM32H747 side.

Variants

Gate the relay on a digital input (sensor) so it only engages when the machine is ready, or add a no-rollover interlock.

relais_securise.ino

// Opta PLC : pilotage des 2 relais intégrés (RO1, RO2) avec LED de statut.
// API officielle : bibliothèque PLCContainer fournie par le paquet Arduino PLC.
#include "PLCContainer.h"

PLCContainer PLC;

const unsigned long PERIODE_MS = 3000;   // cycle de 3 s
unsigned long t0 = millis();
bool etat = false;

void setup() {
  Serial.begin(115200);
  PLC.begin();                 // initialise relais, entrées, analogique, Ethernet
  Serial.println("Opta relais : demarrage");
}

void loop() {
  if (millis() - t0 >= PERIODE_MS) {
    t0 = millis();
    etat = !etat;
    if (etat) {
      PLC.Relay[0].on();       // RO1 fermé
      PLC.Relay[1].off();      // RO2 ouvert
      Serial.println("RO1 ON / RO2 OFF");
    } else {
      PLC.Relay[0].off();
      PLC.Relay[1].on();
      Serial.println("RO1 OFF / RO2 ON");
    }
  }
  // LED RGB intégrée en témoin d'état (rouge = relais 1 actif)
  PLC.LedRgb.set(etat ? 255 : 0, 0, etat ? 0 : 255);
}

← Back to the board