E/A
Digital inputs and outputs are the handshake between the real world and the PLC. A pushbutton, a proximity sensor, a safety relay, a solenoid valve — all talk to the controller through digital I/O channels. Understanding how signals are generated, conditioned, wired, read, and protected is the foundation of every automation system, from a single relay circuit to a 10,000-point process plant.
A digital signal has exactly two states: ON (logic 1, TRUE, HIGH) or OFF (logic 0, FALSE, LOW). In industrial automation the most common standard is 24V DC: approximately 0V represents OFF and approximately 24V represents ON. Understanding how these two states are defined, detected, and guaranteed is the foundation of reliable machine design.
Drag the voltage slider and watch which logic zone the signal falls into. Real-time visual of the IEC threshold bands.
Click the sensor to toggle its state. Watch current flow and PLC input state for both PNP and NPN configurations.
Unlike the clean 0/1 of a textbook, real industrial digital signals are messy: they have rise times, noise superimposed on them, ground offsets, and they can sit in the undefined zone between thresholds. IEC 61131-2 defines exactly what voltages constitute a guaranteed logic 0 and logic 1 for 24V DC systems. Between those thresholds is an undefined zone — any signal in that range may be read as either state. Every competent automation engineer knows these numbers by heart.
// IEC 61131-2 — 24V DC digital signal thresholds
// Type 1 inputs (most common industrial standard)
//
// Voltage range │ Guaranteed state
// ─────────────────┼─────────────────────────────────
// −3V to +5V │ Logic 0 (OFF) — guaranteed
// +5V to +15V │ UNDEFINED — avoid this zone
// +15V to +30V │ Logic 1 (ON) — guaranteed
//
// Real sensor output voltages (good design):
// Sensor OFF: 0V to 1V (well within logic 0 zone)
// Sensor ON: 22V to 24V (well within logic 1 zone)
//
// Common problems that push into undefined zone:
// Long cable + high sensor current → voltage drop
// Shared 0V rail with heavy loads → ground lift
// Damaged sensor output transistor → partial conduction
// Missing termination on shielded cable
//
// Test procedure:
// Measure signal with multimeter (DC) at PLC input terminal
// Expected OFF: < 5V. Expected ON: > 15V
// Anything between 5–15V: INVESTIGATE before commissioning
Industrial sensors and actuators use four main output/input types. PNP (sourcing): transistor connects output to +24V when active — current flows out of the output pin. Most common in Europe. NPN (sinking): transistor connects output to 0V when active — current flows into the output pin. Common in Asia and USA. Push-Pull: contains both PNP and NPN transistors — can source or sink current, works with either input polarity. Most modern sensors use push-pull. Dry contact (potential-free): a mechanical or reed relay contact — just a switch, no voltage. Used for E-Stop buttons, safety devices, and any case where ground isolation is required.
| Type | Output when active | Current direction | Typical region | Wiring |
|---|---|---|---|---|
| PNP (sourcing) | +24V | Out of output pin | Europe | Load to 0V |
| NPN (sinking) | 0V | Into output pin | Asia/USA | Load to +24V |
| Push-Pull | +24V or 0V | Both | Universal | Either PNP or NPN |
| Dry Contact (NO) | Closed (no voltage) | Depends on wiring | Safety/E-Stop | External supply needed |
| Dry Contact (NC) | Open | Depends on wiring | Safety preferred | Fails safe on break |
// Signal type wiring examples — 24V DC system
//
// ── PNP (Sourcing) sensor → PLC input ──────────────────────
// +24V ──────────── Sensor Vcc
// Sensor OUT ──────── PLC Input +
// 0V ──────────── Sensor GND ──────── PLC Input − (Common)
//
// When sensor detects: OUT → +24V → PLC sees HIGH
// When sensor not det: OUT → floating/0V → PLC sees LOW
// Current path: +24V → Sensor → PLC input impedance → 0V
// ── NPN (Sinking) sensor → PLC input ───────────────────────
// +24V ──────────── Sensor Vcc ──── Pull-up resistor ──────┐
// Sensor OUT ──────────────────────── PLC Input
// 0V ──────────── Sensor GND ──── PLC Input − (Common)
//
// When sensor detects: OUT pulls to 0V → PLC sees LOW? No:
// NPN sinking means current flows INTO sensor OUT
// PLC input sees +24V when sensor OFF, 0V when sensor ON
// → Input logic is INVERTED for NPN with pull-up wiring
// ── DRY CONTACT (potential-free) → PLC input ───────────────
// +24V ──── PLC Input + supply ──── Contact A
// Contact B ──── PLC Input
// 0V ──── PLC Input − (Common)
//
// When contact closes: current flows through contact → PLC HIGH
// Galvanically isolated from any external voltage source
// Used for: E-Stop, safety relay contacts, manual switches
// ── PUSH-PULL sensor → PLC input ────────────────────────────
// Works with EITHER PNP or NPN wiring
// ON state: output drives to +24V (PNP transistor active)
// OFF state: output drives to 0V (NPN transistor active)
// No pull-up or pull-down needed — actively drives both states
Every PLC input card has a specified minimum current to guarantee a reliable logic 1 — typically 2–6 mA. Every sensor has a maximum load current it can drive. Every output card has a maximum current per channel and per group. Matching these requirements, including inrush current for capacitive and inductive loads, is essential for reliable operation and to avoid damaging hardware.
// Input/output current matching calculation
//
// Step 1: Check sensor vs PLC input
// Sensor max output current: 200 mA (typical PNP sensor)
// PLC input current draw: 6 mA at 24V (from datasheet)
// → OK: 6 mA << 200 mA
//
// Step 2: Check PLC output vs load
// PLC output max current: 0.5 A continuous
// Solenoid valve coil: P=4.8W, I=4.8/24=0.2A steady
// Solenoid inrush (pick-up): I_inrush = 5 × I_steady = 1.0A
// Duration: ~20 ms
// → 1.0A > 0.5A: OVERLOAD at inrush!
// → Solution: Use output rated ≥ 1A, or add external relay
// → OR: Use solenoid valve with electronic inrush limiter
// (modern ASCO/Festo valves: inrush = 1.2× steady)
//
// Step 3: Group fuse calculation
// 8 outputs per group, all solenoids 0.2A steady
// Simultaneous on: 8 × 0.2A = 1.6A
// Add 25% margin: 1.6 × 1.25 = 2.0A
// Select: 2A fast-blow fuse (or 2.5A slow-blow for inrush)
//
// Step 4: PSU total current
// All I/O current + PLC CPU + HMI + field devices
// Total: 12A estimated → use 15A / 360W PSU @ 24V
// Add UPS buffer capacitor: 15A × 20ms = 0.3 Ah
Digital I/O hardware spans the entire range from fixed onboard I/O on a compact PLC to large remote distributed I/O islands connected over PROFINET. Understanding the internal architecture of an I/O card — the optocoupler, the filter, the protection diode, the current limiting resistor — allows you to diagnose faults that would otherwise be invisible.
Click any input channel to toggle it. Right-click to inject a fault. Watch LED states, group fuse current, and diagnostic messages update live.
A standard 24V DC digital input channel has five stages: terminal block → surge protection (TVS diode and polyfuse) → RC input filter (debounce) → optocoupler (electrical isolation between field wiring and PLC backplane) → logic level shifter to 3.3V or 5V for the CPU. The optocoupler is the heart — it provides galvanic isolation up to 500V–3kV, protecting the PLC from field-side faults. Its minimum current to switch is typically 2–5 mA. The RC filter time constant (1–10 ms default) prevents noise and contact bounce from causing false reads.
// Digital input channel — internal signal path
//
// Field terminal (+) ─┬── [TVS diode to 0V] ← clamps spikes
// │
// └── [R_input ~3.3kΩ] ← current limiter
// │ I = 24V/3.3kΩ = 7.3mA
// ▼
// [C_filter ~1µF] ← RC debounce
// │ τ = 3.3kΩ × 1µF = 3.3ms
// ▼
// [Optocoupler LED] ← 5mA min to switch
// [Optocoupler photo-transistor]
// │ 3kV isolation barrier
// ▼
// [3.3V logic level] ← PLC CPU side
// │
// [Input register] ← Read each PLC scan
// Field terminal (−) ─── [0V common]
//
// Key parameters from datasheet:
// Input voltage range: −3V to +30V (continuous)
// Min. current for logic 1: 4 mA
// Max. current (continuous): 15 mA
// Default filter time: 3.2 ms
// Filter time programmable: 0.1–20 ms
// Isolation voltage: 500V (field to backplane)
// Input impedance at 24V: ~3.3 kΩ (= 7.3 mA → above 4mA min)
Transistor outputs (solid-state) use MOSFET or bipolar transistors — fast switching (<1 ms), no wear, high cycle rates, but can fail short-circuit. They require a freewheeling (flyback) diode for inductive loads — most cards include this internally. Relay outputs use a physical relay contact — can switch AC and DC, galvanically isolated, higher current capability (2–10 A), but slow (5–15 ms switching), wear-limited (typically 100,000–2,000,000 mechanical operations), and susceptible to contact welding on capacitive loads. Use transistor outputs for high-cycle-rate loads; relay outputs for occasional switching of higher-power or mixed-voltage loads.
| Output Type | Max Current | Switching Speed | Load types | Life | Fail mode |
|---|---|---|---|---|---|
| Transistor (MOSFET) | 0.5–2 A | <1 ms | DC only | ∞ (solid state) | Short (fails ON) |
| Transistor (IGBT) | 2–10 A | <1 ms | DC only | ∞ | Short or open |
| Relay | 2–10 A | 5–15 ms | AC + DC | 100k–2M ops | Weld (stuck ON) or open |
| Triac (SSR) | 1–25 A | <0.5 ms | AC only | ∞ | Short (fails ON) |
// Freewheeling diode — why it is MANDATORY for inductive DC loads
//
// When a transistor output switches OFF a coil:
// L × (dI/dt) = V_spike
// Coil inductance L = 0.1H, I = 200mA, turn-off time = 10µs
// V_spike = 0.1 × (0.2 / 0.00001) = 2000V !!!
//
// This 2000V spike appears across the output transistor:
// → Exceeds transistor V_DS rating (typically 50–60V)
// → Transistor avalanche breakdown → eventual failure
// → Also radiates EMI affecting nearby electronics
//
// Freewheeling diode solution:
// Diode placed: anode to 0V, cathode to +24V
// (i.e. reverse-biased during normal operation)
// When output turns OFF: inductor drives current through diode
// Coil energy dissipated safely: V_clamp = 0.7V (diode forward V)
// Spike: 0.7V instead of 2000V
//
// Practical notes:
// Most modern PLC output cards include internal freewheeling diodes
// External is still recommended for long cable runs (cable inductance)
// For faster coil release: Zener diode in series with freewheeling
// (e.g. 27V Zener): V_clamp = 27V, faster energy dissipation
// → Relay/valve opens in ~3ms vs ~50ms with simple diode
//
// Protection components per output channel (external):
// Inductive DC load: 1N4007 freewheeling diode across load
// Inductive AC load: RC snubber (47Ω + 47nF) across load
// Lamp load (inrush): Series NTC thermistor or current fuse
In large machines, running hundreds of individual cables from field devices to a central PLC cabinet is expensive and failure-prone. Remote I/O places small I/O modules directly at the machine, connected to the PLC over a single PROFINET or EtherNet/IP cable. IO-Link (IEC 61131-9) goes further: a bidirectional serial protocol over standard 3-wire cable that carries both I/O data AND device parameters AND diagnostics — a sensor tells the PLC its serial number, detection distance, output status, and temperature, all over the same wire that carries the ON/OFF signal. This transforms field devices from dumb switches into smart diagnostic assets.
// IO-Link device data model (IEC 61131-9)
// Single 3-wire cable: L+ (24V), L− (0V), C/Q (data)
// Communication: 24V UART, 4800/38400/230400 baud
// Process Data (cyclic, every master cycle ~2ms):
// Bit 0: Switch state (ON/OFF) — same as digital I/O
// Bit 1–7: Extended status flags (output overload etc.)
// Device Parameters (acyclic, on demand):
// Index 1: Vendor name (e.g. 'SICK')
// Index 2: Device name (e.g. 'IME08-1B5NSZW2S')
// Index 5: Serial number ('AB12345678')
// Index 16: Switching distance (mm) — read/write!
// Index 17: Hysteresis (mm)
// Index 18: Output logic (NO/NC)
// Diagnostic Data (acyclic, on event):
// Temperature (°C, internal)
// Operating hours (h)
// Short-circuit count (events)
// Signal quality (0–100%)
// PLC code — read IO-Link device temperature:
VAR
iolink_master : IO_LINK_MASTER_REF;
sensor_temp : REAL;
read_done : BOOL;
END_VAR
iolink_master.ReadParameter(
port := 3, // Port 3 on master
index := 32, // Temperature object index
subindex:= 0,
data => sensor_temp,
done => read_done
);
// sensor_temp populated after read_done = TRUE
Reading a digital input and setting a digital output are the simplest PLC operations — but the logic built around them can be sophisticated. Debouncing, edge detection, timing, counting, interlocking, and state machines are all built from these primitive operations. This section covers every pattern, from a single output coil to a full interlock matrix.
Toggle each input condition. Watch the interlock word, the combined AND result, and which bit is blocking the output. This is how a real machine interlock matrix works.
Press the button below to simulate a button press with contact bounce. Watch how the raw signal, the debounced signal, and the edge detector outputs respond.
A digital input state is TRUE or FALSE. An edge is the transition between states — rising edge (FALSE→TRUE) or falling edge (TRUE→FALSE). Many operations should trigger exactly once per transition, not continuously while the signal is high. In IEC 61131-3 Structured Text, R_TRIG and F_TRIG function blocks detect these edges. In Ladder Logic, the P (positive/rising edge) and N (negative/falling edge) contact instructions serve the same purpose. Missing edge detection is one of the most common PLC programming bugs.
// Edge detection — all methods (IEC 61131-3)
// ── METHOD 1: R_TRIG / F_TRIG function blocks ─────────────
VAR
start_button : BOOL; // Direct input
rtrig_start : R_TRIG; // Rising edge detector
ftrig_start : F_TRIG; // Falling edge detector
start_pressed : BOOL; // Single-scan pulse on press
start_released : BOOL; // Single-scan pulse on release
END_VAR
rtrig_start(CLK := start_button);
ftrig_start(CLK := start_button);
start_pressed := rtrig_start.Q; // TRUE for exactly 1 scan
start_released := ftrig_start.Q;
// ── METHOD 2: Manual edge detection (no function blocks) ──
VAR
input_now : BOOL;
input_prev : BOOL := FALSE;
rising_now : BOOL;
fall_now : BOOL;
END_VAR
rising_now := input_now AND NOT input_prev; // 0→1 transition
fall_now := NOT input_now AND input_prev; // 1→0 transition
input_prev := input_now; // Store for next scan — MUST be last!
// ── METHOD 3: Pulse-stretching for very short inputs ──────
// Sensor pulse may be shorter than PLC scan time (e.g. 0.5ms pulse)
// Use hardware input filter OFF + software latch:
VAR
short_pulse : BOOL; // Hardware HSC captures, OR input filter=0
pulse_latch : BOOL;
pulse_timer : TON;
END_VAR
IF short_pulse THEN pulse_latch := TRUE; END_IF;
pulse_timer(IN := pulse_latch, PT := T#50ms);
IF pulse_timer.Q THEN pulse_latch := FALSE; END_IF;
// pulse_latch now stretches short input to 50ms — visible to slow scan
Industrial machines use interlocks to prevent dangerous or damaging combinations of outputs. An interlock is a condition that must be TRUE before an output can be activated. Bad practice: scatter interlocks across dozens of rungs with no structure. Good practice: centralise all interlock conditions into a dedicated BOOL array "interlock_ok[N]", evaluate all conditions once, then use the result in the output rung. This makes the logic auditable and the Electrical Safety Document (ESD) traceable to specific code lines.
// Structured interlock pattern — machine axis enable
// All conditions must be TRUE for axis to enable
VAR
// Raw input signals
estop_ok : BOOL; // E-Stop chain healthy (TRUE = no estop)
guard_closed : BOOL; // Safety guard confirmed closed
home_done : BOOL; // Axis has completed homing
pneum_ok : BOOL; // Pneumatic pressure OK (> 5 bar)
no_fault : BOOL; // Drive has no active fault
mode_auto : BOOL; // Machine in AUTO mode
upstream_ready : BOOL; // Upstream station has released
// Interlock result
axis_interlock : BOOL; // Combined interlock — all must be TRUE
axis_enable : BOOL; // Final output to drive STO
// Diagnostic — which interlock is preventing enable?
interlock_word : WORD; // Bit-mapped diagnostic for HMI
END_VAR
// Evaluate all interlocks ONCE per scan
interlock_word.0 := estop_ok;
interlock_word.1 := guard_closed;
interlock_word.2 := home_done;
interlock_word.3 := pneum_ok;
interlock_word.4 := no_fault;
interlock_word.5 := mode_auto;
interlock_word.6 := upstream_ready;
// Single combined result
axis_interlock := estop_ok AND guard_closed AND home_done
AND pneum_ok AND no_fault
AND mode_auto AND upstream_ready;
// Output: only enable if all interlocks pass
axis_enable := axis_interlock;
// HMI shows interlock_word as bitfield:
// Bit 0 OFF → operator sees 'E-Stop active'
// Bit 1 OFF → 'Guard open'
// Bit 3 OFF → 'Low pneumatic pressure' etc.
// One word carries all diagnostic info — efficient and clear
Digital inputs feed counters and timers that implement machine logic. CTU (Count Up) counts rising edges — pieces produced, faults accumulated. CTUD (Count Up/Down) tracks position or inventory. TON (Timer On-Delay) starts when an input goes TRUE — used for delay-before-action. TOF (Timer Off-Delay) stays TRUE for a set time after input drops — used for run-on and minimum-on-time. TP (Timer Pulse) generates a fixed-width pulse regardless of input duration. A complete machine cycle is typically implemented as a state machine driven by digital inputs from sensors and commanded by digital outputs to actuators.
// Production counter with reset, preset, and HMI output
VAR
part_sensor : BOOL; // Photoelectric sensor — part detected
reset_button : BOOL; // Operator reset
rtrig_part : R_TRIG;
rtrig_reset : R_TRIG;
counter_CTU : CTU;
batch_size : INT := 500;
batch_complete : BOOL;
total_produced : DINT := 0; // Persistent across power cycles
END_VAR
rtrig_part(CLK := part_sensor);
rtrig_reset(CLK := reset_button);
counter_CTU(
CU := rtrig_part.Q, // Count on each part detection
R := rtrig_reset.Q, // Reset on button press
PV := batch_size,
Q => batch_complete, // TRUE when batch_size reached
CV => batch_count // Current count (0 to PV)
);
// Accumulate total (persist across resets)
IF rtrig_part.Q THEN total_produced := total_produced + 1; END_IF;
// Full machine cycle state machine — RDFD pattern
// (simplified to show DI/DO interaction)
CASE machine_state OF
0: // IDLE — waiting for start
IF start_button AND interlock_ok THEN
machine_state := 1;
END_IF;
1: // EXTEND cylinder
cylinder_extend := TRUE;
IF cylinder_fwd_sensor THEN // End of stroke confirmed
dwell_timer(IN:=TRUE, PT:=T#200ms);
IF dwell_timer.Q THEN
dwell_timer(IN:=FALSE);
machine_state := 2;
END_IF;
END_IF;
2: // RETRACT
cylinder_extend := FALSE;
cylinder_retract := TRUE;
IF cylinder_back_sensor THEN
cylinder_retract := FALSE;
machine_state := 0;
END_IF;
END_CASE;
The digital input is only as reliable as the sensor feeding it. Every sensing technology has specific application constraints — detection range, target material, environmental immunity, response time, and output type. Choosing the wrong technology is the most common cause of intermittent machine faults that take hours to diagnose.
Describe your target and environment. The tool computes which sensor technology fits and shows the expected sensing distance with correction factors.
Inductive sensors detect metal targets by generating an alternating magnetic field and measuring the damping caused by eddy currents in the target. They are immune to dirt, oil, coolant, and non-metallic objects — making them the most common sensor type in metal machining. Key parameters: nominal sensing distance Sn (specified for mild steel, 1mm thick square plate of side = 3× Sn), hysteresis (~10–20% of Sn), correction factor Cf for non-standard metals (stainless steel: 0.7, aluminium: 0.45, copper: 0.35). Actual sensing distance for aluminium = Sn × 0.45.
// Inductive sensor — correction factor calculation
// Sensor: Balluff BES 516-300-S272 Sn=5mm (mild steel)
//
// Target material correction factors:
// Mild steel (Fe360): 1.00 (reference)
// Stainless steel 304: 0.70 → Actual Sd = 5 × 0.70 = 3.5mm
// Stainless steel 316L: 0.65 → Sd = 3.25mm
// Cast iron: 1.10 → Sd = 5.5mm
// Aluminium: 0.45 → Sd = 2.25mm
// Brass: 0.40 → Sd = 2.0mm
// Copper: 0.35 → Sd = 1.75mm
//
// CRITICAL: Always verify actual switching distance on
// the real machine with the real target material!
// Spec sheet gives starting point, not final value.
//
// Mounting correction:
// Flush (shielded, embeddable): 100% Sn, can embed in metal
// Non-flush (unshielded): 100% Sn but needs 3Sn clearance
// around sensor body
//
// Temperature effect:
// Standard range: −25°C to +70°C (Sn varies ±10%)
// Extended range: −40°C to +85°C (Sn varies ±15%)
// At −25°C: switching distance may increase by 10%
// At +70°C: switching distance may decrease by 10%
// For tight applications: measure at actual operating temperature
//
// Output types available:
// NO (normally open): outputs HIGH when target present
// NC (normally closed): outputs LOW when target present
// NO+NC (dual output): both signals simultaneously
// IO-Link: digital + analog + diagnostics on one wire
Photoelectric sensors use a light beam (typically infrared LED, 850 nm) to detect objects without physical contact. Three configurations: Through-beam (separate emitter and receiver) has the longest range (up to 60 m) and highest reliability — the beam must be completely blocked. Retro-reflective uses a reflector — simpler installation than through-beam, range up to 10 m, but shiny objects can reflect the beam back without the reflector (false ON). Diffuse mode detects light reflected directly from the target surface — easiest installation, shortest range (0.1–2 m), highly dependent on target colour and surface finish.
| Mode | Max range | Transparent targets | Shiny targets | Install complexity |
|---|---|---|---|---|
| Through-beam | 60 m | Excellent | Excellent | High (2 units) |
| Retro-reflective | 10 m | With polarised filter | Risk of false reflex | Medium |
| Diffuse | 2 m | Poor | Risk of false trigger | Low |
| BG suppression | 0.5 m | OK (laser) | Good | Low |
// Photoelectric sensor selection guide
//
// APPLICATION: Detect transparent bottles on conveyor
// Problem: diffuse mode cannot detect transparent objects
// (light passes through, no reflection back)
// Solution: Through-beam or retro-reflective with polarised filter
//
// APPLICATION: Detect shiny metal lids
// Problem: diffuse may false-trigger on ambient light
// retro-reflective: lid surface may reflect back
// Solution: Background suppression diffuse sensor (laser triangulation)
// or colour mark sensor if mark is present
//
// Excess gain concept:
// Excess gain = actual signal level / minimum detection level
// Excess gain = 1.0: sensor just barely switches — UNRELIABLE
// Excess gain = 5.0: sensor has 5× signal margin — GOOD
// Excess gain > 10: robust in dirty/foggy environments
// Rule: always mount sensor to achieve excess gain > 2.0
// after accounting for worst-case contamination
//
// Response time:
// Mechanical conveyor at 1.5 m/s, part width 10mm:
// Part passes sensor in: 10mm / 1500mm/s = 6.7 ms
// Sensor response time must be << 6.7ms
// Standard sensor: 1–3 ms response → OK
// High-speed sensor: < 0.1 ms → for small parts at high speed
//
// Beam diameter must be < part size:
// Min part size to reliably detect: 1.5 × beam_diameter
// Laser spot: 1–3 mm → detects parts > 1.5–4.5 mm
// LED spot: 5–20 mm → minimum part size 7.5–30 mm
Mechanical limit switches use a physical actuator (plunger, lever, roller, whisker) to open/close electrical contacts. High reliability for position confirmation where physical contact is acceptable. Key parameters: operating force, differential travel (distance between operate and release points), mechanical life (10–30 million operations typical), IP rating, and contact rating (current and voltage). Reed switches use a magnetic field to close contacts — used inside pneumatic cylinders (mounted externally, detects piston magnet through cylinder wall). Hall-effect sensors are the solid-state equivalent — no moving parts, better vibration resistance, available as digital output (switch) or analog (position).
// Limit switch selection — precision positioning
// Application: CNC axis end-of-travel limits
// Key parameters for precision limit switches:
// Repeatability: ±0.01mm (Omron D4C series)
// vs standard limit switch: ±0.5mm
// Operating force: 0.5–2N (low for delicate mechanisms)
// Pre-travel: 0.5–2mm (distance from free to operate)
// Over-travel: 5–10mm (mechanical stops beyond operate point)
//
// Reed switch inside pneumatic cylinder:
// Cylinder bore: 32mm, stroke: 100mm, piston has magnet
// Mount reed switch in T-slot on cylinder body
// Sensing range: 3–5mm through aluminium wall
// Response time: 1–3ms (contact bounce 2–5ms — use input filter)
// Max speed: 2m/s typical (piston must slow near end of stroke)
// Temperature: −20°C to +70°C standard
//
// Common problem: reed switch misalignment
// Symptom: sensor activates mid-stroke (magnet field misaligned)
// Fix: slide switch 5–10mm toward piston travel direction
//
// Hall-effect digital switch (solid-state reed replacement):
// No contact bounce → no input filter needed
// Faster response: < 0.1ms
// Vibration resistant: survives 30g shock vs 10g for reed
// IO-Link version: reports magnetic field strength
// If field_strength < threshold → 'magnet wear' alarm
// Service life: > 10^9 operations (effectively unlimited)
Safety-critical digital I/O is governed by IEC 62061 (SIL) and ISO 13849 (PL). A standard PLC output turning off a motor contactor is NOT a safety function. A certified safety I/O channel with dual-channel monitoring, cross-fault detection, and diagnostics IS. Understanding the difference — and the engineering behind it — is legally required for machine builders in Europe and increasingly everywhere.
Simulate an E-Stop dual-channel safety relay. Click button to trigger/release E-Stop. Inject individual channel faults. See relay state, channel monitoring, and machine output.
Category B/1 (PLa/PLb): single channel, no fault detection. A single component failure can cause loss of safety function — acceptable only for very low risk. Category 2 (PLc): single channel with test/monitoring — a test pulse checks the channel periodically. Category 3 (PLd): dual channel — two independent channels, each sufficient alone. A single fault does not prevent the safety function, and the fault is detected before or at the next demand. Category 4 (PLe): dual channel with immediate fault detection — even a fault during operation is immediately detected and the safety function is executed.
// Dual-channel safety input — wiring and monitoring
// Hardware: Pilz PNOZ m B0 safety relay
// Input: E-Stop button with 2× NC contacts
//
// Channel 1: +24V → button NC1 → terminal S11 of relay
// Channel 2: +24V → button NC2 → terminal S12 of relay
// Common: terminal S14 → 0V
//
// Safety relay internal monitoring:
// Continuously measures voltage on S11 and S12
// Both HIGH (button released, NC contacts closed): OK
// Both LOW simultaneously: E-Stop pressed → SAFE STATE
// One HIGH, one LOW: DISCREPANCY
// → If discrepancy < 500ms: temporary (acceptable)
// → If discrepancy > 500ms: FAULT → latched fault state
// → Requires manual reset after fault cleared
//
// Cross-circuit detection (short between channels):
// Relay sends diagnostic test pulse alternately on ch1/ch2
// If ch2 responds when ch1 is pulsed: short circuit detected
// → Relay locks out immediately
//
// Safety relay outputs (2× NO contacts):
// Contact K1 and K2 in series → drive contactor coil
// Even if K1 welds shut: K2 still opens safely
// Relay monitors K1/K2 feedback to detect welded contacts
// If welded contact detected: relay will not re-enable
// → Forces maintenance before machine can restart
// IEC 62061 PFH calculation (simplified):
// PFH = λ_D × DC where λ_D = dangerous failure rate, DC = diagnostic coverage
// For dual-channel (Cat.3): PFH ≈ λ_D² × T_proof / 2
// Typical result: PFH = 10^-8 /h → achieves SIL 2
A safety PLC (Siemens S7-1500F, Beckhoff with TwinSAFE, Pilz PSS 4000) uses F-peripherals: F-DI (Fail-Safe Digital Input) and F-DO (Fail-Safe Digital Output) modules. These modules communicate over PROFIsafe or FSoE — a safety layer on top of standard PROFINET/EtherCAT that adds CRC, sequence counter, and watchdog to every telegram. The F-module monitors its own channels: short-circuit, wire break, discrepancy, overcurrent, cross-wire. The F-CPU runs a separate safety program in an isolated memory area, cryptographically signed, that the standard program cannot access or corrupt.
// Safety PLC F-DI module — channel configuration (TIA Portal / Siemens)
// Module: SM 326 F-DI 8×24VDC (6ES7326-1BK02-0AB0)
// Channel configuration (per pair of channels):
// Channel mode: 2-channel equivalent evaluation
// Channel 0 + Channel 1 are one safety input (E-Stop button)
// Module monitors both channels and their agreement
// Discrepancy time: 100 ms
// Channels must agree within 100ms → otherwise safety fault
// Supply voltage: 24V DC
// Input filter: 3ms (adjustable 0.1–20ms)
//
// Safety integrity:
// SIL 3 / PL e capable (single module, dual channel)
// PFH: 1.0 × 10^-9 /h
// MTTFd: 474 years
// Proof test interval: 20 years
//
// PROFIsafe communication:
// F-Address: must be unique across all F-peripherals
// Watchdog time: 150ms (if no valid safety telegram in 150ms → fault)
// CRC: 4-byte checksum on every safety telegram
//
// Safety program (SCL / F-FBD):
// Access safety data ONLY through F-approved blocks
VAR
E_stop_F : BOOL; // Read from F-DI via ESTOP1 block
Muting_en : BOOL; // From standard program (muting request)
Safety_OK : BOOL; // Safety output to F-DO
END_VAR
// ESTOP1: standard emergency stop evaluation block (PLCopen Safety)
ESTOP1_instance(
E_STOP := NOT F_DI_channel_0, // NC contact → invert
RESET := reset_button_safe,
T_MUTING := T#500ms,
Q1 => Safety_OK,
Q2 => (* feedback monitoring output *)
);
Machine guarding interlocks prevent access to hazardous areas during machine operation. IEC 14119 classifies interlocks: Type 1 (captive key, e.g. Castell) — key must be physically in lock for machine to run; Type 2 (non-captive, tongue interlock) — most common, coded or non-coded; Type 4 (electronically coded, RFID) — highest anti-tampering level. Muting is the controlled, temporary bypassing of a safety function — for example, allowing product to pass through a light curtain on a conveyor without stopping the machine, while still detecting a person. Muting requires at least two independent muting sensors that must trigger in a specific sequence within a time window.
// Muting sequence for safety light curtain
// Application: product enters machine through curtain on conveyor
// Muting sensors: S_MUT_1 and S_MUT_2, spaced 200mm apart on conveyor
// Sequence: S_MUT_1 must trigger BEFORE S_MUT_2 (confirms product direction)
// Time window: S_MUT_2 must trigger within 5s of S_MUT_1
VAR
lc_beam_broken : BOOL; // Light curtain OSSD output (NC logic)
s_mut_1 : BOOL; // Upstream muting sensor
s_mut_2 : BOOL; // Downstream muting sensor
rtrig_mut1 : R_TRIG;
rtrig_mut2 : R_TRIG;
muting_window : TON; // 5-second muting window timer
muting_active : BOOL; // Muting state
safety_curtain : BOOL; // Final safety output (to F-CPU)
END_VAR
rtrig_mut1(CLK := s_mut_1);
rtrig_mut2(CLK := s_mut_2);
// Muting logic — strict sequence required
IF rtrig_mut1.Q AND NOT muting_active THEN
muting_window(IN:=FALSE); // Reset timer
muting_window(IN:=TRUE, PT:=T#5s);
END_IF;
// S_MUT_2 must follow S_MUT_1 within window
IF rtrig_mut2.Q AND muting_window.IN AND NOT muting_window.Q THEN
muting_active := TRUE;
END_IF;
// Deactivate muting when both sensors clear
IF NOT s_mut_1 AND NOT s_mut_2 THEN
muting_active := FALSE;
muting_window(IN:=FALSE);
END_IF;
// Timeout: no second sensor → cancel muting
IF muting_window.Q AND NOT muting_active THEN
muting_window(IN:=FALSE);
END_IF;
// Safety output: safe unless beam broken AND muting not active
safety_curtain := NOT lc_beam_broken OR muting_active;
// This runs in SAFETY PLC — standard PLC cannot modify safety_curtain
The majority of I/O faults in industrial machines fall into three categories: wiring errors (wrong polarity, missed connection, broken conductor), component failures (sensor failed, output shorted, fuse blown), and logic errors (wrong address, inverted logic, missing debounce). A systematic, physics-first diagnostic approach resolves 95% of I/O faults within minutes. Guessing and replacing parts wastes time and money.
A fault has been injected into the system. Use the virtual multimeter to probe different points. Deduce the root cause from your measurements. Click each probe point to measure.
Watch live digital signals with noise, contact bounce, and EMI. Adjust noise level and see how it affects PLC input reliability. Toggle EMI events.
The diagnostic process is always the same: localise the fault to field wiring, sensor/actuator, or PLC hardware — then within that section, isolate to the specific component. Never start by replacing parts. Start by measuring voltages with a multimeter at the PLC terminal strip. This takes two minutes and identifies 80% of faults immediately.
// Digital I/O fault diagnosis — systematic approach
//
// ── INPUT NOT READING CORRECTLY ──────────────────────────────
//
// Step 1: Check PLC status LEDs
// Input LED ON but PLC reads FALSE:
// → Wrong input address in program (check wiring diagram)
// → Input card failed (rare)
// Input LED OFF but device is activated:
// → No signal reaching PLC terminal → go to Step 2
//
// Step 2: Measure voltage at PLC input terminal (+ vs COM)
// Sensor claimed to be ON:
// Measure > 15V → signal OK → input card fault
// Measure 5–15V → signal in undefined zone → sensor or cable fault
// Measure < 5V → no signal → go to Step 3
//
// Step 3: Measure voltage at sensor output pin
// Sensor ON condition:
// > 20V → cable fault between sensor and PLC (check connector)
// < 1V → sensor output stage failed or not powered
// No supply voltage: check Vcc and 0V at sensor connector
//
// Step 4: Check sensor supply
// Measure Vcc at sensor: should be 18–30V DC
// < 18V: cable resistance drop (long cable + high current)
// or PSU overloaded (measure at PSU terminals)
// 0V: fuse blown, broken wire, wrong pin connection
//
// ── OUTPUT NOT ACTIVATING LOAD ──────────────────────────────
//
// Step 1: Is PLC commanding the output?
// Force output ON in PLC → output LED lights?
// NO → PLC output card fault or output disabled (safety?)
// YES → output card OK, problem is in wiring/load → Step 2
//
// Step 2: Measure voltage at output terminal (+ vs COM)
// Output commanded ON:
// > 20V: signal OK but load not working → check load
// < 15V: voltage drop → check fuse, check load resistance
// 0V: broken wire or blown output transistor
//
// Step 3: Check load
// Solenoid valve: measure coil resistance (Ω)
// Expected: P=4.8W → R = V²/P = 576/4.8 = 120Ω
// Measured 0Ω: coil short → replace valve
// Measured ∞Ω: coil open → replace valve
// Lamp: measure filament resistance
// Relay coil: measure coil resistance
Electrical noise causes digital inputs to false-trigger and outputs to produce glitches. The three noise coupling mechanisms are: conducted noise (noise travels along the wire itself — prevented by filters and TVS diodes), capacitive coupling (noise from adjacent conductors — prevented by physical separation and shielding), and inductive coupling (magnetic field from current loops — prevented by using twisted pairs and minimising loop areas). Ground loops occur when two points nominally at "0V" are actually at different potentials — a common mode voltage that appears as a signal on sensor cables.
// EMC noise diagnosis and prevention
//
// SYMPTOM: Input randomly toggles with no physical change
//
// Diagnosis sequence:
// 1. Check: does it correlate with any machine output?
// (motor start, solenoid fire, welding?) → Conducted/inductive EMI
// 2. Check: does it correlate with day/time? → Mains supply quality issue
// 3. Measure: voltage at PLC input terminal during false trigger
// > 5V transient? → Noise couple into cable
// < 5V: → Ground reference problem (ground loop)
//
// FIX 1: Increase input filter time
// Change filter from 3ms to 10ms
// Cost: slightly slower input response (acceptable for most sensors)
// Eliminates: short transients < 10ms
//
// FIX 2: Cable shielding and routing
// Signal cables: run in separate cable tray from power cables
// Minimum separation: 100mm (200mm near VFD output cables)
// Shield: connect at PLC end only (single-point ground)
// Cross at 90°: when signal and power cables must cross
//
// FIX 3: Ground loop elimination
// Problem: sensor and PLC have different local earth potentials
// e.g. sensor ground = 0.8V above PLC ground → 0.8V common mode
// Fix: ensure all 0V connections return to a single earth point
// Use star topology: ALL 0V wires back to same PSU 0V terminal
// Never: daisy-chain 0V through sensor connectors (adds resistance)
//
// FIX 4: Ferrite cores on cable
// Snap-on ferrite on cable: ~50Ω impedance at 25MHz
// Attenuates HF conducted noise
// Use: 3–5 turns through core for maximum impedance at target frequency
// Zero cost to system operation (no effect on DC/50Hz signals)
//
// FIX 5: Optical isolation (ultimate solution)
// If all else fails: use an isolating signal converter
// Input: 24V DC from field device
// Output: 24V DC to PLC, galvanically isolated
// Common mode rejection: > 1000V
// Cost: €15–50 per channel — use only where necessary
Beyond reactive fault diagnosis, modern systems implement predictive I/O diagnostics. For every digital input connected to a sensor with a defined duty cycle, the PLC can monitor: transition count (how many times has this input changed state per hour?), last transition time (when did this input last change?), and stuck-at detection (input has not changed in N minutes when it should have). This data identifies aging sensors, worn cams, and developing mechanical faults weeks before they cause unplanned downtime.
// Digital I/O predictive diagnostics
// Monitor every input for anomalies
TYPE DigitalInputDiag :
STRUCT
raw_value : BOOL;
prev_value : BOOL;
transition_count: DWORD; // Total state changes
last_change_ms : DWORD; // Timestamp of last change (ms)
state_duration : DWORD; // How long in current state (ms)
expected_hz : REAL; // Expected change rate (for cyclic inputs)
actual_hz : REAL; // Measured change rate
stuck_timeout : TIME := T#30s; // Alarm if no change in this time
alarm_stuck : BOOL;
alarm_fast : BOOL; // Changing much faster than expected
alarm_slow : BOOL; // Changing much slower than expected
END_STRUCT
END_TYPE
// Update function (call every PLC scan)
PROCEDURE UpdateDiag
VAR_IN_OUT d : DigitalInputDiag; END_VAR
VAR
now_ms : DWORD; // System time in ms
dt_ms : DWORD;
END_VAR
now_ms := GetSystemTime_ms();
IF d.raw_value <> d.prev_value THEN
d.transition_count := d.transition_count + 1;
dt_ms := now_ms - d.last_change_ms;
d.actual_hz := 1000.0 / DWORD_TO_REAL(dt_ms + 1);
d.last_change_ms := now_ms;
d.alarm_stuck := FALSE; // Activity: clear stuck alarm
END_IF;
d.state_duration := now_ms - d.last_change_ms;
// Stuck-at detection: no change for too long
d.alarm_stuck := (d.state_duration > TIME_TO_DWORD(d.stuck_timeout))
AND (d.expected_hz > 0.0); // Only if cyclic expected
// Rate alarms (for cyclic inputs like cam-driven sensors)
IF d.expected_hz > 0.0 THEN
d.alarm_fast := d.actual_hz > d.expected_hz * 2.0; // >2× expected
d.alarm_slow := d.actual_hz < d.expected_hz * 0.5; // <50% expected
END_IF;
d.prev_value := d.raw_value;
END_PROCEDURE
Voltage thresholds, PNP/NPN wiring, safety architectures, noise diagnosis, and IO-Link — all tested with detailed technical explanations.
A PLC digital input card specifies "PNP (sourcing), 24 V DC, 4 mA minimum". A field sensor supplies only 2 mA at 24 V. What will happen?
What is the difference between a "sourcing" (PNP) output and a "sinking" (NPN) output?
A proximity sensor output is connected directly to a PLC input that is already wired to another sensor (OR connection). Both sensors are NPN type. What protection is needed?
IEC 61131-2 defines input voltage thresholds for "Type 1" 24V DC inputs. What are the logic 0 and logic 1 voltage windows?
An output card drives a 24V DC solenoid valve coil rated 2W. The card spec says 0.5A max per output. How many channels can the card safely drive simultaneously from a single 2A fuse group?
What is "input filter time" (debounce) on a PLC digital input, and when must it be set very low?
A safety relay requires two NC (normally closed) contacts from an E-Stop button for IEC 62061 SIL 2 compliance. Your button only has one NC contact. What is the correct solution?
What causes "voltage drop" problems in long cable runs to digital inputs, and how is it calculated?
What is "diagnostics per channel" on a modern IO-Link or safety I/O module, and why is it valuable?
A PLC output drives a relay coil. After months of operation, the relay coil is drawing progressively more current and running hot. The coil resistance has dropped from 480Ω to 200Ω. What is the fault and what is the risk?