Menu
CoddyTech

IF and THEN

Part of the Structured Text section of Coddy's PLC Programming journey. Lesson 4 of 17.

An IF runs statements only while a condition is TRUE:

IF Start THEN
    Motor := TRUE;
END_IF;

This is a set coil. When Start is not pressed, the statement inside is skipped, and Motor keeps the value it had: nothing turns it off. So a second IF does the reset:

IF NOT Stop THEN
    Motor := FALSE;
END_IF;

Every IF ends with END_IF;. The IF that comes last wins, the way a reset coil on a lower rung wins over a set coil above it.

challenge icon

Challenge

Easy
  • With an IF, set Motor when Start is pressed.
  • With a second IF below it, reset Motor when Stop is pressed or the overload trips.
  • Light RunLamp while Motor is on.

Try it yourself

// Set the motor with Start

// Reset it with Stop or the overload

// The run lamp

All lessons in Structured Text

Practice on your own: PLC playground