📖 Scenario: You are programming a simple indicator light system for a machine. The light should turn on when the machine is running and turn off when it is stopped.
🎯 Goal: Create a PLC program that controls an indicator light based on the machine's running status.
📋 What You'll Learn
Create a boolean variable machine_running to represent the machine status.
Create a boolean variable indicator_light to represent the light status.
Write logic to set indicator_light to True when machine_running is True.
Write logic to set indicator_light to False when machine_running is False.
Print the status of indicator_light.
💡 Why This Matters
🌍 Real World
Controlling indicator lights is common in industrial machines to show status clearly to operators.
💼 Career
PLC programming skills like this are essential for automation technicians and engineers working with factory equipment.
Progress0 / 4 steps
1
Create machine status variable
Create a boolean variable called machine_running and set it to True to represent the machine is running.
PLC Programming
Hint
Use machine_running = True to create the variable.
2
Create indicator light variable
Create a boolean variable called indicator_light and set it to False initially.
PLC Programming
Hint
Use indicator_light = False to create the variable.
3
Control indicator light based on machine status
Write logic to set indicator_light to True when machine_running is True, otherwise set it to False.
PLC Programming
Hint
Use an if statement to check machine_running and set indicator_light accordingly.
4
Display indicator light status
Write a print statement to display the status of indicator_light as ON if True and OFF if False.
PLC Programming
Hint
Use a print statement with a conditional expression to show the light status.
Practice
(1/5)
1. What is the main purpose of an indicator light in a PLC-controlled machine?
easy
A. To increase the machine's speed
B. To show the status of the machine or process clearly
C. To store data from the machine
D. To control the temperature of the machine
Solution
Step 1: Understand indicator light function
Indicator lights are used to show if a machine is running, stopped, or has a fault.
Step 2: Match purpose to options
Only To show the status of the machine or process clearly describes showing status clearly, which is the main purpose.
Final Answer:
To show the status of the machine or process clearly -> Option B
Quick Check:
Indicator lights = show status [OK]
Hint: Indicator lights always show machine status visually [OK]
Common Mistakes:
Thinking indicator lights control machine speed
Confusing indicator lights with data storage
Assuming indicator lights control temperature
2. Which of the following is the correct syntax to turn ON an indicator light named Light1 when a condition StartButton is TRUE in a PLC program?
easy
A. IF StartButton THEN Light1 = ON;
B. IF (StartButton) Light1 = ON;
C. IF StartButton Light1 = ON;
D. IF StartButton THEN Light1 ON;
Solution
Step 1: Identify correct IF syntax in PLC
Standard PLC IF syntax uses 'IF condition THEN action;' format.
Step 2: Check each option
IF StartButton THEN Light1 = ON; matches correct syntax with 'IF StartButton THEN Light1 = ON;'. Others miss THEN or equal sign.
Final Answer:
IF StartButton THEN Light1 = ON; -> Option A
Quick Check:
IF ... THEN ... = ...; syntax [OK]
Hint: Always use THEN and = in PLC IF statements [OK]
Common Mistakes:
Omitting THEN keyword
Missing equal sign for assignment
Incorrect parentheses usage
3. Given this PLC code snippet:
IF Sensor = TRUE THEN
LightGreen = ON;
ELSE
LightGreen = OFF;
END_IF;
What will be the state of LightGreen if Sensor is FALSE?
medium
A. LightGreen will be ON
B. LightGreen will blink
C. LightGreen state will not change
D. LightGreen will be OFF
Solution
Step 1: Analyze IF condition with Sensor FALSE
Since Sensor = FALSE, the ELSE branch runs.
Step 2: Determine LightGreen state in ELSE branch
ELSE sets LightGreen = OFF, so light turns off.
Final Answer:
LightGreen will be OFF -> Option D
Quick Check:
Sensor FALSE -> ELSE -> LightGreen OFF [OK]
Hint: FALSE condition triggers ELSE branch [OK]
Common Mistakes:
Assuming light stays ON when sensor is FALSE
Thinking light blinks automatically
Ignoring ELSE branch
4. Identify the error in this PLC code controlling an indicator light:
IF Start = TRUE THEN
LightRed = ON
ELSE
LightRed = OFF;
END_IF;
ELSE and END_IF are correctly used; variable name 'Start' is valid.
Final Answer:
Missing semicolon after 'LightRed = ON' -> Option C
Quick Check:
Every statement ends with ; [OK]
Hint: Check every statement ends with a semicolon [OK]
Common Mistakes:
Forgetting semicolons
Misusing ELSE keyword
Assuming END_IF is optional
5. You want to control two indicator lights: LightGreen turns ON when MachineRunning is TRUE, and LightRed turns ON when MachineFault is TRUE. Which PLC code correctly implements this logic?
hard
A. IF MachineRunning THEN LightGreen = ON; ELSE LightGreen = OFF; END_IF;\nIF MachineFault THEN LightRed = ON; ELSE LightRed = OFF; END_IF;
B. IF MachineRunning = TRUE AND MachineFault = FALSE THEN LightGreen = ON; ELSE LightGreen = OFF; END_IF;
C. IF MachineRunning THEN LightGreen = ON; IF MachineFault THEN LightRed = ON; END_IF;
D. IF MachineRunning OR MachineFault THEN LightGreen = ON; ELSE LightRed = ON; END_IF;
Solution
Step 1: Understand requirements for each light
LightGreen depends only on MachineRunning; LightRed depends only on MachineFault.
Step 2: Check each option for correct separate control
IF MachineRunning THEN LightGreen = ON; ELSE LightGreen = OFF; END_IF;\nIF MachineFault THEN LightRed = ON; ELSE LightRed = OFF; END_IF; uses two separate IF blocks, correctly controlling each light independently.
Step 3: Identify errors in other options
IF MachineRunning = TRUE AND MachineFault = FALSE THEN LightGreen = ON; ELSE LightGreen = OFF; END_IF; combines conditions incorrectly; IF MachineRunning THEN LightGreen = ON; IF MachineFault THEN LightRed = ON; END_IF; misses ELSE for LightRed OFF; IF MachineRunning OR MachineFault THEN LightGreen = ON; ELSE LightRed = ON; END_IF; mixes logic wrongly.
Final Answer:
Separate IF blocks for each light with proper ON/OFF control -> Option A
Quick Check:
Separate IFs for independent lights [OK]
Hint: Control each light with its own IF-ELSE block [OK]
Common Mistakes:
Combining conditions incorrectly
Missing ELSE to turn lights OFF
Using OR instead of separate controls
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.