PNP and NPN sensor simulator
Wiring a 3-wire sensor to a PLC looks easy until the input refuses to light. Here you can connect an inductive PNP or NPN sensor to a 24 V supply and a PLC input, wire by wire, and see where the current flows, what voltage there is at every point and why it works or not. Make all the mistakes you like: nothing burns out here.
The sensor
Output type
Contact
The part
The PLC card
Wiring: which terminal does each wire go to?
What a multimeter would read
Find the fault
A correctly wired sensor is set up with a random fault, and you are not told which. Find it by moving the part and watching the LEDs and the measurements, just as you would at the machine.
Try this
How to use it
- Set-up: start with a correctly wired PNP or NPN sensor, or with no wires so you can connect it from scratch.
- The sensor: choose the output type (PNP or NPN) and the contact (NO or NC). It is an M12 inductive sensor with a 4 mm rated sensing distance.
- The part: change the material and drag the distance. The blue band on the ruler shows how far it detects.
- The card: bidirectional, like the built-in inputs of the S7-1200 CPU, or PNP only, like many remote I/O cards.
- Wiring: choose the terminal for each wire. The moving yellow dashes show where current flows, in the conventional direction (from + to −). Even when nothing is detected, the sensor’s own consumption, about 10 mA, flows through brown and blue.
- Measurements: what you would read with a multimeter at the sensor, at the input to 0 V, and between the input and its common. The input reads 1 from about 15 V (2.5 mA) and 0 below 5 V; in between is the undefined zone.
PNP vs NPN in one sentence
Both have three wires: brown to +24 V, blue to 0 V and black for the signal. The difference is what the black wire does when the sensor detects:
| PNP | NPN | |
|---|---|---|
| On detection, black goes to | +24 V (switches the positive) | 0 V (switches the negative) |
| With nothing detected, black is | left floating | left floating |
| The card common goes to | 0 V | +24 V |
| The PLC input | sinks current | sources current |
| Most common in | Europe | Asia and machines built there |
One way to remember it: the P in PNP goes with Positive, and the N in NPN goes with Negative.
Sinking and sourcing: the naming mess
Sinking and sourcing describe which way the current flows, seen from whoever is talking. A PNP sensor sources current and the input that receives it sinks it. With an NPN it is the other way round. The confusion comes from some manufacturers naming the card by how the input works and others by the sensor it accepts: a "sinking input" and a "PNP input" can be exactly the same thing. The safe approach is to look at the wiring diagram in the card manual, which shows where the common goes.
Some cards, like the built-in inputs of the S7-1200 CPU, accept current in both directions (inside there is a bidirectional optocoupler) and work with PNP or NPN depending on where you connect the common. Many remote I/O cards, however, only let it through one way. That is why an NPN on a "PNP only" card gives the right voltages and still does not light the input. Try it in the simulator.
Why almost everything in Europe is PNP
Picture a chafed signal wire rubbing against the machine frame, which is earthed and normally tied to 0 V. With a PNP, that rub is a short circuit: the sensor protects itself and the input stays at 0. With an NPN, touching 0 V is exactly what the sensor does on detection, so the input switches on by itself and the PLC thinks there is a part. A fault that gives a false signal is much worse than one that leaves the signal at zero. That is why Europe almost always uses PNP with the common at 0 V. NPN is common on machines from Asia, and North America uses both: check before ordering a replacement.
Note that neither PNP nor NPN turns a standard sensor into a safety device. Guards, light curtains and emergency stops are monitored with safety sensors and safety relays, not with standard PLC inputs.
Sensing distance and materials
The rated sensing distance (Sn) of an inductive sensor is measured with a standard steel target. Other metals are detected closer: multiply Sn by the correction factor from the datasheet. Typical values:
| Material | Factor | With Sn = 4 mm |
|---|---|---|
| Steel | 1 | 4 mm |
| Stainless steel | 0.6 to 1 (depends on the alloy) | 2.4 to 4 mm |
| Brass | 0.4 to 0.5 | 1.6 to 2 mm |
| Aluminium | 0.3 to 0.45 | 1.2 to 1.8 mm |
| Copper | 0.25 to 0.4 | 1 to 1.6 mm |
| Plastic, wood, cardboard | 0 | Not detected |
To make it work every time, you stay within the assured operating distance (Sa), which is 81 % of Sn: with a 4 mm sensor, the part should pass at 3.2 mm or less. A flush sensor, which can be mounted embedded in metal, has a shorter range than a non-flush one of the same size. And they all have hysteresis: they switch off a little further away than where they switch on, so the output does not chatter when the part vibrates right at the limit.
NO or NC
A normally open (NO) sensor switches its output on when it detects. An NC sensor does the opposite: its output is on while nothing is detected and goes off on detection. NC is used when a broken wire should be treated as the safe condition. For example, a high-level sensor on a tank: if it is NC, both "tank full" and "broken wire" leave the input at 0 and the pump stops. There are also 4-wire sensors with one NO and one NC output.
How to troubleshoot a sensor
- Check the power LED. If it is off, measure between brown and blue at the sensor itself or at its connector. If there are no 24 V, look for a broken wire or a blown fuse.
- Bring a part close and watch the output LED. If it does not light, check the distance, the material, and that the sensing face is clean and undamaged.
- If the LED lights but the PLC does not see it, measure between I0.0 and 1M, not between I0.0 and 0 V. With a PNP you should see about 22 or 23 V on detection.
- If there is voltage between I0.0 and 1M but the input LED stays off, the card is not reading it: either it is the wrong type, or that input is damaged.
- If the output LED flashes, on many sensors that warns of a short circuit or overload: look for a chafed or pinched black wire. Check the manual, because others flash when the part passes right at the edge of the range.
To understand the topic in depth: Commissioning with the programmer, with theory and a practice test.