🛠 Lire une entrée numérique 24 V (capteur de proximité)
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
- Arduino Opta with 24 VDC power supply on the power terminals (12–24 VDC, tightening torque 0.80 Nm)
- A 3-wire PNP inductive proximity sensor (or a simple button connected to +24 V)
- Wires 0.5–6 mm², insulated screwdriver
- Arduino IDE with the Opta core
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
- PNP/NPN confusion: the Opta expects a source signal (+24 V on the terminal); an NPN sensor (sinking) will not drive the input correctly without adaptation.
- Forgetting sensor power: the 24 V on the input terminals is not a sensor power supply, provide a separate 24 V power supply for the sensors.
- Watch out for interrupts: terminals I1 (A0) and I4 (A3) cannot use interrupts simultaneously (documented limitation in the user manual).
- Floating input: an unwired input may oscillate; in production, connect a real load or a 0 V reference.
Other tutorials for this board
- Premier sketch : faire clignoter une LED sur Arduino Opta
- Commander une charge 230 V avec un relais de sortie
- Server Modbus TCP : exposer les relais sur Ethernet
- Lire un capteur analogique 0–10 V sur les entrées Opta
- Remonter des données machine en MQTT via Ethernet
- Exploiter le double cœur : M7 pour le PLC, M4 en coprocesseur
Code examples for this board
relais_securise.inoArduinoentrees_numeriques.inoArduinoanalogique_0_10v.inoArduinomodbus_tcp_esclave.inoArduinomodbus_rtu_maitre.inoArduinomqtt_telemetrie.inoArduino