Engine start stop program using STL language with Siemens S7 1200

24 January 2023 841 Reading time: 53 second

For a simple code example to control the motor with the start-stop button using the Siemens S7-1200, the Structured Text (STL) language is as follows:
 


VAR
    start_button: BOOL;
    stop_button: BOOL;
    motor_relay: BOOL;
BEGIN
    //Read the state of the start button
    start_button := INPUT.X0;
    //Read the state of the stop button
    stop_button := INPUT.X1;
    //Check if the start button is pressed
    IF start_button THEN
        //Turn on the motor
        motor_relay := TRUE;
    ELSE
        //Check if the stop button is pressed
        IF stop_button THEN
            //Turn off the motor
            motor_relay := FALSE;
        END_IF
    END_IF
    //Write the state of the motor relay to the output
    OUTPUT.X2 := motor_relay;
END

This program reads the state of the start button (input X0) and the stop button (input X1) and depending on the state of these buttons, it controls the state of the motor relay (output X2). When the start button is pressed, the motor relay is turned on and when the stop button is pressed, the motor relay is turned off.

Similar articles