Photoelectric Sensors: Types, Wiring and PLC Use


Flat vector infographic of three photoelectric sensor modes connected to a PLC rack, showing through-beam, retro-reflective and diffuse beam paths on a conveyor

Photoelectric sensors are probably the most versatile discrete sensor you will wire to a PLC input. They detect objects without touching them, work across large distances, and come in configurations that handle everything from shiny metal cans to translucent packaging film. But pick the wrong mode, wire it to the wrong input type, or mount it an inch too far, and you will spend a shift chasing ghost faults. This guide covers the three main operating modes, wiring to a PLC, output type selection and the real-world problems that trip people up.

What Is a Photoelectric Sensor in a PLC System?

A photoelectric sensor detects the presence, absence, distance or position of an object by emitting a beam of light (typically infrared or visible red laser) and measuring what returns to a receiver. When the detection condition is met, the sensor switches its output ON or OFF, delivering a discrete 24 VDC signal directly to a PLC digital input module. The PLC reads that signal every scan cycle and acts on it in ladder logic or structured text.

Three Photoelectric Sensor Operating Modes

The operating mode determines the physical installation, the achievable range, and what types of targets the sensor handles reliably. Getting this choice right at the design stage saves a lot of pain.

Through-Beam (Opposed Mode)

The emitter and receiver are separate units mounted facing each other across the detection zone. An object triggers the sensor by breaking the beam. This mode offers the longest range (5 to 60 m on most industrial units), the highest immunity to surface colour and reflectivity, and reliable detection of transparent objects like glass bottles or clear film. The downside is that you need conduit runs and wiring to two separate locations, which adds installation cost.

Through-beam is the right choice for wide conveyor gaps, end-of-line gates, or any application where the target is clear or semi-transparent. I have used Keyence's PZ-G series for detecting clear PET bottles on a filling line, and through-beam was the only mode that worked without constant nuisance trips.

Retro-Reflective Mode

Emitter and receiver share a single housing. The sensor fires a beam at a corner-cube reflector mounted on the opposite side, and the receiver looks for that returned beam. An object breaks the path between sensor and reflector, triggering the output. Range is typically 0.1 to 10 m depending on reflector size. You only need to wire one device, but you do need to mount and align the reflector, which is still two mechanical fixings.

One gotcha: shiny objects (polished metal cans, reflective labels) can bounce enough light back to the receiver to fool the sensor into thinking the beam is unbroken even when the target IS in the beam path. Polarised retro-reflective sensors add a polarising filter that only accepts light polarised by the corner-cube reflector, rejecting reflections from shiny targets. If your product is specular, specify the polarised version.

Diffuse (Proximity) Mode

Emitter and receiver are again in one housing, but this time the sensor uses light reflected directly from the target surface. No reflector needed. This is the simplest installation: one device, one mounting bracket, one cable run. Range is limited, typically 20 to 300 mm for standard diffuse sensors, though background-suppression (BGS) variants extend that to 1 to 2 m while ignoring anything beyond the set distance window.

Standard diffuse sensors are sensitive to target colour and surface finish because dark or matte targets absorb more light and return a weaker signal. A BGS sensor using triangulation is far more consistent across mixed-colour products. Use diffuse mode for close-range presence detection where running wiring to a second location or a reflector is impractical.

ModeRangeWiring PointsBest ForAvoid When
Through-beam5 to 60 m2 (emitter + receiver)Clear objects, wide gaps, high reliabilityWiring to two sides is impractical
Retro-reflective0.1 to 10 m1 + reflectorMedium range, one-side accessShiny/specular targets (use polarised variant)
Diffuse standard20 to 300 mm1Close range, simple installMixed colours, dark targets, background clutter
Diffuse BGS50 mm to 2 m1Mixed products, background rejection neededTransparent objects
Photoelectric sensor mode comparison for PLC applications

Photoelectric Sensor Output Types and PLC Input Matching

Most photoelectric sensors have a 3-wire or 4-wire output. The critical decision is NPN vs PNP, which determines whether the sensor switches to 0 V (NPN, sinking) or to 24 V (PNP, sourcing). This must match the input type of your PLC module. If you wire a PNP sensor to a sinking-only input, or an NPN sensor to a sourcing-only input, the input will either never see a valid signal or you risk damaging the module. The post on NPN vs PNP sensors and PLC wiring covers this in detail, and the post on sinking vs sourcing PLC I/O explains the module side.

Many sensors also offer a light-on / dark-on selection, either via a physical switch or a teach button. Light-on (L.O.) means the output activates when the receiver sees the beam. Dark-on (D.O.) means the output activates when the beam is broken. For through-beam sensors used for object detection, dark-on is the normal choice: the output goes ON when an object interrupts the beam. Always confirm this setting during commissioning because it is easy to wire a sensor correctly but have the logic inverted by a wrong L.O./D.O. setting.

4-wire sensors provide both an NPN and a PNP output simultaneously. They cost slightly more but give you flexibility if you are not sure which input type your PLC module uses, or if you need to feed the same sensor signal to two different destinations.

How to Wire a PNP Photoelectric Sensor to a PLC Input

The industry standard wire colours for 3-wire DC sensors follow IEC 60947-5-2: brown to 24 VDC positive, blue to 0 V common, and black to the signal output. For a PNP sensor the black wire connects to the PLC input terminal. When the sensor detects a target, it pulls the black wire to approximately 24 V, which the PLC reads as logic 1. See the 3-wire sensor wiring guide for wiring diagrams of both polarities.

Flat vector wiring diagram of a PNP photoelectric sensor with brown, blue and black wires connected to a PLC sourcing input terminal and 24 VDC supply
PNP photoelectric sensor wiring to a PLC sourcing input module

Keep the sensor cable away from motor power cables and VFD output cables. Photoelectric sensors are susceptible to electrical noise, especially the high-frequency switching noise from drives. Route sensor cables in a separate trunking and use shielded cable for runs over 5 m, grounding the shield at the panel end only. The post on shielding analog signal cables covers the grounding principle, and the same approach applies here.

Photoelectric Sensor PLC Ladder Logic Example

A through-beam sensor on a conveyor exit gate feeds an input tag. When the beam breaks (sensor output goes ON in dark-on mode), the PLC should latch a part-present flag, start a 500 ms verification timer to filter spurious pulses, and only count the part after the timer completes. This avoids false counts from vibration or a slow-moving part edge. You can try a similar debounce circuit yourself in the interactive debounce exercise.

Through-Beam Sensor: Verified Part Detection with TON Debounce (Studio 5000). Ladder logic (5 rungs): Rung 0: examine if Gate_PhotoEye is on (XIC), then TON on Eye_Verify. Rung 1: examine if Eye_Verify.DN is on (XIC), then examine if Part_Count_Latch is off (XIO), then examine if Count_OS is on (XIC), then CTU on Exit_Counter. Rung 2: examine if Exit_Counter.DN is on (XIC), then examine if Batch_DN_OS is on (XIC), then latch output Batch_Done_Latch (OTL). Rung 3: examine if Batch_Done_Latch is on (XIC), then examine if HMI_BatchReset is on (XIC), then unlatch output Batch_Done_Latch (OTU), then either RES on Exit_Counter. Rung 4: examine if Gate_PhotoEye is off (XIO), then RES on Eye_Verify. Gate_PhotoEye goes ON when the through-beam is broken (dark-on mode). A 500 ms TON filter confirms the detection is not a glitch. On timer completion, a one-shot increments the batch counter. The counter latches Batch_Done_Latch at preset. Clearing the beam resets the verify timer so the next part starts fresh. This prevents double-counting from a part pausing in the beam.

Through-Beam Sensor: Verified Part Detection with TON Debounce (Studio 5000)Ladder logic
Toggle inputs
Rung 0
Ladder logic rung: examine if Gate_PhotoEye is on (XIC), then TON on Eye_Verify examine if Gate_PhotoEye is on (XIC), then TON on Eye_Verify XIC Gate_PhotoEye Gate_PhotoEye Gate_PhotoEye TON Eye_Verify 500 0 TONTimerEye_VerifyEye_VerifyPreset500500Accum00
Rung 1
Ladder logic rung: examine if Eye_Verify.DN is on (XIC), then examine if Part_Count_Latch is off (XIO), then examine if Count_OS is on (XIC), then CTU on Exit_Counter examine if Eye_Verify.DN is on (XIC), then examine if Part_Count_Latch is off (XIO), then examine if Count_OS is on (XIC), then CTU on Exit_Counter XIC Eye_Verify.DN Eye_Verify.DN Eye_Verify.DN XIO Part_Count_Latch Part_Count_Latch Part_Count_Latch OSR Count_OS Count_OS_Bit Count_OS Count_OS OSR Count_OS_Bit Count_OS_BitCTU Exit_Counter 9999 0 CTUCounterExit_CounterExit_CounterPreset99999999Accum00
Rung 2
Ladder logic rung: examine if Exit_Counter.DN is on (XIC), then examine if Batch_DN_OS is on (XIC), then latch output Batch_Done_Latch (OTL) examine if Exit_Counter.DN is on (XIC), then examine if Batch_DN_OS is on (XIC), then latch output Batch_Done_Latch (OTL) XIC Exit_Counter.DN Exit_Counter.DN Exit_Counter.DN OSR Batch_DN_OS Batch_DN_Bit Batch_DN_OS Batch_DN_OS OSR Batch_DN_Bit Batch_DN_BitOTL Batch_Done_Latch Batch_Done_Latch Batch_Done_Latch L
Rung 3
Ladder logic rung: examine if Batch_Done_Latch is on (XIC), then examine if HMI_BatchReset is on (XIC), then unlatch output Batch_Done_Latch (OTU), then either RES on Exit_Counter examine if Batch_Done_Latch is on (XIC), then examine if HMI_BatchReset is on (XIC), then unlatch output Batch_Done_Latch (OTU), then either RES on Exit_Counter XIC Batch_Done_Latch Batch_Done_Latch Batch_Done_Latch XIC HMI_BatchReset HMI_BatchReset HMI_BatchReset OTU Batch_Done_Latch Batch_Done_Latch Batch_Done_Latch U RES Exit_Counter RESAccumulatorExit_CounterExit_Counter
Rung 4
Ladder logic rung: examine if Gate_PhotoEye is off (XIO), then RES on Eye_Verify examine if Gate_PhotoEye is off (XIO), then RES on Eye_Verify XIO Gate_PhotoEye Gate_PhotoEye Gate_PhotoEye RES Eye_Verify RESAccumulatorEye_VerifyEye_Verify
energizedTip: click a contact in the diagram to flip its bit.
Gate_PhotoEye goes ON when the through-beam is broken (dark-on mode). A 500 ms TON filter confirms the detection is not a glitch. On timer completion, a one-shot increments the batch counter. The counter latches Batch_Done_Latch at preset. Clearing the beam resets the verify timer so the next part starts fresh. This prevents double-counting from a part pausing in the beam.

Alignment, Teach and Sensitivity Settings

Most modern photoelectric sensors have a multi-turn sensitivity potentiometer and a pair of indicator LEDs: one for power/output state, one for signal margin. During alignment you want the signal margin LED to be solid green (not flickering), which means the sensor is seeing the beam or the reflector with enough excess gain to handle lens contamination or slight misalignment over time. A flickering margin LED on day one means you will have nuisance faults within weeks.

Through-beam sensors need careful angular alignment. Most manufacturers spec a maximum angular deviation of plus or minus 3 to 5 degrees. On a long 20 m run that is still several centimetres of lateral tolerance at the receiver, but vibration from heavy machinery can walk the beam over time. Lock the mounts with thread-locking compound after alignment. I had a through-beam sensor on a press line that looked perfectly aligned at commissioning but dropped out every time the press cycled at full tonnage because the mount was bolted to the same frame as the press. Moving it to a free-standing post fixed it immediately.

Teach functions on diffuse and retro-reflective sensors let you set detection thresholds automatically by pressing a button with and without the target in place. This is far more reliable than manually turning the potentiometer and guessing. Use it.

Common Faults and How to Diagnose Them

Intermittent sensor faults on photoelectric sensors almost always trace back to one of four causes: dirty or fogged optics, marginal sensing distance or alignment, electrical noise, or a wiring connection that has vibrated loose. The post on intermittent sensor fault troubleshooting has a systematic method that applies directly. For suspected wiring issues, the PLC digital input fault diagnosis guide walks you through multimeter checks at the input terminal.

  • Output always ON regardless of target: check L.O./D.O. selection, verify the beam path is not permanently blocked or the reflector is missing.
  • Output never ON: check 24 V supply to sensor (brown wire), verify NPN/PNP match to input module, measure black wire voltage when target is present.
  • Random false triggers: look for ambient light sources (sunlight through a window, another sensor cross-talking), and check cable routing near VFD output cables.
  • Stable during setup but fails in production: usually thermal expansion shifting alignment, or lens contamination from coolant mist or dust.
  • PLC input LED flickers but logic does not see it: the signal duration may be shorter than the PLC scan time. Add a TON debounce timer in logic or use a sensor with output pulse stretching. See how the PLC scan cycle works for why this matters.
Never aim two through-beam emitters directly at each other's receivers in the same area without checking for cross-talk. If two sensors share a field of view, they can trigger each other. Use sensors with different modulation frequencies, or stagger them physically so their beams cannot interfere.

Choosing Between a Photoelectric and a Proximity Sensor

Inductive proximity sensors are simpler, cheaper and extremely resistant to noise and contamination, but they only detect ferrous (and some non-ferrous) metals at short range, typically 2 to 20 mm. Capacitive proximity sensors extend that to non-metals and liquids, still at short range. Photoelectric sensors detect any material, at much longer distances, with no contact. The tradeoff is that photoelectrics need clean optics and careful alignment. If your target is a steel part at 5 mm range in a dirty environment, an inductive proximity sensor wins every time. If it is a plastic bottle at 300 mm, a diffuse photoelectric is the right tool. The inductive vs capacitive proximity sensor comparison covers the proximity side in depth.

For PLC wiring mechanics, photoelectric sensors wire identically to proximity sensors: 3-wire or 4-wire, same 24 VDC supply, same PNP/NPN output to the digital input module. If you already know how to wire a proximity sensor to a PLC from the proximity sensor wiring guide, you already know how to wire a photoelectric sensor. The physics differ; the wiring does not.

An increasing number of photoelectric sensors now ship with IO-Link ports alongside the standard discrete output. IO-Link lets the PLC read signal strength, temperature, operating hours and error codes from the sensor over a single unshielded cable, and set parameters like sensitivity and threshold remotely without touching the sensor. This is genuinely useful on hard-to-reach mounting positions. If you are specifying new hardware and your PLC supports IO-Link masters, it is worth the small cost premium. The IO-Link explained guide covers how the master/device architecture works and how the data maps into the PLC.


If you want to go deeper on sensor wiring to PLC inputs, start with the 3-wire PNP vs NPN wiring guide and then the proximity sensor wiring to a PLC complete guide which shows terminal-level diagrams for several PLC families. To see a real counter application that uses a photoelectric sensor as the trigger, the PLC bottle filling machine project walks through a full ladder logic program. And if you want to practice counting parts from a sensor signal yourself, open the batch counting exercise in the interactive ladder editor and toggle the inputs to see the CTU in action.

Was this helpful?

Related Blogs

Flat vector wiring diagram comparing NPN and PNP sensor connections to a PLC digital input module showing current flow direction for each type
npn vs pnp sensorssensor wiringplc inputs

NPN vs PNP Sensors: Wiring and PLC Connection

NPN and PNP sensors switch current in opposite directions. Get the wrong one for your PLC input card and the signal never works. Here is how to tell them apart and wire each type correctly.

Aug 5, 2026 · 8 min read

Flat vector diagram comparing an inductive proximity sensor detecting a metal gear and a capacitive proximity sensor detecting a plastic container, both wired to a PLC input module
proximity sensorsplc wiringsensor selection

Inductive vs Capacitive Proximity Sensors: Full Guide

Inductive and capacitive proximity sensors look identical but detect completely different targets. Learn the key differences, typical specs, and wiring rules for PLC integration.

Aug 5, 2026 · 9 min read

Flat vector diagram showing PNP and NPN proximity sensor wiring connections to a PLC input module with labeled wire colors and current flow arrows
proximity sensor wiringplc sensorspnp npn wiring

Proximity Sensor Wiring to a PLC: Full Guide

Learn how to wire 2-wire, 3-wire and 4-wire proximity sensors to a PLC input. Covers PNP and NPN types, color codes, sinking vs sourcing inputs, and common wiring mistakes.

Aug 5, 2026 · 9 min read

PNP and NPN 3-wire sensor wiring diagram to PLC input terminals
sensor wiringplc inputspnp npn

3-Wire Sensor Wiring: PNP vs NPN to PLC Inputs

PNP or NPN sensor, sinking or sourcing input? Learn exactly how to wire 3-wire sensors to any PLC input card with real wiring rules and common mistakes.

Jul 1, 2026 · 9 min read

Intermittent sensor fault troubleshooting diagram showing PLC, wiring, and signal dropout
intermittent sensor faultplc troubleshootingsensor diagnostics

Intermittent Sensor Faults: How to Find Them

Intermittent sensor faults in PLC systems are notoriously elusive. Learn how to capture, isolate and permanently fix them using real field techniques.

Jul 2, 2026 · 7 min read

Flat vector diagram of a PLC digital input module with sensor wiring and a multimeter measuring input voltage at a terminal block
plc input faultdigital input diagnosisplc troubleshooting

PLC Digital Input Faults: How to Diagnose Them

PLC digital input faults are deceptive. The status bit looks fine but the machine misbehaves. Here is how to systematically find the real cause in minutes.

Jul 27, 2026 · 9 min read