📖 Scenario: You are setting up a simple PLC program to read digital inputs from sensors. There are two common sensor wiring types: NPN (sinking) and PNP (sourcing). Understanding how to read these inputs correctly in your PLC program is important for automation tasks.In this project, you will create a small program that simulates reading digital inputs from both NPN and PNP sensors and determines if the sensor is active (ON) or not.
🎯 Goal: Build a PLC program that defines digital input signals for NPN and PNP sensors, configures a threshold to detect ON state, applies logic to interpret the sensor signals correctly, and outputs the sensor status.
📋 What You'll Learn
Create variables to represent digital input signals from NPN and PNP sensors with exact values
Add a configuration variable to represent the ON threshold voltage level
Write logic to determine if each sensor is ON based on the threshold
Print the ON/OFF status of both sensors
💡 Why This Matters
🌍 Real World
In industrial automation, correctly reading digital inputs from NPN and PNP sensors is essential for controlling machines and processes safely and reliably.
💼 Career
PLC programmers and automation engineers must understand sensor wiring types and how to interpret their signals in software to build effective control systems.
Progress0 / 4 steps
1
Define digital input signals for NPN and PNP sensors
Create two variables: npn_input with value 0 and pnp_input with value 24 to represent the voltage levels from NPN and PNP sensors respectively.
PLC Programming
Hint
Use simple variable assignments to set the voltage levels for each sensor input.
2
Set the ON threshold voltage level
Create a variable called on_threshold and set it to 12 volts. This threshold will be used to decide if a sensor input is ON or OFF.
PLC Programming
Hint
The threshold is a simple number variable representing voltage.
3
Determine if each sensor is ON based on the threshold
Write logic to create two boolean variables: npn_on and pnp_on. Set npn_on to True if npn_input is less than on_threshold (because NPN sinks current), otherwise False. Set pnp_on to True if pnp_input is greater than or equal to on_threshold (because PNP sources current), otherwise False.
PLC Programming
Hint
Use comparison operators < and >= to compare inputs with the threshold and assign boolean results.
4
Print the ON/OFF status of both sensors
Write two print statements to display the status of the sensors. Print "NPN Sensor ON: {npn_on}" and "PNP Sensor ON: {pnp_on}" using f-strings.
PLC Programming
Hint
Use print() with f-strings to show the boolean status variables.
Practice
(1/5)
1. What is the main difference between NPN and PNP sensors in digital input wiring?
easy
A. NPN sensors pull the input to ground; PNP sensors supply positive voltage.
B. NPN sensors supply positive voltage; PNP sensors pull the input to ground.
C. Both NPN and PNP sensors supply positive voltage.
D. Both NPN and PNP sensors pull the input to ground.
Solution
Step 1: Understand NPN sensor behavior
NPN sensors connect the input to ground (0V) when active, sinking current.
Step 2: Understand PNP sensor behavior
PNP sensors connect the input to positive voltage (e.g., 24V) when active, sourcing current.
Final Answer:
NPN sensors pull the input to ground; PNP sensors supply positive voltage. -> Option A
2. Which wiring connection is correct for a PNP sensor to a PLC digital input?
easy
A. Sensor output connected to PLC input; sensor negative to +24V; sensor positive to +24V.
B. Sensor output connected to 0V; sensor negative to PLC input; sensor positive to +24V.
C. Sensor output connected to PLC input; sensor negative to 0V; sensor positive to +24V.
D. Sensor output connected to PLC input; sensor negative to +24V; sensor positive to 0V.
Solution
Step 1: Identify PNP sensor wiring
PNP sensors source positive voltage to the PLC input; sensor positive terminal connects to +24V, negative to 0V.
Step 2: Confirm correct PLC input connection
Sensor output wire connects directly to the PLC digital input to supply voltage when active.
Final Answer:
Sensor output connected to PLC input; sensor negative to 0V; sensor positive to +24V. -> Option C
Quick Check:
PNP sources +24V to input = D [OK]
Hint: PNP sensor positive to +24V, output to input, negative to 0V [OK]
Common Mistakes:
Reversing sensor positive and negative connections
Connecting sensor output to 0V instead of PLC input
Mixing NPN wiring rules with PNP sensors
3. Given this PLC input wiring with an NPN sensor, what will the PLC input read when the sensor is active? Sensor output connected to PLC input; sensor negative to 0V; sensor positive to +24V.
medium
A. PLC input reads HIGH (24V)
B. PLC input reads an error signal
C. PLC input reads fluctuating voltage
D. PLC input reads LOW (0V)
Solution
Step 1: Understand NPN sensor active state
When active, NPN sensor pulls output to 0V (ground), sinking current.
Step 2: Determine PLC input voltage
Since sensor output connects to PLC input and is pulled to 0V, PLC input reads LOW (0V).
Final Answer:
PLC input reads LOW (0V) -> Option D
Quick Check:
NPN active pulls input LOW = B [OK]
Hint: NPN active means input pulled to ground = LOW [OK]
Common Mistakes:
Assuming NPN sensor outputs positive voltage when active
Confusing sensor wiring polarity
Thinking input voltage fluctuates instead of stable LOW
4. A technician wired a PNP sensor but the PLC input never reads HIGH. Which is the most likely wiring mistake?
medium
A. Sensor output connected to 0V instead of PLC input.
B. Sensor positive connected to 0V instead of +24V.
C. Sensor negative connected to +24V instead of 0V.
D. Sensor output connected to PLC input correctly.
Solution
Step 1: Review correct PNP wiring
PNP sensor output must connect to PLC input to supply positive voltage when active.
Step 2: Identify wiring mistake
If sensor output is connected to 0V instead of PLC input, input never receives voltage, so PLC reads LOW always.
Final Answer:
Sensor output connected to 0V instead of PLC input. -> Option A
Quick Check:
Output must connect to input, not 0V = A [OK]
Hint: Output wire must go to PLC input, not ground [OK]
Common Mistakes:
Connecting sensor output to 0V instead of input
Swapping sensor positive and negative wires
Assuming PLC input reads HIGH without proper wiring
5. You have a PLC input configured for sourcing (PNP) sensors but only NPN sensors are available. How should you wire the NPN sensor to ensure the PLC reads the input correctly?
hard
A. Connect the NPN sensor output to 0V and sensor positive to PLC input.
B. Use an external pull-up resistor to +24V on the PLC input and connect the NPN sensor output to the input and sensor negative to 0V.
C. Connect the NPN sensor output directly to +24V and sensor negative to PLC input.
D. Wire the NPN sensor as a PNP sensor without any changes.