Type to search, in English or Thai

  1. Home
  2. English lessons
  3. PLC Automation

// Chapter 22 · PLC Automation · electrician → student → engineer

PLC Automation

A PLC (Programmable Logic Controller) replaces panels of hundreds of relays with a program you can edit. This course runs from how a PLC scans, through wiring PNP/NPN sensors correctly, writing ladder logic, timers and counters, to motor control, star–delta, sequential systems, analog and PID, and commanding VFDs. Every example can be tried straight away in the simulator on the page. There are formulas with citable IDs and worked examples.

By Ajarn ModUpdated
In 30 seconds
  • A PLC repeats three things every few milliseconds: read inputs → run the program → write outputs
  • Ladder: series = AND · parallel = OR · NC = NOT · a self-holding rung works like a contactor
  • A PNP sensor pairs with a sinking input (COM to 0 V) · NPN pairs with sourcing
  • STOP and emergency-stop buttons are wired NC, and critical interlocks must stay in hardware
  • IEC 61131-3 timers TON, TOF, TP and counters CTU, CTD work on every brand

Learning path by level

Level 1 · electrician · vocational

Wire it and write ladder logic

What a PLC is, I/O wiring, ladder, self-holding, timers, counters

Fundamentals → I/O wiring → Ladder → Timers

Level 2 · technician · programmer

Real factory work

Motor control, sequential control, analog, commanding VFDs, commissioning

Motor control → Sequential control → Analog · PID

Level 3 · engineering student · engineer

System-level design

Boolean algebra, state machines, SFC, ST, response time, discrete PID, functional safety

IEC 61131-3 → SFC → Safety

Try it: a star–delta PLC in your browser

Press START (I0.1) and watch the green power flow through the ladder. Timer T1 counts 6 seconds, K2 (star) drops out, there is an 80 ms dead time, then K3 (delta) pulls in. Choose another example from the menu, or open “Edit the program” to write your own. The full simulator with worksheets is at Ladder simulator.

Key equations used throughout

H1 Worst-case response

tresp,max≈tin+2 tscan+toutt_{resp,max} \approx t_{in} + 2\,t_{scan} + t_{out}

H2 Latch rung

Q=STOP‾⋅(START+Q)    ≡    STOP wired NC → NO contact in the programQ = \overline{\text{STOP}}\cdot(\text{START} + Q) \;\;\equiv\;\; \text{STOP wired NC → NO contact in the program}

H3 On-delay timer

QTON=IN∧(ET≥PT)ET≤PTQ_{TON} = IN \wedge (ET \ge PT) \qquad ET \le PT

H4 Analog scaling

y=ymin+(x−xmin) ymax−yminxmax−xminy = y_{min} + (x - x_{min})\,\frac{y_{max} - y_{min}}{x_{max} - x_{min}}

PLCs found in the region and their address notation

Brand (example models)InputOutputMemorySoftware
IEC 61131-3 (standard)%IX0.0%QX0.0%MX0.0CODESYS and others
Siemens (S7-1200/1500)I0.0Q0.0M0.0TIA Portal
Mitsubishi (FX5U, iQ-R)X0Y0M0GX Works3
Omron (CP1, NX/NJ)0.00100.00W0.00CX-Programmer / Sysmac Studio
Delta (DVP, AS)X0Y0M0ISPSoft
Rockwell (Micro800, CompactLogix)_IO_EM_DI_00 / tag_IO_EM_DO_00 / tagtagCCW / Studio 5000

This course uses Siemens-style I0.0 / Q0.0 / M0.0 addresses because they are easy to read and translate directly to other brands.

Every page in this course

Search every formula in one place

Prefixes: H overview · F fundamentals · W I/O wiring · B ladder · T timers/counters · L languages · M motors · S sequential · P analog/PID · K commissioning/safety

  1. H1Worst-case response
    tresp,max≈tin+2 tscan+toutt_{resp,max} \approx t_{in} + 2\,t_{scan} + t_{out}
  2. H2Latch rung
    Q=STOP‾⋅(START+Q)    ≡    STOP wired NC → NO contact in the programQ = \overline{\text{STOP}}\cdot(\text{START} + Q) \;\;\equiv\;\; \text{STOP wired NC → NO contact in the program}
  3. H3On-delay timer
    QTON=IN∧(ET≥PT)ET≤PTQ_{TON} = IN \wedge (ET \ge PT) \qquad ET \le PT
  4. H4Analog scaling
    y=ymin+(x−xmin) ymax−yminxmax−xminy = y_{min} + (x - x_{min})\,\frac{y_{max} - y_{min}}{x_{max} - x_{min}}
  5. F1Scan time
    tscan=tread I+tprogram+twrite Q+tcomm/diagt_{scan} = t_{read\,I} + t_{program} + t_{write\,Q} + t_{comm/diag}
  6. F2Program execution estimate
    tprogram≈Nbit tbit+Nword tword+Nreal trealt_{program} \approx N_{bit}\,t_{bit} + N_{word}\,t_{word} + N_{real}\,t_{real}
  7. F3System response time
    tin+tscan+tout  ≤  tresp  ≤  tin+2 tscan+toutt_{in} + t_{scan} + t_{out} \;\le\; t_{resp} \;\le\; t_{in} + 2\,t_{scan} + t_{out}
  8. F4Shortest pulse surely seen
    tpulse>tscan+tint_{pulse} > t_{scan} + t_{in}
  9. F5I/O count with spare
    NI/O=⌈1.2 Nrequired⌉(15–25 % spare)N_{I/O} = \left\lceil 1.2\,N_{required} \right\rceil \quad (\text{15–25 \% spare})
  10. W1Input current
    Iin≈V−VLEDRin≈24−1.24.7 kΩ≈5 mAI_{in} \approx \frac{V - V_{LED}}{R_{in}} \approx \frac{24 - 1.2}{4.7\ \text{k}\Omega} \approx 5\ \text{mA}
  11. W2Two-wire sensor compatibility
    Ileak,sensor≤IOFF,maxVdrop,sensor≤24−VON,minI_{leak,sensor} \le I_{OFF,max} \qquad V_{drop,sensor} \le 24 - V_{ON,min}
  12. W3Inductive kick
    vL=Ldidtno suppressor: several hundred voltswith a diode: Vclamp≈Vsupply+0.7 Vv_L = L\frac{di}{dt} \qquad \text{no suppressor: several hundred volts} \qquad \text{with a diode: } V_{clamp} \approx V_{supply} + 0.7\ \text{V}
  13. W424 VDC supply sizing
    IPSU≥1.25(ICPU+∑Iin+∑Isensor+∑Iout (simultaneous))I_{PSU} \ge 1.25\left(I_{CPU} + \sum I_{in} + \sum I_{sensor} + \sum I_{out\,(\text{simultaneous})}\right)
  14. B1AND (series)
    Y=A⋅BST: Y:=A AND B;Y = A \cdot B \qquad \text{ST: } Y := A \text{ AND } B;
  15. B2OR (parallel)
    Y=A+BST: Y:=A OR B;Y = A + B \qquad \text{ST: } Y := A \text{ OR } B;
  16. B3NOT (NC contact)
    Y=A‾ST: Y:=NOT A;Y = \overline{A} \qquad \text{ST: } Y := \text{NOT } A;
  17. B4De Morgan
    A⋅B‾=A‾+B‾A+B‾=A‾⋅B‾\overline{A\cdot B} = \overline{A} + \overline{B} \qquad \overline{A + B} = \overline{A}\cdot\overline{B}
  18. B5XOR (exclusive OR, two-way switch)
    Y=AB‾+A‾BY = A\overline{B} + \overline{A}B
  19. B6Motor latch in a PLC
    Q0.0=I0.0(STOP, NC)⋅(I0.1(START)+Q0.0)⋅I0.2(OL 95-96, NC)Q0.0 = I0.0_{(\text{STOP, NC})}\cdot(I0.1_{(\text{START})} + Q0.0)\cdot I0.2_{(\text{OL 95-96, NC})}
  20. B7Set/Reset with reset priority (R rung below)
    Qk+1=(S+Qk)⋅R‾Q_{k+1} = (S + Q_k)\cdot\overline{R}
  21. B8Rising edge (one-shot)
    P(A)k=Ak⋅Ak−1‾N(A)k=Ak‾⋅Ak−1P(A)_k = A_k\cdot\overline{A_{k-1}} \qquad N(A)_k = \overline{A_k}\cdot A_{k-1}
  22. T1TON — on-delay
    ET={min⁡(ET+Δt, PT)IN=10IN=0Q=IN∧(ET≥PT)ET = \begin{cases} \min(ET + \Delta t,\ PT) & IN = 1 \\ 0 & IN = 0 \end{cases} \qquad Q = IN \wedge (ET \ge PT)
  23. T2TOF — off-delay
    Q=IN∨(ET<PT)where ET starts timing when IN:1→0, ET=0 while IN=1Q = IN \vee (ET < PT) \quad \text{where } ET \text{ starts timing when } IN: 1 \to 0,\ ET = 0 \text{ while } IN = 1
  24. T3TP — fixed-length pulse
    Q=1 during [t0, t0+PT) after a rising edge of IN at t0 (not retriggered during the pulse)Q = 1 \ \text{during } [t_0,\ t_0 + PT) \text{ after a rising edge of } IN \text{ at } t_0 \ (\text{not retriggered during the pulse})
  25. T4Software timer accuracy
    PT≤tactual≤PT+tscan+tbasePT \le t_{actual} \le PT + t_{scan} + t_{base}
  26. T5Flasher from two timers
    T1=TON(EN∧T2‾, ton)T2=TON(T1, toff)Q=EN∧T1‾(Tperiod=ton+toff)T1 = \text{TON}(EN \wedge \overline{T2},\ t_{on}) \quad T2 = \text{TON}(T1,\ t_{off}) \quad Q = EN \wedge \overline{T1} \quad (T_{period} = t_{on} + t_{off})
  27. T6CTU — up counter
    CVk+1={0R=1CVk+1P(CU)CVkotherwiseQ=(CV≥PV)CV_{k+1} = \begin{cases} 0 & R = 1 \\ CV_k + 1 & P(CU) \\ CV_k & \text{otherwise} \end{cases} \qquad Q = (CV \ge PV)
  28. T7CTD — down counter
    CV=PV on LDCVk+1=CVk−1 at P(CD)Q=(CV≤0)CV = PV \text{ on LD} \qquad CV_{k+1} = CV_k - 1 \text{ at } P(CD) \qquad Q = (CV \le 0)
  29. T8Software counter limit
    fmax≈12 (tscan+tin)f_{max} \approx \frac{1}{2\,(t_{scan} + t_{in})}
  30. L1Signed integer range
    −2n−1≤x≤2n−1−1n=16⇒−32768…32767-2^{n-1} \le x \le 2^{n-1} - 1 \qquad n = 16 \Rightarrow -32768 \ldots 32767
  31. L2Integer pitfalls in scaling
    27648×1027648  (INT overflows at the multiplication)1382427648×10=0  (division truncates before the multiplication)\frac{27648 \times 10}{27648} \;\text{(INT overflows at the multiplication)} \qquad \frac{13824}{27648}\times 10 = 0 \;\text{(division truncates before the multiplication)}
  32. M1Run command
    Cmd=I0.0⋅I0.2⋅Fault‾⋅(I0.1+Cmd)\text{Cmd} = I0.0\cdot I0.2\cdot\overline{\text{Fault}}\cdot(I0.1 + \text{Cmd})
  33. M2Feedback discrepancy
    Fault←TON(Cmd⊕FB, tfb)tfb≈0.5–2 s\text{Fault} \leftarrow \text{TON}(\text{Cmd} \oplus \text{FB},\ t_{fb}) \qquad t_{fb} \approx 0.5\text{–}2\ \text{s}
  34. M3Software interlock
    QF=S0‾ OL‾ (SF+QF) SR‾ QR‾ FBR‾QR=S0‾ OL‾ (SR+QR) SF‾ QF‾ FBF‾Q_F = \overline{S0}\,\overline{OL}\,(S_F + Q_F)\,\overline{S_R}\,\overline{Q_R}\,\overline{FB_R} \qquad Q_R = \overline{S0}\,\overline{OL}\,(S_R + Q_R)\,\overline{S_F}\,\overline{Q_F}\,\overline{FB_F}
  35. M4Star–delta sequence
    KY=Run TY‾ KΔ‾K1=Run (KY+K1)KΔ=Run TON(TY, tdead) KY‾ FBY‾K_Y = \text{Run}\,\overline{T_Y}\,\overline{K_\Delta} \quad K_1 = \text{Run}\,(K_Y + K_1) \quad K_\Delta = \text{Run}\,\text{TON}(T_Y,\ t_{dead})\,\overline{K_Y}\,\overline{FB_Y}
  36. S1Transition rule
    Xn+1←1, Xn←0whenXn∧tn→n+1X_{n+1} \leftarrow 1,\ X_n \leftarrow 0 \quad \text{when}\quad X_n \wedge t_{n\to n+1}
  37. S2One active step
    ∑iXi=1\sum_i X_i = 1
  38. S3Outputs from steps
    Qj=⋁i∈AjXi⋅(enable condition)Q_j = \bigvee_{i \in A_j} X_i \cdot \text{(enable condition)}
  39. P1Linear scaling
    y=ymin+(x−xmin) ymax−yminxmax−xminy = y_{min} + (x - x_{min})\,\frac{y_{max} - y_{min}}{x_{max} - x_{min}}
  40. P2Resolution per raw count
    Δy=ymax−yminxmax−xmine.g. 10 bar27648=0.36 mbar\Delta y = \frac{y_{max} - y_{min}}{x_{max} - x_{min}} \qquad \text{e.g. } \frac{10\ \text{bar}}{27648} = 0.36\ \text{mbar}
  41. P3Signal validity (NAMUR NE 43)
    3.8≤I≤20.5 mA: valid measurementI≤3.6 or I≥21 mA → fault3.8 \le I \le 20.5\ \text{mA: valid measurement} \qquad I \le 3.6 \text{ or } I \ge 21\ \text{mA → fault}
  42. P4PID (standard form)
    u(t)=Kp(e+1Ti∫0te dτ+Td dedt)e=SP−PVu(t) = K_p\left(e + \frac{1}{T_i}\int_0^t e\,d\tau + T_d\,\frac{de}{dt}\right) \qquad e = SP - PV
  43. tst_s) analog · pid · vfd u_k = k_p left (e_k + frac {t_s}{t_i} sum _{j=0}^{k} e_j - frac {t_d}{t_s}(pv_k - pv_{k-1}) right ) ">P5Discrete PID (sample time TsT_s)
    uk=Kp(ek+TsTi∑j=0kej−TdTs(PVk−PVk−1))u_k = K_p\left(e_k + \frac{T_s}{T_i}\sum_{j=0}^{k} e_j - \frac{T_d}{T_s}(PV_k - PV_{k-1})\right)
  44. P6Frequency setpoint over Modbus
    Reg=f0.01 Hz(35.5 Hz→3550)orReg=ffmax×Scale100%\text{Reg} = \frac{f}{0.01\ \text{Hz}} \quad (35.5\ \text{Hz} \to 3550) \qquad \text{or} \quad \text{Reg} = \frac{f}{f_{max}}\times \text{Scale}_{100\%}
  45. K1Stop categories
    Cat 0: remove power immediatelyCat 1: controlled stop, then remove powerCat 2: controlled stop, power kept on\text{Cat 0: remove power immediately} \qquad \text{Cat 1: controlled stop, then remove power} \qquad \text{Cat 2: controlled stop, power kept on}
  46. K2PL / SIL by dangerous failure rate
    PL d≈SIL 2:10−7≤PFHD<10−6PL e≈SIL 3:10−8≤PFHD<10−7\text{PL d} \approx \text{SIL 2}: 10^{-7} \le PFH_D < 10^{-6} \qquad \text{PL e} \approx \text{SIL 3}: 10^{-8} \le PFH_D < 10^{-7}
  47. K3Minimum safety distance (ISO 13855)
    S=K T+CK=2000 mm/s (if S≤500 mm), 1600 mm/s (otherwise)C=8(d−14) mm, d≤40 mmS = K\,T + C \qquad K = 2000\ \text{mm/s (if } S \le 500\ \text{mm)},\ 1600\ \text{mm/s (otherwise)} \qquad C = 8(d - 14)\ \text{mm},\ d \le 40\ \text{mm}

Standards and references

  • IEC 61131-1 (overview) · IEC 61131-2 (hardware, 24 VDC input types) · IEC 61131-3 (programming languages)
  • IEC 60204-1 (electrical equipment of machines, stop categories) · ISO 13849-1 / IEC 62061 (functional safety of machinery)
  • IEC 60848 (GRAFCET) · Modbus Application Protocol Specification (Modbus Organization)
  • F. D. Petruzella, Programmable Logic Controllers · W. Bolton, Programmable Logic Controllers · PLC manufacturers' manuals

Frequently asked questions

What should I know before learning PLCs?

You should understand contactor control circuits (self-holding, interlocks, timers), because ladder logic is designed to read like a relay circuit, and basic 24 VDC and 230 VAC electrics so you can wire I/O correctly. All of this is covered in the motor-control course on this site.

Which PLC brand should I start with?

The principles are the same for every brand because they follow IEC 61131. Choose a brand used in the factories or schools near you, and one with free software and a simulator. In this region Mitsubishi, Omron, Siemens, Delta, Schneider, Rockwell and Keyence are common.

How is a PLC different from an Arduino or a microcontroller?

A PLC is designed for the factory environment: noise-immune, isolated 24 VDC I/O, a predictable scan, self-diagnostics, standardised languages, modules that can be serviced and replaced in use, and certification to industrial standards. A microcontroller is more flexible and cheaper, but the user has to build all that robustness themselves.

Ajarn Mod · Teerawut Savangboon
Lecturer in Electrical Engineering, Dhonburi Rajabhat University, Samut Prakan · Profile