Learn PLCs free
Intermediate1 hourPhotoeye triggeringEdge detectionPneumatic actuator timingCounter

Conveyor with Photoeye Sort

A classic packaging-line application: photoeye detects a passing part, a downstream pneumatic pusher fires after a calculated delay, sorting the part into a reject bin. The example covers edge detection, calibrated timing, and counting.

Sequence overview showing inputs flowing into PLC logic and outputs driving actuators, with this example named Conveyor with Photoeye Sort.Process flow: inputs → logic → outputsInputsPhotoeyeA, PhotoeyeB, RejectFlag3 signalsPLC LogicPhotoeye triggering · Edge detectionIntermediate · 1 hourOutputsConvRun, Pusher2 signals

I/O list

TagTypeDescription
ConvRunDOConveyor motor run command
PhotoeyeADIUpstream photoeye (part detected)
PhotoeyeBDIDownstream photoeye (sort confirmation)
RejectFlagDIQuality reject signal from upstream inspection
PusherDOPneumatic pusher solenoid
RejectCountINTTotal rejects this shift

Structured Text code

PROGRAM main
VAR
    PartDetect       : R_TRIG;
    PartConfirm      : R_TRIG;
    PusherDelayTimer : TON;
    PusherFireTimer  : TP;          (* Pulse timer for actuator *)
    PartInQueue      : ARRAY[0..9] OF BOOL;  (* simple FIFO *)
    QueueIdx         : INT;
END_VAR

(* Conveyor always running in this example *)
ConvRun := TRUE;

(* Detect part entering: rising edge on PhotoeyeA *)
PartDetect(CLK := PhotoeyeA);
IF PartDetect.Q THEN
    PartInQueue[QueueIdx] := RejectFlag;     (* remember if this part is reject *)
    QueueIdx := (QueueIdx + 1) MOD 10;
END_IF;

(* When part reaches the pusher (PhotoeyeB rises), check the queue *)
PartConfirm(CLK := PhotoeyeB);
IF PartConfirm.Q THEN
    (* Check queue head — if reject, fire pusher *)
    IF PartInQueue[(QueueIdx - 1 + 10) MOD 10] THEN
        PusherFireTimer(IN := TRUE, PT := T#200ms);
        RejectCount := RejectCount + 1;
    END_IF;
END_IF;

Pusher := PusherFireTimer.Q;

How it works

Edge detection: R_TRIG fires once when the photoeye transitions from off to on, even if the photoeye stays on for several seconds while the part passes.

FIFO queue: as parts pass the upstream photoeye, their reject status is queued. As they reach the downstream pusher photoeye, the queue is checked.

Pulse timer (TP): fires the pusher for exactly 200 ms regardless of how long the photoeye stays triggered. Critical for pneumatic actuator sequencing.

Reject counter: increments only when the pusher actually fires.

More examples