With code examples. What is a PLC? Ladder Logic Explained. Hello World in 4 Languages. KSA Jobs & Future.
For Beginners & Career Starters. Made for Engineers.
12Sections
10Worked Examples
4Languages
KSACareer Roadmap
01 · Section
Why PLC?
This Booklet is designed to help you understand many important questions in industrial automation, such as:
?
Why do we use PLCs?
?
Why Ladder Logic instead of C or Python?
?
Why not just use hardware logic circuits?
?
Why is PLC control preferred in industry?
Here we try to answer one core idea: “Why?”
In engineering systems, we already use different types of programming approaches such as:
๐ง
Approach 01
General Purpose Language
e.g. Python, JavaScript — text-based programming used for software, automation, and applications.
โ
Approach 02
System-Level Language
e.g. C, C++, Assembly — low-level programming used for hardware control and embedded systems.
๐
Approach 03
Engineering Computation Language
e.g. MATLAB, Simulink — mathematical and simulation-based engineering approach.
Now we will compare these approaches and understand how they connect to hardware and industrial control systems.
02 · Section
Side-by-Side Comparison
Feature
๐ช Ladder Logic
๐ง General Purpose Language
โ System-Level Language
๐ Engineering Computation Language
Type
Industrial control language (graphical logic used in PLC systems)
Text-based programming approach used for software, automation, and applications
Low-level programming approach used for hardware control and embedded systems
Mathematical and simulation-based engineering approach
Basic idea
Uses electrical-style diagrams to control machines using ON/OFF logic
Uses step-by-step instructions to solve problems and automate tasks
Uses efficient code to directly interact with hardware and memory
Uses mathematical equations to model and simulate engineering systems
disp(‘Hello, World!’)
% Bonus โ MATLAB makes math easy:
x = 5;
y = 3;
result = x * y + sqrt(16)
% result = 19
*Here is what each symbol means
โโ[ ]โโ
Normally Open ContactThe input (sensor/button). Passes power when TRUE (ON). Like a switch.
โโ( )โโ
Output CoilThe output (motor/light/valve). Turns ON when power flows to it.
โโ[/]โโ
Normally Closed ContactPasses power when FALSE (OFF). Breaks when the contact is activated.
โโโฌโโ
Power RailThe two vertical lines. Left = power source. Right = return.
04 · Section
The Electrical Engineering View
Every programming language needs hardware to run on. But here is something most beginners don’t realize: the hardware you need is COMPLETELY different depending on which language you choose. This chapter looks at automation through the eyes of an electrical engineer.
When you write ๐ง General Purpose Language, โ System-Level Language, or ๐ Engineering Computation Language, you are NOT building a control system yet — you are just writing software. To make that software actually control a motor, you must DESIGN and BUILD supporting electronic hardware. A PLC, by contrast, is already that hardware.
โ ๐ป General Computer Languages
To control a real motor with ๐ง General Purpose Language or โ System-Level Language, running on a PC or Raspberry Pi, an electrical engineer must design and wire ALL of this:
A computer or single-board computer (PC, Raspberry Pi, Arduino)
Digital Input circuit — opto-isolators to protect the computer from 24 V field signals
Digital Output circuit — relay or transistor driver boards (the computer’s 3.3 V pin cannot switch a motor)
Signal conditioning — pull-up/pull-down resistors, debounce circuits for buttons
A separate 24 V DC power supply for field devices + 5 V for the logic
Surge protection, fuses, and EMI filtering (factories are electrically noisy)
An enclosure rated for the environment (dust, heat, vibration)
Custom PCB design or breadboard wiring — and you must debug it all yourself
โ ๐ Engineering Computation Language
Engineering Computation Language normally runs on a PC for SIMULATION only — it needs no field hardware at all because it doesn’t control real machines directly. To deploy Engineering Computation Language logic to real hardware, Simulink generates ๐ง General Purpose Language or โ System-Level Language code, which then needs the SAME hardware design as the ๐ง General Purpose Language or โ System-Level Language above. Engineering Computation Language is a design tool, not a controller.
You must DESIGN & BUILD all of this for Python / C control. 6–8 separate circuits the engineer must design, wire, protect & debug: opto-isolation for inputs, relay/transistor driver boards for outputs, dual power supplies (5 V + 24 V), surge protection, fuses & EMI filtering, signal conditioning & debounce, a rated enclosure + custom PCB / wiring.
โ ๏ธ The Hidden Cost
With ๐ง General Purpose Language, โ System-Level Language, or ๐ Engineering Computation Language, the LANGUAGE is free and easy — but the HARDWARE DESIGN is the hard part. You become an electronics designer: choosing components, calculating resistor values, designing isolation, handling noise, and debugging wiring faults. This can take weeks and requires real high electrical engineering skill.
โ ๐ช PLC (Ladder Logic) — The Engineered Solution
This is the key advantage. A PLC is a purpose-built industrial computer where all of that supporting hardware is already designed, built, tested, and certified inside one rugged unit:
Input modules — opto-isolation, signal conditioning, and 24 V handling are built in
Output modules — relay or transistor outputs that can directly switch contactors
Industrial power supply — regulated, protected, designed for factory voltages
Rugged enclosure — rated for heat, dust, vibration, and electrical noise (EMI)
Built-in diagnostics — LED indicators show input/output status instantly
Certified to industrial standards (CE, UL) — no custom electronics to debug
With a PLC — all that hardware is already built & certified inside one box. PLC = one integrated unit: input module (opto-isolation, 24 V handling, signal conditioning) → CPU + Ladder (runs the program) → output module (built-in relays, drives contactors, surge protected).
The engineer’s job is now simple — no electronics design required:
Isolation, drivers, power supply, protection & enclosure are pre-built by the manufacturer
Just wire field sensors to labelled input terminals and the motor to output terminals
Write the logic in Ladder software — change it anytime without touching a single wire
→ Weeks of hardware design become a few hours of wiring and configuration.
โ Why Engineers Choose PLCs
With a PLC, the electrical engineer does NOT design isolation circuits, driver boards, or power supplies. That engineering work is already done by the PLC manufacturer (Siemens, Allen-Bradley, etc.). The engineer simply selects the right modules, wires field devices to labelled terminals, and writes Ladder Logic. Weeks of hardware design become hours of configuration.
Hardware Comparison Table
Hardware Need
๐ง General Purpose / โ System-Level on a Computer
๐ช PLC (Ladder Logic)
Input isolation
Design opto-isolator circuits yourself
Built into input module
Output switching
Build relay/transistor driver board
Built into output module
Power supply
Source & protect 5 V + 24 V separately
Industrial supply included
Noise/EMI protection
Add filters, shielding manually
Designed-in, certified
Enclosure
Find/build a rated cabinet
Rugged industrial housing
Diagnostics
Write your own; add LEDs
Built-in status LEDs
Setup effort
Weeks of EE design + debug
Hours of wiring + config
Reliability in factory
Depends on your design skill
Certified for 20+ yr service
๐ก The Big Idea
A PLC is essentially ‘electrical engineering hardware design — pre-solved and put in a box.’ You pay more for the unit, but you save enormous amounts of design time, and you get certified industrial reliability. For a factory running 24/7, that is exactly the right trade-off.
05 · Section
Replacing Hardwired Relay Logic — A Real Example
Before PLCs, electrical engineers built control systems by physically wiring electromechanical relays. This is called ‘hardwired logic’. The logic was literally the wiring. Let’s take ONE real example and see how it is built four different ways.
๐ญ The Example: A Two-Conveyor Safety Interlock
A small packaging line has two conveyors:
Conveyor 2 (feeds boxes OUT) must NEVER run unless Conveyor 1 (feeds boxes IN) is already running — otherwise boxes pile up and jam.
An EMERGENCY STOP button must instantly stop BOTH conveyors.
Logic: Conveyor 2 runs ONLY IF (Start pressed) AND (Conveyor 1 running) AND (E-Stop NOT pressed)
Important — How a PLC Works: The Scan Cycle
A PLC doesn’t run code once — it loops through the same steps thousands of times per second. This loop is called the Scan Cycle:
Step
Name
What Happens
1
Read Inputs
PLC checks all sensors: Is the button pressed? Is the temperature above 80°C? Is the door open?
2
Execute Program
The program logic runs: ‘IF button is pressed AND door is closed THEN start motor’
3
Write Outputs
PLC sends signals: turn on motor, open valve, sound alarm
A typical scan cycle takes 5 to 50 milliseconds — that means the PLC makes decisions 20 to 200 times every second. This is why machines can react so quickly and safely.
06 · Section
Method 1 — Hardwired Relay Logic (The Old Way)
The engineer wires physical relays and contacts. The ‘program’ is the copper wiring inside the panel. To change the logic, you must physically rewire it.
Method 1 — Hardwired Relay Panel (the program IS the wiring). L1 (+24 V) → START (NO) → E-STOP (NC) → CONV1 RUNNING → CR2 control relay coil → L2 (0 V). CR2 aux (seal-in) parallels START. A second CR2 aux contact drives the Conveyor-2 motor. Every contact, coil and line above is a REAL physical part joined by REAL copper wire. To change the logic you must physically rewire the panel — and every relay is a part that can fail. There is no software, no diagnostics screen, and no remote monitoring.
โ Problems with Hardwired Logic
Changing logic = rewiring the panel (hours/days)
Each relay is a physical part that can fail
Large panels — relays take lots of space
Hard to troubleshoot — must trace wires
No data, no remote monitoring
โ What the Engineer Must Do
Draw a wiring schematic
Select & buy each relay and contact
Mount and wire every component
Test by physically pressing buttons
Re-wire entirely if requirements change
07 · Section
Method 2 — PLC Ladder Logic (The Modern Replacement)
The SAME interlock, now in a PLC. The relays become software contacts. The wiring is replaced by a Ladder program. To change the logic, you edit software — no rewiring.
Method 2 — Same Interlock in PLC Ladder Logic (the program is software). Conveyor-2 Interlock — Ladder Program. Rung 1: [START] with [CONV2_RUN] seal-in branch → [/E-STOP] → [CONV1_RUN] → (CONV2_RUN). Rung 2: [CONV2_RUN] → (CONV2_MOTOR).
Ladder Logic was designed to look exactly like relay wiring — a direct one-to-one replacement:
Relay coil CR2 → Ladder coil ( CONV2_RUN )
Seal-in wire → parallel Ladder branch
Relay aux contact → Ladder contact [ ]
Copper wiring → editable software
→ To change the logic: just edit the program and download — no rewiring, ever.
๐ The Direct Replacement
Notice: the relay CR1_aux contact becomes the Ladder contact [CONV1_RUN]. The relay CR2 coil becomes the Ladder coil (CONV2_RUN). The seal-in wire becomes a parallel contact. Ladder Logic was DESIGNED to look exactly like relay wiring — so electricians could switch from hardwired panels to PLCs without learning a totally new way of thinking.
08 · Section
The Motor Latch — “Hello World” of PLCs
The Motor Start/Stop circuit is THE fundamental building block of industrial automation. Every engineer learns this first. It solves a real problem: How do you press a button briefly to start a motor, and have it keep running after you release the button?
๐ค The Problem to Solve
You have:
A green START button (momentary — only ON while held)
A red STOP button (momentary — only ON while held)
A motor contactor (needs continuous signal to stay ON)
Challenge: Press START briefly → motor runs. Press STOP → motor stops. How do you keep the motor running after you release START?
The Logic Solution: Seal-In (Latch)
The answer is a feedback loop called a ‘seal-in’ or ‘latch’. Once the motor starts, a contact on the motor output feeds back to keep the rung TRUE — even after START is released. The STOP button breaks this loop.
[MOTOR_RUN] seal-in contact also opens → motor stops and stays stopped
The Ladder Logic Diagram
โ Motor Start/Stop with Seal-In Latch
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[START_BTN]โโโฌโโ[/STOP_BTN]โโโโโโโโโโโโโโ(MOTOR_RUN)โ โ START (NO) in series with STOP (NC) โ energizes motor coilโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ[MOTOR_RUN]โโโ โโโโโโโโโโโโโโโโโโโโโโโโโโ( )โ โ MOTOR_RUN contact in parallel with START โ this is the SEAL-IN (latch)โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
START
STOP
MOTOR_RUN (prev)
Result
OFF (0)
NOT pressed (NC=1)
OFF (0)
Motor stays OFF
ON (1) — pressed
NOT pressed (NC=1)
OFF (0)
Motor turns ON โ
OFF (0) — released
NOT pressed (NC=1)
ON (1)
Motor STAYS ON (seal-in) โ
OFF (0)
PRESSED (NC=0)
ON (1)
Motor turns OFF โ
09 · Section
The Same Logic in Every Language
Now the magic: let’s write EXACTLY the same motor latch logic in ๐ง General Purpose Language, โ System-Level Language, or ๐ Engineering Computation Language, and Ladder Logic. Notice how the logic is identical — only the syntax changes.
โ ๐ช Ladder Logic — The Visual Way
The seal-in pattern in its simplest form. Input A starts the rung; Output Y latches itself ON through its own feedback contact in parallel with A; Input B (NC) breaks the rung when pressed.
โ ๐ง General Purpose Language — The Readable Way
In General Purpose Language, we simulate the same logic with variables. This is exactly what PLC simulation software does internally:
# Motor Latch Logic # This simulates one PLC scan cycle# — Input Variables (read from sensors) —
start_btn = False# Green START button
stop_btn = False# Red STOP button (True = pressed = OPEN the circuit)
overload = False# Thermal overload relay# — Output Variables (written to actuators) —
motor_run = False# Motor contactor
run_lamp = False# Green indicator lamp# — SCAN CYCLE LOOP —while True:
# — READ INPUTS (simulated) —
start_btn = read_input(‘START’) # reads digital input
stop_btn = read_input(‘STOP’)
overload = read_input(‘OVERLOAD’)
# — RUNG 1: Motor start/stop logic —# (START pressed OR motor already running) AND STOP not pressed AND no overloadif (start_btn or motor_run) and (not stop_btn) and (not overload):
motor_run = Trueelse:
motor_run = False# — RUNG 2: Indicator lamp —
run_lamp = motor_run
# — WRITE OUTPUTS —
write_output(‘MOTOR’, motor_run)
write_output(‘LAMP’, run_lamp)
โ โ System-Level Language — The Embedded Way
System-Level Language is used in custom embedded controllers and some PLC modules. Here the same logic runs in a while(1) loop — just like the PLC scan cycle:
โ ๐ Engineering Computation Language — The Simulation Way
Engineering Computation Language is used to SIMULATE and TEST the logic before deploying to a real PLC:
% Motor Latch Logic % Simulates 100 scan cycles to test behavior% — Initialize variables —
motor_run = false;
run_lamp = false;
% — Simulate 100 scan cycles —for cycle = 1:100% Simulate button presses (test scenario)
start_btn = (cycle == 10); % Press START at cycle 10
stop_btn = (cycle == 50); % Press STOP at cycle 50
overload = false;
% RUNG 1: Start/stop latch logicif (start_btn || motor_run) && ~stop_btn && ~overload
motor_run = true;
else
motor_run = false;
end% RUNG 2: Lamp
run_lamp = motor_run;
% Log results for plotting
log_motor(cycle) = motor_run;
end% Plot the motor state over time
plot(log_motor);
title(‘Motor State vs Scan Cycle’);
xlabel(‘Scan Cycle’); ylabel(‘Motor ON/OFF’);
๐ฏ Key Insight
The motor latch logic is IDENTICAL in all four languages — the same conditions, the same logic. What changes is:
HOW you write it (graphical vs text)
WHERE you run it (PLC vs computer vs microcontroller vs simulation)
WHO reads it (electrician vs developer vs engineer)
This is why learning the LOGIC first makes learning any language easier!
10 · Section
Jobs, Future & Getting Started
Saudi Arabia’s Vision 2030 is the largest industrial transformation in the Middle East. It is creating thousands of automation jobs — and the skills in this booklet are exactly what employers need.
KSA Job Market Snapshot (2025)
Role
Salary (SAR/yr)
Key Skills
Where
Automation & Controls Engineer
120K–160K
Ladder, SCADA, HMI
KAEC, Riyadh
Maintenance Automation Engineer
200K–300K
PLC troubleshoot, drives
Jubail, Yanbu
OT/IIoT Integration Engineer
150K–220K
OPC-UA, Python, MQTT
NEOM, Riyadh
DCS & Safety Engineer
180K–280K
Yokogawa, Honeywell, SIL
Aramco, SABIC
Embedded Systems Engineer
90K–150K
C/C++, RTOS, hardware
All regions
OT Cybersecurity Specialist
200K–350K
IEC 62443, firewalls
Riyadh, Aramco
The Future: OT + IoT + Smart Systems
Where We Are Now
PLCs run isolated on factory floors
Data stays local — paper records
Maintenance is reactive (fix when broken)
Operators must be on-site
Limited analytics, manual reports
Where We Are Going
PLCs connected to cloud via IIoT
Real-time data dashboards anywhere
Predictive maintenance with AI
Remote monitoring from a phone
AI detects faults before they happen
Your Beginner Roadmap
Phase
Timeline
What To Do
START
Month 1–2
Install Codesys (free). Write your first Ladder program. Make a light turn ON with a button. Understand NO/NC contacts and output coils.
BASICS
Month 3–4
Build the motor start/stop latch. Add a timer (TON). Add a counter. Build a 3-step sequence. Install Python and run Hello World.
CONNECT
Month 5–8
Learn SCADA (try Ignition free edition). Connect Python to a PLC simulator via Modbus. Build a simple data logger. Study Profinet basics.
ADVANCE
Month 9–18
Learn Siemens TIA Portal (S7-1200). Study PID control. Get a hands-on training kit. Target your first automation job in KSA.
EXPERT
18+ months
Add OPC-UA, IIoT, and cybersecurity. Pursue ISA CCST or CAP certification. Work toward IEC 62443 specialist roles.
Free Tools to Start Today
CodesysFree professional PLC IDE supporting all IEC 61131-3 languages (codesys.com)
PLC FiddleBrowser-based Ladder Logic simulator, no install needed (plcfiddle.com)
Siemens S7-PLCSIMFree PLC simulator included with TIA Portal trial
PythonFree, download from python.org, thousands of automation libraries
MATLAB OnlineFree 30-day trial, Simulink included for control system design
RealPars on YouTubeBest free video tutorials for PLC programming beginners
ISA Student MembershipAccess to standards, webinars, and industry network
๐ Final Message
You now have the foundation: you understand what a PLC is, how Ladder Logic works, how the same logic looks in Python, C, and MATLAB, and why these languages exist together. The factory floor and the digital world are merging — and engineers who speak BOTH languages are the ones who will build Saudi Arabia’s industrial future. Start with one button. One light. One rung. Then never stop building.
11 · Section
Example and Practice Questions
Example 01
Start a Motor
Requirement: When the START button is pressed, the MOTOR turns ON.
|—-[ START ]—————-( MOTOR )—-|
Explanation
[ START ] → Input contact
( MOTOR ) → Output coil
If START becomes TRUE → MOTOR energizes
Example 02
Stop a Motor
Requirement: The MOTOR runs only when STOP is NOT pressed.
|—-[/ STOP ]—————( MOTOR )—-|
Explanation
[/ STOP ] = Normally Closed Contact
When STOP is pressed → logic opens → MOTOR OFF
Example 03
Start/Stop Conveyor System
Requirement:
START button → Conveyor ON
STOP button → Conveyor OFF
|—-[ START ]—-[/ STOP ]——–( CONVEYOR )—-|
Explanation — Both conditions must be TRUE:
START pressed
STOP not pressed
Example 04
Automatic Light Control
Requirement: Turn ON a LIGHT when motion is detected.
|—-[ MOTION_SENSOR ]————( LIGHT )—-|
Explanation — Motion detected → LIGHT turns ON. Used in:
Smart buildings
Corridors
Security systems
Example 05
Water Tank Pump Control
Requirement: Turn ON pump when water level becomes LOW.
|—-[ LOW_LEVEL ]—————( PUMP )—-|
Explanation — Low water detected → Pump starts filling tank.
Example 06
High Temperature Alarm
Requirement: Turn ON alarm if temperature becomes too high.
|—-[ HIGH_TEMP ]—————( ALARM )—-|
Explanation — High temperature → Alarm activates. Used in:
Factories
Boilers
Industrial ovens
Example 07
Safety Interlock System
Requirement: Machine runs only if:
SAFETY_DOOR closed
START pressed
|—-[ SAFETY_DOOR ]—-[ START ]—-( MACHINE )—-|
Explanation — Both conditions must be TRUE. This is an AND logic example.