Bird
Raised Fist0
PLC Programmingscripting~10 mins

State machine in ladder logic in PLC Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - State machine in ladder logic
Start
↓
State 0: Idle
↓
Check Input
| Yes↓
Transition to State 1
↓
State 1: Running
↓
Check Input
| Yes↓
Transition to State 2
↓
State 2: Done
↓
Reset or Loop Back
↩Back to State 0
The ladder logic state machine moves through states based on input conditions, transitioning from Idle to Running to Done, then resets.
Execution Sample
PLC Programming
(* Ladder logic states with bits *)
// State bits: S0, S1, S2
// Input: StartBtn
// Output: MotorOn

// If in S0 and StartBtn pressed, go to S1
// If in S1 and StartBtn pressed, go to S2
// If in S2 and StartBtn not pressed, reset to S0
This ladder logic controls a simple 3-state machine using bits and input to move through states.
Execution Table
StepCurrent State (S0,S1,S2)Input (StartBtn)ConditionActionNext StateOutput (MotorOn)
1S0=1, S1=0, S2=00StartBtn=0?No transitionS0=1, S1=0, S2=00
2S0=1, S1=0, S2=01StartBtn=1?Transition S0->S1S0=0, S1=1, S2=01
3S0=0, S1=1, S2=00StartBtn=0?No transitionS0=0, S1=1, S2=01
4S0=0, S1=1, S2=01StartBtn=1?Transition S1->S2S0=0, S1=0, S2=10
5S0=0, S1=0, S2=10StartBtn=0?Reset to S0S0=1, S1=0, S2=00
6S0=1, S1=0, S2=00StartBtn=0?No transitionS0=1, S1=0, S2=00
💡 Loop continues; state machine cycles through states based on StartBtn input.
Variable Tracker
VariableStartAfter Step 2After Step 4After Step 5Final
S010011
S101000
S200100
StartBtn01100
MotorOn01000
Key Moments - 3 Insights
Why does the motor turn on only in State 1?
Because in the execution_table rows 2 and 3, MotorOn is 1 only when S1=1, showing output is linked to State 1.
What happens if StartBtn is not pressed in State 0?
As shown in row 1, no transition occurs and the state remains S0 with MotorOn off.
How does the state machine reset after reaching State 2?
Row 5 shows that in State 2, the machine resets to State 0 automatically when StartBtn is 0.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at Step 2, what is the next state after pressing StartBtn?
AS0=0, S1=1, S2=0
BS0=1, S1=0, S2=0
CS0=0, S1=0, S2=1
DNo change
💡 Hint
Check the 'Next State' column in row 2 of execution_table.
At which step does the motor turn off after being on?
AStep 5
BStep 3
CStep 4
DStep 6
💡 Hint
Look at the 'Output (MotorOn)' column in execution_table rows 3 and 4.
If StartBtn is never pressed, what state does the machine stay in?
AState 1
BState 0
CState 2
DCycles through all states
💡 Hint
See rows 1 and 6 where StartBtn=0 and state remains S0.
Concept Snapshot
State machine in ladder logic uses bits to represent states.
Transitions happen when input conditions are met.
Only one state bit is active at a time.
Outputs depend on current state.
Reset logic returns to initial state.
Simple and clear for controlling sequences.
Full Transcript
This visual execution shows a simple state machine implemented in ladder logic. The machine has three states represented by bits S0, S1, and S2. It starts in State 0 (Idle) with S0=1. When the Start button is pressed (StartBtn=1), it transitions to State 1 (Running) by setting S1=1 and clearing S0. The motor output turns on in State 1. Pressing StartBtn again moves the machine to State 2 (Done) with S2=1 and motor off. In State 2, the machine resets back to State 0 automatically when StartBtn is released. The execution table traces each step, showing state bits, input, conditions, actions, next state, and output. Variable tracker shows how bits and output change over time. Key moments clarify common confusions about output activation, no input behavior, and reset logic. The quiz tests understanding of state transitions and outputs. This approach helps beginners see exactly how ladder logic controls a state machine step-by-step.

Practice

(1/5)
1. What is the main purpose of a state machine in ladder logic?
easy
A. To control a process by remembering and switching between states
B. To perform mathematical calculations
C. To store large amounts of data
D. To display information on an HMI screen

Solution

  1. Step 1: Understand state machine concept

    A state machine controls a process by remembering the current step or state and moving to the next based on conditions.
  2. Step 2: Compare options to concept

    Only To control a process by remembering and switching between states describes controlling process flow by switching states, which matches the state machine purpose.
  3. Final Answer:

    To control a process by remembering and switching between states -> Option A
  4. Quick Check:

    State machine controls steps = D [OK]
Hint: State machines remember and switch states to control flow [OK]
Common Mistakes:
  • Confusing state machine with data storage
  • Thinking it only does math
  • Assuming it controls display only
2. Which ladder logic element is typically used to represent a state in a state machine?
easy
A. Timer
B. Bit or coil
C. Counter
D. Analog input

Solution

  1. Step 1: Identify state representation in ladder logic

    States are usually represented by bits or coils that can be ON or OFF to show current state.
  2. Step 2: Eliminate other options

    Timers and counters are for timing/counting, analog inputs read values, so only bits/coils represent states.
  3. Final Answer:

    Bit or coil -> Option B
  4. Quick Check:

    States use bits/coils = C [OK]
Hint: States are bits or coils ON/OFF in ladder logic [OK]
Common Mistakes:
  • Choosing timers or counters as states
  • Confusing analog inputs with states
  • Not knowing bits represent ON/OFF
3. Given this ladder logic snippet for a state machine:
--[ State1 ]--+--[ Condition ]--( State2 )
              |
              +--( Reset State1 )

What happens when Condition is TRUE?
medium
A. State2 turns OFF and State1 turns ON
B. State1 and State2 both turn ON
C. State1 stays ON and State2 stays OFF
D. State1 turns OFF and State2 turns ON

Solution

  1. Step 1: Analyze ladder logic behavior on Condition TRUE

    When Condition is TRUE, the coil for State2 energizes and the Reset coil for State1 de-energizes State1.
  2. Step 2: Understand state transition

    This means State1 turns OFF and State2 turns ON, moving the machine to the next state.
  3. Final Answer:

    State1 turns OFF and State2 turns ON -> Option D
  4. Quick Check:

    Condition TRUE switches states = A [OK]
Hint: Condition TRUE switches OFF current and ON next state [OK]
Common Mistakes:
  • Thinking both states turn ON simultaneously
  • Assuming no change happens
  • Confusing which state resets
4. You wrote this ladder logic for a state machine:
--[ State1 ]--+--[ Condition ]--( State2 )
              +--( State1 )

Why does the state machine never leave State1?
medium
A. Because State1 coil is never reset, so it stays ON
B. Because Condition is never TRUE
C. Because State2 coil is missing
D. Because the rung has a syntax error

Solution

  1. Step 1: Check how State1 coil is controlled

    State1 coil is energized again on the same rung without a reset coil, so it stays ON continuously.
  2. Step 2: Understand why state never changes

    Without turning OFF State1, the machine cannot move to State2 even if Condition is TRUE.
  3. Final Answer:

    Because State1 coil is never reset, so it stays ON -> Option A
  4. Quick Check:

    No reset keeps state ON = B [OK]
Hint: Always reset current state coil to move states [OK]
Common Mistakes:
  • Ignoring need to reset current state
  • Assuming Condition is always FALSE
  • Thinking missing coil causes lock
5. You want to design a 3-step state machine in ladder logic: State1 -> State2 -> State3 -> State1. Which approach correctly implements the transitions?
hard
A. Use timers to switch states automatically without conditions
B. Use one bit for all states and toggle it on each condition
C. Use bits for each state; each transition resets current state bit and sets next state bit based on conditions
D. Use counters to count states and reset after 3

Solution

  1. Step 1: Understand state machine design

    A proper state machine uses separate bits for each state and transitions that turn OFF the current state bit and ON the next state bit.
  2. Step 2: Evaluate options for correct implementation

    Use bits for each state; each transition resets current state bit and sets next state bit based on conditions matches this approach; the other options do not correctly represent state transitions in ladder logic.
  3. Final Answer:

    Use bits for each state; each transition resets current state bit and sets next state bit based on conditions -> Option C
  4. Quick Check:

    Separate bits with reset/set transitions = A [OK]
Hint: Reset current and set next state bits for transitions [OK]
Common Mistakes:
  • Using one bit for all states
  • Relying only on timers or counters
  • Not resetting current state bit
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard