Divider or optocoupler, calculated and checked against PLC input thresholds
Values rounded to the E24 series (resistors) and E6 (capacitor). For the divider, the guaranteed thresholds of a CMOS input are used: 0 below 0.3·VDD and 1 above 0.7·VDD. The standard's voltages and currents are indicative; for equipment that must comply, check the text of IEC 61131-2.
In industrial automation, sensors, limit switches, push buttons and PLC outputs work at 24 V DC, while a microcontroller accepts at most its own supply, 3.3 or 5 V. In addition, field lines are long and carry spikes, noise from motors and contactors, and sometimes wiring mistakes. A 24 V input for a microcontroller must reduce the voltage, limit the current, set a clear threshold between 0 and 1, filter noise and survive a wrong connection.
The programmable controller standard defines three types of 24 V DC digital input, with voltage and current zones for the ON state, the OFF state and a transition zone between them. Meeting them guarantees that the input works with any sensor that also meets them.
| Type | ON | OFF | Use |
|---|---|---|---|
| Type 1 | 15 to 30 V, 2 to 15 mA | Up to 5 V (or up to 15 V with less than 0.5 mA) | Mechanical contacts: push buttons, limit switches, relays |
| Type 2 | 11 to 30 V, 6 to 30 mA | Up to 5 V (or up to 11 V with less than 2 mA) | Older two-wire proximity sensors with high leakage current |
| Type 3 | 11 to 30 V, 2 to 15 mA | Up to 5 V (or up to 11 V with less than 1.5 mA) | Modern two-wire proximity sensors; the most common today |
The minimum ON current is not a whim: it cleans mechanical contacts and ensures that the small leakage current of an idle two-wire sensor is not read as a 1.
Two resistors reduce the 24 V to the microcontroller voltage. It is the cheapest option, but the input is not isolated: the microcontroller ground and the field 0 V must be connected. The problem is fitting both the maximum voltage and the thresholds: if 30 V must give at most 3.3 V, the guaranteed logic 1 is not reached until about 21 V, which is too high. That is why the divider is calculated for the thresholds and a clamp cuts off the high voltages:
The LED of an optocoupler receives the 24 V signal through R1 and the phototransistor pulls the microcontroller pin to ground through a pull-up resistor. This way the field side and the logic are isolated: a spike or a wiring mistake does not reach the microcontroller. It is the solution used in almost all PLCs and input modules. Three things must be taken into account:
There are ICs that do all this with current limiting, such as the MAX22191 or the ISO1211, which dissipate much less power than a resistor because they keep the current constant over the whole voltage range.
A PNP ("sourcing") sensor gives +24 V when activated, and the input goes between the signal and 0 V: this is the case covered by this calculator and the usual one in Europe. An NPN ("sinking") sensor connects the signal to 0 V when activated, and the input must go between +24 V and the signal. With an optocoupler, an input valid for both types can be made using an optocoupler with two LEDs in antiparallel, such as the PC814, and a common terminal that is taken to 0 V or to +24 V.
Related: optocoupler, logic level shifting, pull-up and pull-down resistors and ladder simulator.