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.
I/O list
| Tag | Type | Description |
|---|---|---|
| ConvRun | DO | Conveyor motor run command |
| PhotoeyeA | DI | Upstream photoeye (part detected) |
| PhotoeyeB | DI | Downstream photoeye (sort confirmation) |
| RejectFlag | DI | Quality reject signal from upstream inspection |
| Pusher | DO | Pneumatic pusher solenoid |
| RejectCount | INT | Total 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
Traffic Light PLC Program
Single-intersection traffic light controller with N-S and E-W phases plus all-red interval
Water Tank Level Control
Two-pump water tank with high/low level sensors, alternating pumps for even wear, high-high alarm trip
HVAC Zone Temperature Control
Single-zone temperature control with PID heater output, thermostat dead-band, and occupied/unoccupied scheduling
Motor Reversing with Interlock
Bidirectional motor with start/stop buttons for forward and reverse, with software interlock preventing both contactors energising simultaneously