Skip to main content

More Examples and Patterns

This section provides simple, reusable logic patterns for common PLC programming tasks in Structured Text (ST).

1. Basic Motor Start/Stop Logic

// Start motor if Start button is pressed and Stop is not
IF Start_Button AND NOT Stop_Button THEN
Motor_Run := 1;
ELSE
Motor_Run := 0;
END_IF;

Or, simplified:

Motor_Run := Start_Button AND NOT Stop_Button;

2. Latched Motor Control (Set/Reset Pattern)

// Latch motor ON when Start is pressed
IF Start_Button THEN
Motor_Latch := 1;
END_IF;

// Unlatch motor when Stop is pressed
IF Stop_Button THEN
Motor_Latch := 0;
END_IF;

// Run motor based on latch state
Motor_Run := Motor_Latch;

3. Analog Threshold Control

// Turn on fan when temperature exceeds 60.5°C
IF Temperature > 60.5 THEN
Fan := 1;
ELSE
Fan := 0;
END_IF;

4. Mode Selector with CASE

CASE Mode OF
1: Operation := 'Auto';
2: Operation := 'Manual';
3: Operation := 'Maintenance';
ELSE
Operation := 'Unknown';
END_CASE;