entrees_numeriques.ino

Arduino Opta (micro PLC, STM32H747) · File : entrees_numeriques.ino · Language : Arduino · Use case : Lire les 4 entrées numériques 24 V avec anti-rebond

Opta inputs take industrial 24 V directly: this sketch watches IN1 to IN4, filters bounce at 30 ms and prints every state change to the serial port. A direct input-to-relay mapping completes the demo.

Hardware

An STMicroelectronics Opta PLC (real-time STM32H747 + secure i.MX RT1052 companion) programmed with the Arduino PLC environment, 24 V DIN-rail supply. Buttons or three-wire 24 V sensors (PNP/positive logic) on IN1..IN4, 0 V to the COM terminal.

Wiring

Each sensor: +24 V to its supply, output to the INx terminal, 0 V to the shared input COM. No external resistor: 24 V is the standard here.

How it works

DigitalIn.read returns the hardware-filtered level; the 30 ms software filter removes mechanical contact duplicates. write copies the state to the relay.

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

Flip to low-level detection (NPN sensor) or keep a per-input press counter to build a production counter.

entrees_numeriques.ino

// Opta PLC : lecture des entrées numériques IN1..IN4 (24 V DC, logique positive).
#include "PLCContainer.h"

PLCContainer PLC;

const int ENT[4] = { OPTA_IN_1, OPTA_IN_2, OPTA_IN_3, OPTA_IN_4 };
int etatPrec[4] = { -1, -1, -1, -1 };
unsigned long dernier[4] = { 0, 0, 0, 0 };
const unsigned long ANTI_REBOND_MS = 30;

void setup() {
  Serial.begin(115200);
  PLC.begin();
  for (int i = 0; i < 4; i++)
    PLC.DigitalIn.setMode(ENT[i], PLCDigitalIn::PULL_UP);
  Serial.println("Entrées Opta prêtes (IN1..IN4)");
}

void loop() {
  for (int i = 0; i < 4; i++) {
    int e = PLC.DigitalIn.read(ENT[i]) ? 1 : 0;
    unsigned long maintenant = millis();
    if (e != etatPrec[i] && maintenant - dernier[i] > ANTI_REBOND_MS) {
      dernier[i] = maintenant;
      etatPrec[i] = e;
      Serial.printf("IN%d = %s\n", i + 1, e ? "ACTIVE (24V)" : "inactive");
      if (i == 0) PLC.Relay[0].write(e);   // bouton IN1 -> relais 1
    }
  }
}

← Back to the board