PLC Programming for Beginners: A Guide to Industrial Logic

Published by LogicHobbyist Automation Lab — From zero to first working program. No expensive hardware required. Learn the scan cycle, ladder logic, and how to practice for free.

⚡ Before you start: A PLC is not an Arduino. It is designed for reliability and real‑time determinism. The mindset is different: you are wiring logic, not writing sequential code.

1. What is a PLC and Why Does It Exist?

A Programmable Logic Controller (PLC) is an industrial computer hardened to survive vibration, dust, heat, and electrical noise. It replaces racks of relays, timers, and counters. Unlike a PC, a PLC runs one single program in an endless loop – this is the scan cycle.

Scan cycle diagram – Read inputs → Execute logic → Write outputs → Repeat

Figure : 1 Scan cycle diagram – Read inputs → Execute logic → Write outputs → Repeat

2. The Scan Cycle – The Heartbeat of Every PLC

Most beginners make the mistake of thinking a PLC runs like a Python script. It does not. The scan cycle is fixed and continuous:

  1. Read inputs – The PLC copies the physical status of all input terminals into memory (input image table).
  2. Execute program – It runs your ladder logic or structured text, using the input image and internal memory bits.
  3. Write outputs – The result (output image table) is sent to the physical output terminals.
  4. Housekeeping & communication – Update timers, handle PC communication, then loop back to step 1.

Typical scan times: 1‑50 milliseconds. That means your program runs 20‑1000 times per second.

⚠️ Common beginner trap: Do not create long loops or wait instructions inside your PLC code. The PLC must finish the scan quickly. Instead, use timers and state machines.

3. The 5 IEC 61131-3 Programming Languages (and which one to learn first)

The international standard defines five languages. You don’t need to learn all at once.

Language Best for Difficulty Learn first?
Ladder Logic (LD) Digital logic, start/stop, interlocks Easy (looks like electrical diagrams) Yes
Structured Text (ST) Math, loops, complex algorithms Medium (Pascal/C‑like) No – after ladder
Function Block (FBD) Process control, PID, analog scaling Easy to medium Optional
Sequential Function Chart (SFC) Step‑by‑step sequences (batch processes) Medium No – later
Instruction List (IL) Legacy systems (obsolete) Hard ❌ Avoid
💡 Recommendation: Start with Ladder Logic. It is visual, forgiving, and every electrician understands it. You can build a working motor starter in 10 minutes.

4. The Three Basic Elements of Ladder Logic

Ladder logic is drawn between two vertical “rails” (power) with horizontal “rungs” (circuits).

  • Normally Open (NO) contact – Passes power when the associated bit is ON (1).
  • Normally Closed (NC) contact – Passes power when the associated bit is OFF (0).
  • Output coil – Turns ON when power flows to it.
A single rung with Start button, Stop button, and Motor coil – simple start/stop circuit

Figure : 2 A single rung with Start button, Stop button, and Motor coil – simple start/stop circuit

5. The Most Important Pattern: Seal‑In (Latch) Circuit

A momentary pushbutton normally cannot keep a motor running. The seal‑in circuit uses the motor’s own output to “hold” itself on.

How it works:

  • When you press the Start button, the Motor coil energises.
  • An extra NO contact of that Motor (called a “seal contact”) is placed in parallel with the Start button.
  • Once the coil is ON, the seal contact closes, keeping power flowing even after you release Start.
  • The Stop button (normally closed) breaks the circuit when pressed.
Ladder diagram – Start button (NO) parallel with Motor seal contact, both in series with Stop button (NC), driving Motor coil

Figure : 3 Ladder diagram – Start button (NO) parallel with Motor seal contact, both in series with Stop button (NC), driving Motor coil

This is the foundation of almost every digital control system – conveyors, pumps, fans, and even high‑level state machines.

🔧 Interactive Simulation – Seal‑In (Latch) Circuit
The diagram below shows the exact ladder logic from Figure 3, built with real 24V components. Press the Start push‑button – the motor runs and stays on even after you release the button. Press Stop to turn it off.

🎮 How to use the simulation:
  • Click the Run / STOP button (or press Ctrl+R) to start the simulation.
  • Click on the Start switch (it will momentarily close, then return to open).
  • Observe the motor (bottom right) and the relay coil labelled (M).
  • Click Stop to break the latch circuit.
📂 No interactive view above?
If the simulation does not load, you can import the circuit manually:
  1. Download the circuit file: latch-seal-in-circuit-real-life-example.txt (right‑click → Save Link As…).
  2. Open Falstad’s online simulator .
  3. Go to File → Open File… and select the downloaded .txt file, or File → Import From Text… and paste the code below.
📋 Click to show circuit code (copy‑paste)
<cir f="1" ts="0.000005" ic="159.55918304990493" cb="80" pb="50" vr="5" mts="5e-11">
    <RelayCoil x="976 496 1136 496" f="0" lb="(M)" in="0.2" oc="0.02" cr="20" ofc="0.015" swt="0.005" tp="0" ci="0.000023999520009599808" st="0" sp="0"/>
    <RelayContact x="496 576 688 576" f="0" lb="(M)" ron="0.05" roff="1000000" ip="1"/>
    <s x="768 496 912 496" f="0"/>
    <s x="496 496 688 496" f="0" p="1" mm="true"/>
    <v x="848 256 608 256" f="16" wf="0" maxv="24"/>
    <w x="608 256 336 256" f="0"/>
    <w x="336 256 336 496" f="0"/>
    <w x="496 496 496 576" f="0"/>
    <w x="848 256 1136 256" f="0"/>
    <w x="1136 256 1136 496" f="0"/>
    <w x="912 496 976 496" f="0"/>
    <w x="688 496 768 496" f="0"/>
    <w x="688 720 976 720" f="0"/>
    <w x="688 576 688 496" f="0"/>
    <w x="336 496 496 496" f="0"/>
    <x x="702 354 742 357" f="0" si="14" te="Rungs"/>
    <x x="587 516 617 519" f="0" si="14" te="(NO)"/>
    <x x="819 523 848 526" f="0" si="14" te="(NC)"/>
    <x x="1044 454 1068 457" f="0" si="14" te="Coil"/>
    <x x="829 463 857 466" f="0" si="14" te="Stop"/>
    <x x="578 606 608 609" f="0" si="14" te="(NO)"/>
    <w x="688 352 400 352" f="0"/>
    <w x="752 352 1088 352" f="0"/>
    <w x="1088 352 1072 336" f="0"/>
    <w x="1088 352 1072 368" f="0"/>
    <w x="400 352 416 336" f="0"/>
    <w x="400 352 416 368" f="0"/>
    <x x="586 466 615 469" f="0" si="14" te="Start"/>
    <w x="336 496 336 720" f="0"/>
    <w x="1136 496 1136 720" f="0"/>
    <w x="1136 720 1072 720" f="0"/>
    <w x="336 720 496 720" f="0"/>
    <DCMotor x="976 720 1072 720" f="0" in="0.5" rs="1" k="0.15" kb="0.15" j="0.02" b="0.05" gr="1" ta="0"/>
    <x x="578 750 608 753" f="0" si="14" te="(NO)"/>
    <RelayContact x="496 720 688 720" f="0" lb="(M)" ron="0.05" roff="1000000" ip="1"/>
    </cir>

6. Free Software & Virtual PLCs – Practice Without Buying Hardware

You don’t need a physical PLC to start learning. These free tools include built‑in simulators that let you write, test, and debug real IEC 61131‑3 code on your PC. The table below shows which one fits your goals.

Platform Best for Languages Simulation Cost
OpenPLC Absolute beginners, open‑source fans, running on a Raspberry Pi LD, ST, IL, FBD, SFC Yes (built‑in) Free (open source)
CODESYS Learning professional IEC 61131‑3, SoftPLC on Windows/Linux LD, ST, IL, FBD, SFC Yes (built‑in) Free IDE, runtime free for development
TwinCAT 3 Advanced motion control, Beckhoff ecosystem, Visual Studio integration LD, ST, FBD, C++ Yes (built‑in) Free engineering, 7‑day runtime license (renewable)
⚡ Pro Tip – Licenses made simple: All three platforms are completely free for learning and prototyping. CODESYS and TwinCAT 3 use “development‑free, runtime‑paid” models – you only pay when you deploy a machine 24/7. OpenPLC is 100% open source, ideal for hobby projects.

🔹 OpenPLC – The open‑source PLC engine

OpenPLC is the first fully functional open‑source PLC software. It includes an IEC 61131‑3 editor and a runtime that turns any PC or Raspberry Pi into a real PLC.

  • Languages: Ladder Logic (LD), Structured Text (ST), Function Block Diagram (FBD), Instruction List (IL), Sequential Function Chart (SFC)
    PLC multiple languages: IL-ST-LD-FBD

    Figure : 4 PLC multiple languages: IL-ST-LD-FBD

  • Simulation: Click Start PLC Simulation in the toolbar to test your program without hardware.
    OpenPLC Simulation started for the same example described in section 5.

    Figure : 5 OpenPLC Simulation started for the same example described in section 5.

  • Hardware deployment: Upload the runtime to a Raspberry Pi, Arduino, or ESP32 for low‑cost physical testing.
    OpenPLC deployment

    Figure : 6 OpenPLC deployment

  • Web‑based configuration: Access the runtime via a browser on port 8080 (default login: openplc/openplc).
    OpenPLC web-based configuration

    Figure : 7 OpenPLC web-based configuration

🔹 CODESYS – The professional IEC 61131‑3 IDE

CODESYS is used worldwide by hundreds of automation manufacturers (WAGO, IFM, Phoenix Contact, etc.). The development system is free and includes a powerful SoftPLC simulator.

  • Languages: All five IEC 61131‑3 languages (LD, ST, IL, FBD, SFC)[reference:4].
  • Integrated features: Built‑in editor, syntax checking, variable monitoring, breakpoints, and forcing[reference:5].
  • Simulator: Compile and run your code virtually, test visualizations, and debug step by step[reference:6].
  • SoftPLC: Runs on Windows, Linux, Raspberry Pi, and many industrial PCs[reference:7].

🔹 TwinCAT 3 – The premium industrial powerhouse

Developed by Beckhoff, TwinCAT 3 integrates PLC, motion control, safety, C++ modules, analytics, and I/O configuration directly into Microsoft Visual Studio. The Solution Explorer organises your project into SYSTEM, MOTION, PLC, SAFETY, C++, ANALYTICS, and I/O – giving you one unified engineering environment for every automation task.

  • Free engineering: The development environment (TE1000) is completely free, with no annual contracts[reference:9][reference:10].
  • 7‑day runtime license: Run the real‑time kernel for 7 days, then restart – renewable indefinitely[reference:11].
  • Integrated HMI: Build professional HMIs with JavaScript or .NET extensions[reference:12].
  • Motion & CNC: Includes high‑end motion control and CNC capabilities – unmatched by other free tools.
⚠️ Which one should you start with?
Zero experience? → OpenPLC: The simplest interface, perfect for your first ladder diagram.
Want an industry‑standard CV skill? → CODESYS: Recognised by hundreds of PLC brands.
Interested in advanced motion or PC‑based control? → TwinCAT 3: A steep learning curve, but extremely powerful.

📚 More free tools for your automation toolbox

Beyond PLC programming, you can design HMIs, simulate circuits, and create PCBs – all with free software. 👉 Read our complete free industrial software list →

🔧 Step‑by‑step practice (OpenPLC):
  1. Download OpenPLC Editor from openplcproject.com .
  2. Create a new project – add one rung with a normally open (NO) contact, a normally closed (NC) contact, and an output coil.
  3. Click Start PLC Simulation.
  4. Toggle the “Start” button – the output latches. Press “Stop” – it turns off.
  5. Add a second contact in parallel with “Start” using the output itself (the seal‑in circuit from Section 5).

7. Hardware for Beginners (when you are ready to go physical)

If you want to wire real lights, buttons, and sensors, here are three low‑cost options:

Platform Approximate cost Pros Cons
Click PLC (Automation Direct) $70‑150 Free software, real industrial I/O, great manuals US‑centric, limited to Click ecosystem
Arduino Opta $120‑200 Arduino IDE + PLC languages, Ethernet, relay outputs Not as rugged as traditional PLCs
Used Siemens LOGO! or Allen‑Bradley Micro800 $50‑150 (used) Real industrial brand, large user community Software licensing can be tricky

For absolute cheapest physical setup: buy an ESP32 + a relay module and use OpenPLC firmware. You can then program it with ladder logic over Wi‑Fi.

8. Your First Practice Project (simulate it today)

Goal: A motor that starts with a momentary START pushbutton, stops with a momentary STOP pushbutton, and has a “running” indicator light.

Steps in OpenPLC:

  1. Create two digital inputs: %IX0.0 = START, %IX0.1 = STOP.
  2. Create one digital output: %QX0.0 = MOTOR.
  3. Write one rung:
    – Place START (NO) in parallel with MOTOR contact (NO).
    – Put both in series with STOP (NC).
    – Connect to MOTOR coil.
  4. Run the simulator. Press START – motor turns on. Release – motor stays on. Press STOP – motor turns off.
OpenPLC ladder with the completed seal‑in rung

Figure : 8 OpenPLC ladder with the completed seal‑in rung

9. Critical Tips for Beginners (avoid frustration)

  • Name your variables. Do not use “M0.0” – use “Motor_Running”. Your future self will thank you.
  • Document each rung with a comment (most editors have a comment field).
  • One output per rung – do not put two coils on the same rung.
  • Prefer rising/falling edges for counters and one‑shots to avoid multiple triggers in one scan.
  • Use simulation first, then hardware. 90% of your bugs can be caught in the simulator.
⚠️ Never create an endless loop inside a PLC: Instructions like WHILE...DO or FOR loops in Structured Text can block the scan. If you must loop, limit iterations.

10. Recommended Learning Path (3–4 weeks)

Week 1

Understand scan cycle & ladder basics

Watch YouTube tutorials on OpenPLC. Build a simple start/stop simulation. Understand NO, NC, and coils.

Week 2

Add timers and counters

Create a flashing light (TON timer) and a part counter (CTU). Simulate a conveyor that runs for 5 seconds then stops.

Week 3

Small state machine

Use internal markers to create a three‑step sequence (fill → mix → drain). This is a mini industrial process.

Week 4

Introduce real I/O (optional)

Buy a Click PLC or an ESP32 with OpenPLC firmware. Wire a real button and a LED. Run your simulation on real hardware.

11. Where to Go Next

Once you are comfortable with ladder logic, explore:

And remember: every expert started with a single rung. Build it, simulate it, break it, fix it. That is how you learn.


LogicHobbyist Automation Lab – independent technical reference. Next reading: How to Simulate a PLC Program for Free (OpenPLC Tutorial)

🔧

LogicHobbyist Automation Lab

Industrial PLCs · Modbus · EtherCAT · Beckhoff · Sensors · HMIs

We publish in‑depth technical comparisons, real‑world configuration guides, and performance reviews. Our content helps engineers and procurement teams select the right automation components. No consulting, no service offers – just reliable technical data.

Leave a Comment