Applications of Type PNP and NPN Sensors

What assumption can we make about the PLC’s digital inputs?

This post presents the “how to” and the “why” for connecting type PNP and NPN industrial sensors to a typical Programmable Logic Controller (PLC). We will concentrate on PLCs with 24 VDC digital inputs. We will also assume that the PLC features digital positive-logic thresholds defined as:

  • voltages less than 5 VDC are considered logic-zero
  • voltages greater than 15 VDC are considered logic-one

Finally, we will assume each of the PLC’s I/O pins has a static 10 kΩ input resistance.

Be sure to verify these specifications against your PLC’s data sheet as there are PLCs outside of this typical range. Also, recognize that some PLCs have negative logic inputs. This will not be addressed in this post, other than to say that the core message is flipped.

What are PNP and NPN industrial sensors?

The term PNP and NPN refer to the sensor’s output configuration. Three-wire industrial sensors are typically sold as type NPN or PNP with sinking and sourcing outputs respectively. Many sensors are available in both configurations.

NPN and PNP sensors look identical, and the part numbers are often closely related. This can lead to purchasing errors and delays. This is especially true in PLC applications where there is a natural preference for the sourcing PNP type.

The NPN and PNP designation refer to the internal construction of the sensor, specifically the type of transistor used in the output stage. Recall that there are two types of transistors including the NPN and the PNP. Perhaps you once used an NPN transistor in a project such as the venerable 2N3904. The classic configuration is to ground the NPN transistor’s emitter, place the load between the positive power supply and the collector, and then drive the base through a current limiting resistor. In this configuration, the transistor pulls the load down to ground (sinking current).

The configuration using a PNP transistor is a bit different. Now, the PNP transistor’s emitter is tied to the positive power supply. The load is connected between the collector and ground. When the base is activated, the transistor pulls the load up to the positive voltage rail (sourcing current).

We can summarize this by simply stating:

  • PNP pulls up
  • NPN pulls down

In the language of PLC and industrial controls:

  • PNP sources current
  • NPN sinks current

Why is the PNP sensor to PLC interface preferred?

The PNP type sensor to PLC configuration is presented as Figure 1. The three-wire sensor is presented as a block containing a generic sensor module and a PNP output transistor. This is a relatively simple configuration especially when we consider the constraints identified in the opening section.

When activated, the PNP transistor pulls up against the PLC’s input resistance. In an ideal situation, the PNP transistor will be fully turned on and the voltage on the black wire will be 24 VDC. The PLC will identify this as a logic-one as it is considerably higher than the previously identified 15 VDC threshold.
When deactivated, the PNP transistor does not pull. Consequently, the voltage on the black wire will be zero and the PLC will register a logic-zero.

Figure 1: Schematic showing the typical PNP sensor to PLC interface

Tech Tip: The three-wire open collector configuration allows sensors to be connected in parallel using a wired OR configuration. You can find additional information about this type of configuration in this related post. While this is a valid configuration, the system will be easier to troubleshoot if each sensor is connected to an independent PLC channel.

NPN sensor to PLC interface

Figure 2 presents the NPN sensor to PLC interface. The added complexity is immediately apparent. You can now understand why the PNP sensor if the preferred solution given the constraint we identified earlier. The PNP sensor circuit is simplified because the sensor’s output pulls up against the PLC’s input resistance.

Necessity of an external pull up resistor

Recall that the NPN transistor pulls the load down. The external 1 kΩ resistor is an essential component as it provides the critical load for the NPN transistor to pull against. Without this external resistor, the sensor’s output (black) wire will always be zero. Many technicians and engineers have fallen into this trap wondering why the sensor is “defective” when it is incorrectly configured.

We need to step back at this point and apply Ohm’s law to ensure the external resistor is sufficient. For a moment, let’s ignore the sensor. What remains is a voltage divider between the external 1 kΩ and the PLC’s internal 10 kΩ resistor. Using the voltage divider rule we can calculate the PLC input voltage as:

V_{PLC} = 24 * \dfrac{10 }{1 + 10} \approx 22\ VDC

This voltage will be safely interpreted as a logic-one by the PLC.

We can now activate the sensor. It will pull at the center of this 22 VDC voltage divider to ground. In an ideal situation, the PLC’s input voltage will now be zero.

Figure 2: Schematic showing the typical NPN sensor to PLC interface featuring an external pull up resistor

How to correct the PNP vs NPN logic inversion

At this point, you may be tempted with the belief that NPN and PNP sensors are interchangeable. This is almost true. Looking back, we interpret an active PNP sensor as a logic-one. Contrasted with an active NPN sensor interpreted as a logic-zero.

Changing sensor types will require a modification to the PLC program to account for the inversion. Hopefully, the programmer used input mapping and the associated I/O pin appears in one and only one location. With I/O mapping this will be an easy change that you can make with confidence. Without a map – well maybe just wait for the correct sensor to arrive, but that is another story.

Best Wishes,

APDahlen

P.S. Sensor selection between a PNP and NPN should be guided by failsafe considerations. Always ask what will happen if there was a broken wire or a sensor failure. This is related to the concept of an emergency stop. As a rule, things that stop a machine should be wired using normally closed contacts so that a broken wire will turn off the machine.

About the Author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians. Dahlen has returned to his Northern Minnesota home and thoroughly enjoys researching and writing articles such as this. LinkedIn | Aaron Dahlen - Application Engineer - DigiKey

Return to the Industrial Control and Automation Index

Thank you. Do you have any content in your website that can help newbies to learn about PLC?

Thank you, bidrohini.

At this point there is limited PLC data on this forum. Perhaps we can change that in the future. For now I will refer you to:

Please let us know if these links are useful. Also, if you are reading this, please add additional links or comments below.

Best Wishes,

APDahlen

1 Like

Thanks a lot. I will check these out soon.

1 Like