📖 Scenario: You are programming a simple washing machine controller using PLC logic. The machine has three main steps: filling water, washing, and spinning. Each step runs for a fixed time. You will create a control sequence to manage these steps in order.
🎯 Goal: Build a PLC program that controls the washing machine sequence by defining the steps, setting the duration for each step, and then running the sequence in order.
📋 What You'll Learn
Create a dictionary called steps with keys as step names and values as durations in seconds
Create a variable called current_step to track the current step
Use a for loop to iterate over steps.items() to simulate running each step
Print the current step and its duration in the format: Running {step} for {duration} seconds
💡 Why This Matters
🌍 Real World
Washing machines use control sequences to automate the washing process, ensuring water fills, washing, and spinning happen in order.
💼 Career
Understanding control sequences and loops is essential for automation engineers programming PLCs in manufacturing and home appliance industries.
Progress0 / 4 steps
1
Define washing machine steps and durations
Create a dictionary called steps with these exact entries: 'Fill Water': 5, 'Wash': 10, 'Spin': 3
PLC Programming
Hint
Use curly braces to create a dictionary with step names as keys and durations as values.
2
Create a variable to track the current step
Create a variable called current_step and set it to an empty string ''
PLC Programming
Hint
Set current_step to an empty string to start.
3
Run the washing machine sequence
Use a for loop with variables step and duration to iterate over steps.items(). Inside the loop, set current_step to step.
PLC Programming
Hint
Use for step, duration in steps.items(): to loop through the dictionary.
4
Display the running step and duration
Inside the for loop, add a print statement to display: Running {step} for {duration} seconds using an f-string.
PLC Programming
Hint
Use print(f"Running {step} for {duration} seconds") inside the loop.
Practice
(1/5)
1. In a washing machine control sequence, what is the main purpose of using timers?
easy
A. To turn the machine on and off manually
B. To measure water temperature
C. To detect if the door is open
D. To control how long each washing step runs
Solution
Step 1: Understand washing machine steps
The washing machine runs steps like filling, washing, rinsing, and spinning, each needing a set time.
Step 2: Role of timers in automation
Timers control how long each step runs automatically without manual intervention.
Final Answer:
To control how long each washing step runs -> Option D
Quick Check:
Timers = control step duration [OK]
Hint: Timers set step durations automatically [OK]
Common Mistakes:
Confusing timers with manual switches
Thinking timers detect door status
Assuming timers measure temperature
2. Which of the following is the correct way to represent a step transition in a PLC ladder logic for washing machine control?
easy
A. IF timer_done THEN next_step = TRUE
B. FOR step IN sequence DO run()
C. while(timer < max) { step = next }
D. switch(step) { case timer: run }
Solution
Step 1: Identify PLC ladder logic style
PLC ladder logic uses conditions like IF timer_done THEN to move to next step.
Step 2: Match correct syntax
IF timer_done THEN next_step = TRUE uses a simple IF condition to set the next step flag, matching PLC logic style.
Final Answer:
IF timer_done THEN next_step = TRUE -> Option A
Quick Check:
IF timer_done THEN next_step [OK]
Hint: Look for IF condition style for PLC step control [OK]
Common Mistakes:
Using programming loops not typical in PLC ladder logic
Confusing switch-case with PLC logic
Using syntax from other programming languages
3. Given this PLC pseudocode for washing machine steps:
step = 1
if step == 1 and timer_done:
step = 2
elif step == 2 and timer_done:
step = 3
elif step == 3 and timer_done:
step = 4
What will be the value of step after three timer_done events?
medium
A. 1
B. 4
C. 3
D. 2
Solution
Step 1: Trace step changes on timer_done events
Initially step=1. After first timer_done, step=2. After second, step=3. After third, step=4.
Step 2: Confirm final step value
After three timer_done events, step reaches 4.
Final Answer:
4 -> Option B
Quick Check:
3 timer_done events advance step to 4 [OK]
Hint: Count timer_done events to track step increments [OK]
Common Mistakes:
Stopping count at 3 instead of 4
Confusing elif conditions
Ignoring step update after each event
4. Identify the error in this PLC pseudocode snippet controlling washing machine steps:
if step == 1 and timer_done:
step = 2
if step == 2 and timer_done:
step = 3
if step == 3 and timer_done:
step = 4
What problem can occur during execution?
medium
A. Multiple steps may be skipped in one cycle
B. The timer_done flag is never checked
C. Step never changes from 1
D. Syntax error due to missing else
Solution
Step 1: Analyze if statements without else
All if statements run independently, so if timer_done is true, multiple steps can update in one cycle.
Step 2: Understand effect on step variable
Step can jump from 1 to 4 in one cycle, skipping intermediate steps.
Final Answer:
Multiple steps may be skipped in one cycle -> Option A
Quick Check:
Separate ifs cause multiple step changes [OK]
Hint: Use elif to prevent multiple step changes [OK]
Common Mistakes:
Assuming only one if runs per cycle
Ignoring need for exclusive conditions
Thinking timer_done is unchecked
5. You want to add a safety check to the washing machine PLC program to prevent spinning if the door is open. Which logic addition correctly implements this?
hard
A. if door_open and step == 'spin': skip spinning step
B. if step == 'spin' or door_open: start spinning immediately
C. if door_closed and step == 'spin' and timer_done: proceed to next step
D. if door_closed or step != 'spin': stop the machine
Solution
Step 1: Understand safety requirement
Spinning should only happen if the door is closed to avoid accidents.
Step 2: Choose logic that checks door status before spinning
if door_closed and step == 'spin' and timer_done: proceed to next step checks door_closed before allowing spinning step to proceed, ensuring safety.
Final Answer:
if door_closed and step == 'spin' and timer_done: proceed to next step -> Option C
Quick Check:
Door closed required before spin step [OK]
Hint: Check door_closed before spinning step [OK]
Common Mistakes:
Using OR instead of AND allowing unsafe spin
Skipping spin step without proper condition
Stopping machine incorrectly on door status
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.