🛠 Lire une entrée numérique 24 V (capteur de proximité)

Arduino Opta (micro PLC, STM32H747) · debutant · Schéma : IMG-opta-plc-debutant-2-opta-entree-numerique-24v.svg — capteur de proximité trois fils alimenté en 24 V dont la sortie est raccordée à la borne I1 de l'Opta avec le schéma de câblage PNP

Objectives

Read a real industrial signal on the Opta's multifunction inputs. The 8 inputs I1..I8 (pins A0..A7) accept 0–24 VDC directly: no conditioning card is required. VIH threshold ≥ 6.6 V, VIL ≤ 4.46 V, impedance 8.9 kΩ, overvoltage and reverse polarity protection.

Hardware

Complete code

// opta_entree_24v.ino — etat d'un capteur sur I1 (broche A0)

const int CAPTEUR = A0; // borne I1 : 0 V / +24 V, VIH >= 6,6 V

void setup {
  Serial.begin(9600);
  pinMode(CAPTEUR, INPUT); // entree 24 V toleree, 8,9 kOhm
}

void loop {
  bool present = digitalRead(CAPTEUR) == HIGH;
  Serial.println(present ? "PIECE PRESENTE" : "RIEN");
  delay(50);
}

Expected verification

Bring a metal piece close to the sensor (or close the button towards +24 V): the serial monitor displays "PIECE PRESENTE". At rest, the input below 4.46 V reads LOW. The input is protected against reverse polarity, but respect the 0–24 VDC range.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials