How to connect NPN and PNP sensors

How to connect NPN and PNP sensors

From time to time, Yoctopuce support receives questions from customers who do not quite know what to do with the three wires coming out of a PNP or NPN sensor. This week, we are going to tell you how these NPN and PNP outputs work, how to connect them, and with which modules.




NPN and PNP interfaces

This type of NPN or PNP output is widespread in the industrial world. It's used for example in proximity sensors, but you can also find them in more exotic sensors such as bubble sensors. These outputs provide binary (ON/OFF) information, and not an analogical value. You therefore find them mostly in detectors rather than in measuring devices.

A few proximity sensors equipped with NPN or PNP outputs
A few proximity sensors equipped with NPN or PNP outputs



These outputs have three wires with standard, although counter-intuitive, colors:

  • Brown: Power supply, usually 12 to 24V
  • Blue: Ground
  • Black: Signal

PNP or NPN, there are always these three wires: blue, black, and brown
PNP or NPN, there are always these three wires: blue, black, and brown



How this type of output works is relatively simple: the sensor acts as a simple switch.

PNP outputs

When a sensor with a PNP output is activated, it puts into contact the signal wire with the power supply wire. The voltage on the signal wire therefore changes to the value of the power supply voltage. It has the advantage of being very simple, but you can't really choose the signal output voltage.

How PNP outputs work
How PNP outputs work


NPN outputs

NPN outputs work the other way around. When the sensor is active, it puts into contact the output wire with ground. Which means that it doesn't inject current in the output wire. Therefore, for the change to be detected, someone has to put some voltage on the wire. It's the job of a pull-up.

How NPN outputs work
How NPN outputs work


A pull-up consists simply in connecting a signal line to any voltage with the help of a resistance. In our case, when the sensor is idle, the signal line is at the pull-up voltage and when the sensor is active, voltage goes to zero. Note, a resistance is compulsory. If you directly connect the signal line to the voltage source, there is going to be a short-circuit as soon as the sensor puts together the signal wire and ground. The typical value of a pull-up resistance is 4.7kΩ. In the case of Yoctopuce modules, you don't need to add an external resistance: pull-ups are embedded in the modules.

The pull-up principle
The pull-up principle


The advantage of NPN outputs is the possibility to choose an arbitrary signal voltage. Note that an NPN output works in the opposite way to a PNP output: signal goes to zero when the sensor is active.

Use with Yoctopuce modules

You can use essentially three types of Yoctopuce modules to easily interpret an NPN or PNP outputs and to exploit them by USB. They are the Yocto-IO, the Yocto-PWM-Rx, and the Yocto-Knob.

The Yocto-IO, the Yocto-PWM-Rx, and the Yocto-Knob
The Yocto-IO, the Yocto-PWM-Rx, and the Yocto-Knob


The Yocto-IO

The Yocto-IO and its big brother the Yocto-Maxi-IO-V2 are the perfect interfaces to read a PNP or NPN output. However, as these modules cannot provide more than 5V, you'll probably need an external power supply to power your sensor.

What you have to do is:

  1. To configure the Yocto-IO for an external power supply
  2. To connect ground (-) of the external power supply and the sensor blue wire on the module ground
  3. To connect the (+) of the external power supply and the sensor brown wire on the external Power (pwr) input
  4. To connect the black wire on the channel of your choice
  5. To configure the corresponding channel as input
  6. If you use an NPN sensor, you must also configure the corresponding input in "open drain" mode to enable the internal pull-up. In the opposite, if you use a PNP sensor, disable open drain.


Connecting
<br>to a Yocto-IO  The same, for real
Connecting to a Yocto-IO

The Yocto-PWM-Rx

The Yocto-PWM-Rx can also read an NPN or PNP output. It measures a 0% duty-cycle when the input is zero and a 100% duty-cycle when the input is 1. It even has a pulse counter enabling to precisely count the number of transitions happening in a given time frame. It can count tens of thousands transitions par second. However, its reaction time to detect a modification of the duty-cycle from 0 to 100%, and from 100 to 0%, is relatively long, in the order of one second. That's why one can use it to count objects passing ahead of a sensor, even if they are very fast, but one can't use it to know exactly when an object is front of the sensor. As with the Yocto-IO, you need an external power supply for your sensor.

The NPN sensor:

To interface an NPN sensor with a Yocto-PWM-Rx, you need:

  1. To connect ground (-) of the external power supply and the sensor blue wire on the module ground
  2. To connect the (+) of the external power supply and the brown wire of the sensor together
  3. To connect the black wire on the channel of your choice and the on the corresponding pull-up (PU) input


Connecting an NPN output to a Yocto-PWM-Rx  The same, for real
Connecting an NPN output to a Yocto-PWM-Rx


The PNP sensor:

To interface a PNP sensor with a Yocto-PWM-Rx, you need:

  1. To connect ground (-) of the external power supply and the sensor blue wire on the module ground
  2. To connect the (+) of the external power supply and the sensor brown wire together
  3. To connect the black wire on the channel of your choice

Connecting a PNP output to a Yocto-PWM-Rx  The same, for real
Connecting a PNP output to a Yocto-PWM-Rx

The Yocto-Knob

The Yocto-Knob is a cheap solution, which works with NPN outputs but not with PNP ones. There as well, you need an external power supply. To connect an NPN sensor to a Yocto-Knob, you need:

  1. To connect ground (-) of the external power supply and the sensor blue wire on the module ground
  2. To connect the (+) of the external power supply and the sensor brown wire together
  3. To connect the black wire on the channel of your choice

Connecting an NPN output on a Yocto-Knob  The same, for real
Connecting an NPN output on a Yocto-Knob


Note, the Yocto-Knob is much less expensive than the Yocto-PWM-Rx or the Yocto-IO and there is a reason for this: the Yocto-Knob is not an isolated module. You must therefore ensure that the external power supply of the sensor and that of the Yocto-Knob can share the same ground and that they are powered from the same phase. Otherwise, you have a high risk of blowing a few components.

Conclusion

As a conclusion, here is a little table explaining the main differences between all four device when used for interfacing NPN ou PNP outputs.

Yocto-IOYocto-maxi-IO-V2Yocto-PWM-rxYocto-Knob
PNP-
NPN
Channels4825
Latency <1s-
Counters--
Isolation-


Here you are, you know everything. You can now buy sensors with an NPN or PNP output knowing that you can interface them with Yoctopuce modules.

Add a comment No comment yet Back to blog












Yoctopuce, get your stuff connected.