PLC Programming and Ladder Logic: A Practical Guide for Student Automation Projects

A practical PLC ladder-logic guide for Electrical final-year students: how the scan cycle works, contacts, coils and the seal-in circuit, timers (TON/TOF/TP) and counters with a worked bottle-filling example, sinking-vs-sourcing 24 V I/O wiring, a student-budget PLC comparison with indicative INR bands, free simulators, hardwired E-stop safety, a demo-day commissioning checklist, and a fault table.

Written by Projectech19 min readPublished
For B.E./B.Tech Electrical final-year students doing PLC-based automation projects Topics: PLC, Ladder Logic, Siemens TIA Portal, Allen-Bradley, SCADA
Illustration of a PLC panel with ladder logic rungs, timers, sensors and a conveyor bottle-filling setup, generated for this guide.
Illustration generated for this guide.
In this guide

If you are building a PLC-based automation setup for your final-year submission, you will spend most of your time in two places: in front of the panel wiring sensors and contactors, and in front of the ladder editor wondering why a rung that looks right does not behave right. This guide covers both. It assumes you have access to a small PLC in your college lab — a Siemens S7-1200, an Allen-Bradley MicroLogix, or a Delta DVP — and walks through the scan cycle, ladder fundamentals, timers and counters with a worked bottle-filling example, sinking-versus-sourcing wiring, budget hardware choices, hardwired safety, and a commissioning checklist.

The ideas here transfer across brands. A seal-in circuit is a seal-in circuit whether the addresses are I0.0/Q0.0 or X0/Y0. What changes is the software and the addressing syntax, both covered below.

What a PLC actually does: the scan cycle

A PLC is not a microcontroller running your code line by line whenever it feels like it. It is a ruggedized controller that repeats one fixed loop forever:

  1. Input scan — the PLC reads every physical input and copies the states into its input image table. Your program never reads the terminals directly; it reads this snapshot.
  2. Program scan — the PLC evaluates your ladder rungs top to bottom, left to right, using the input snapshot, and writes results to an output image table.
  3. Output scan — the PLC copies the output image table to the physical output terminals in one shot.
  4. Housekeeping — communications, diagnostics, and then back to step 1.

A full loop is the scan time, typically 1–20 ms for a small student program. Three consequences matter for your project:

  • Outputs do not change mid-scan. If two rungs write to the same coil, the last one evaluated wins, and the physical output only changes at the next output scan. Duplicate coil addresses across rungs are the classic cause of "the output flickers" bugs.
  • A very short input pulse can be missed. A photoeye pulse shorter than one scan time may never appear in the input snapshot. If your conveyor sensor pulses are brief, use a hardware interrupt input or a high-speed counter channel — most small PLCs dedicate specific terminals for this.
  • Rung order is execution order. Put safety and interlock rungs first, sequencing logic after. Anything that must react fastest goes at the top.

Quotable rule of thumb: the PLC sees the world as a photograph taken once per scan. Your program edits the photograph, and the outputs are repainted from it once per scan. Every ladder bug you will ever debug is a misunderstanding of that loop.

Ladder logic in 10 minutes: contacts, coils, and the seal-in circuit

Ladder logic draws a program as two vertical power rails with horizontal rungs between them. Each rung is one logical condition. The symbols:

  • Normally open (NO) contact —[ ]—: passes power when its signal is TRUE (1).
  • Normally closed (NC) contact —[/]—: passes power when its signal is FALSE (0).
  • Output coil —( )—: energizes when its rung is TRUE.

Contacts are references to inputs (I0.0), outputs (Q0.0), or internal memory bits (M0.0). A contact does not care what the physical field device is — a NO contact on I0.0 is TRUE when input terminal I0.0 has voltage. (Wiring a physically-NC pushbutton to a NO contact is a separate decision; keep the distinction clear: the device's contact type and the ladder contact type are independent.)

The seal-in (latching) circuit

The seal-in circuit is the single most reused rung pattern in student automation projects — it makes a motor keep running after you release the start button, and stop when you press stop. Memorize it:

Rung 1 — Motor start/stop with seal-in
   I0.0            I0.1            Q0.0
   START (NO)      STOP (NC)       MOTOR RUN
  --[ ]-----------[/]--+----------( )--
                       |
   Q0.0                |
   SEAL-IN (NO)        |
  --[ ]----------------+

How it works: press START (I0.0 goes TRUE) while STOP (I0.1, wired NC, so its contact reads TRUE when not pressed) — the rung is TRUE, coil Q0.0 energizes. The parallel NO contact of Q0.0 now also conducts, so when you release START, Q0.0 keeps itself energized through its own contact — it has "sealed in." Press STOP and the NC contact opens, the rung goes FALSE, Q0.0 drops, and the seal-in contact opens too. The circuit resets.

Notice the STOP is an NC contact in series. This is deliberate: if the stop button's wire breaks, the circuit reads the stop as pressed and the motor cannot start. Fail-safe by default — a broken wire stops the machine instead of letting it run. This is the same philosophy behind hardwired E-stops, covered later.

Timers and counters, with a worked bottle-filling example

Timers and counters are function blocks, not contacts. The three timer types:

Timer Behavior Typical student use
TON (on-delay) Output turns ON only after the input has been TRUE continuously for the preset time Dwell/fill times, start delays
TOF (off-delay) Output stays ON for the preset time after the input goes FALSE Cooling fan run-on, lamp off-delay
TP (pulse) Output turns ON for exactly the preset time on a rising edge Fixed-duration pulses, debounced triggers

Counters: CTU (count up — increments on each rising edge, output at preset) and CTD (count down). A CTU with a preset of 10 and a reset input is how you count ten bottles and then signal a full tray.

Worked example: automatic bottle filling

Take a PLC-based automatic bottle filling plant — conveyor, photoeye, fill valve, pneumatic pusher. The sequence:

  1. Conveyor runs until a photoeye detects a bottle in the fill position.
  2. Conveyor stops; the fill valve opens for 5 seconds (TON).
  3. Valve closes; a pneumatic cylinder pushes the bottle off (TP pulse, 1 second).
  4. Conveyor restarts; a CTU counts the bottle. At 10 bottles, signal "tray full."

Ladder (Siemens-style addressing; TON preset as S5TIME or TIME depending on platform):

Rung 1 — Run conveyor until bottle detected
   I0.3            I0.2             Q0.0
   TRAY NOT FULL   PHOTOEYE (NC    CONVEYOR
   (NC)            while clear)
  --[/]------------[/]-------------( )--

Rung 2 — Bottle present: open fill valve, start 5 s fill timer
   I0.2            TON_1.IN
   PHOTOEYE (NO)
  --[ ]------------------------[ TON, PT:=5s ]--
                                   DB1

Rung 3 — Fill valve follows the timer input (valve open while timing)
   TON_1.IN                        Q0.1
                                   FILL VALVE
  --[ ]----------------------------( )--

Rung 4 — Timer done: close valve (implicit, IN false), pulse the pusher cylinder
   TON_1.Q                         TP_1.IN
  --[ ]------------------------[ TP, PT:=1s ]--

Rung 5 — Pusher cylinder follows the pulse
   TP_1.Q                          Q0.2
                                   PUSHER
  --[ ]----------------------------( )--

Rung 6 — Count each completed bottle; reset after 10
   TON_1.Q (rising edge)           CTU_1
  --[P]------------------------[ CTU, PV:=10 ]--

Rung 7 — Tray full signal and conveyor inhibit
   CTU_1.Q                         Q0.3
                                   TRAY FULL LAMP
  --[ ]----------------------------( )--

Design notes worth defending in a review: the photoeye contact in Rung 1 is NC so the conveyor runs while the beam is clear and stops the instant a bottle breaks it; Rung 2's timer input is the same photoeye as NO, so timing only starts when a bottle is actually present; the CTU counts on the timer-done edge, so an aborted fill does not increment the count. The bottle-filling plant project linked above follows exactly this structure — compare your rungs against its working logic.

The same timer/counter vocabulary appears in a PLC-based pneumatic paper cutting machine: a photoeye or limit switch detects the sheet, a TON provides the clamp dwell time, and a TP fires the cutting cylinder. Learn the pattern once, reuse it everywhere.

I/O wiring that actually works: sinking vs sourcing, 24 V DC, relay vs transistor outputs

Wiring mistakes destroy more demo days than logic bugs. The four things to get right:

1. Sinking vs sourcing inputs — the number-one wiring mistake

From the PLC input module's point of view:

  • Sinking input module: current flows out of the input terminal, through the field device, to the common. It expects an NPN (sinking) sensor.
  • Sourcing input module: current flows into the input terminal from the field device. It expects a PNP (sourcing) sensor.

The rule that prevents the #1 wiring mistake: match the sensor's output type to the module's common wiring. A PNP (sourcing) sensor must feed a sourcing input module whose common is 0 V; an NPN (sinking) sensor must feed a sinking input module whose common is 24 V. Buy the sensor after you know your module — not before.

Student symptom of getting it wrong: the input LED behaves inverted or never lights, and no amount of ladder editing fixes it, because the problem is copper, not code. Draw the current path on paper before powering anything.

2. Keep control circuits at 24 V DC

Run your sensors, pushbuttons, and PLC I/O on 24 V DC from a dedicated SMPS. Switch 230 V AC only through contactors and relay outputs, never through sensor wiring. This single decision eliminates most shock hazards on a student panel and makes faults far easier to trace — a 24 V control circuit can be probed with a basic multimeter without the caution a mains circuit demands.

3. Relay outputs vs transistor outputs

Relay output Transistor output
Switches AC and DC DC only
Speed ~10 ms, too slow for fast pulsing Microseconds, suitable for PWM/fast pulses
Wear Mechanical contacts, rated around 100k operations No moving parts, effectively unlimited
Current Higher per point (often 2 A) Lower per point (often 0.3–0.5 A)
Typical student use Contactors, lamps, solenoid valves Indicator LEDs, small DC loads, fast signals

Practical guidance: drive contactor coils and pneumatic solenoid valves from relay outputs; drive high-speed or high-frequency signals from transistor outputs. Never switch a 3-phase motor directly from a PLC output — the output drives a contactor coil, and the contactor switches the motor. That two-stage arrangement (small signal → contactor → heavy load) is standard practice, and your panel should reflect it.

4. Wire like someone else will fault-find it

Ferrule every stranded conductor, keep 24 V DC and 230 V AC in separate trunking, label both ends of every wire with the terminal numbers, and maintain a one-page I/O list (terminal → device → function) taped inside the panel door. A temperature control trainer using PID is a good reference for tidy panel layout with labeled I/O.

Addressing basics: I0.0, Q0.0, M bits — across the three student brands

Addressing syntax differs by manufacturer. This table covers the brands you will actually meet in college labs:

Meaning Siemens (TIA Portal / S7-1200) Allen-Bradley (MicroLogix / RSLogix 500) Delta DVP (WPLSoft / ISPSoft)
Physical digital input I0.0, I0.1 … I:0/0, I:0/1 … X0, X1 …
Physical digital output Q0.0, Q0.1 … O:0/0, O:0/1 … Y0, Y1 …
Internal memory bit M0.0, M0.1 … B3:0/0, B3:0/1 … M0, M1 …
Timer TON_DB (IEC timer) T4:0 T0, T1 …
Counter CTU_DB (IEC counter) C5:0 C0, C1 …
Analog input (typical) IW64 I:1.0 D1110 (special registers vary)

Two habits save hours: never use a physical input address as scratch memory (use M bits / B3 bits for internal flags), and keep a written address allocation table before you start programming — deciding mid-project that Q0.2 means something different is how duplicate-coil bugs are born.

Which PLC fits a student budget

Most students use whatever their lab owns, which is usually a Siemens S7-1200 or S7-300, a Delta DVP, or occasionally an Allen-Bradley MicroLogix. If you are buying your own unit, the comparison below uses indicative market-typical price bands in INR (new units from industrial distributors; street prices move with stock and GST, so treat these as budgeting guidance, not quotations):

PLC Typical new-unit band (INR, indicative) Software Why students pick it
Delta DVP-SS2 / DVP-SX2 (14–20 I/O) ₹6,000 – ₹12,000 WPLSoft / ISPSoft, free; built-in simulator Lowest entry cost; common in Indian college labs
Siemens LOGO! 8 ₹10,000 – ₹16,000 LOGO! Soft Comfort (free demo; full version paid) Simple logic, compact, good for small demonstrators
Siemens S7-1200 (CPU 1214C) ₹25,000 – ₹40,000 TIA Portal (21-day trial; campus licenses vary) Industry-standard ladder + Profinet; strong on a resume
Allen-Bradley MicroLogix 1400 ₹35,000 – ₹60,000 RSLogix 500 / CCW (licensing varies) Common in plants using Rockwell ecosystems; harder to source new

Notes on buying: used and refurbished units from industrial surplus dealers typically run 40–60% of new prices and are fine for a student panel — PLCs are built for decades of service. Check that the seller includes the programming cable pinout; a missing proprietary cable can cost more than you expect. Whatever you buy, confirm the I/O count and type (relay vs transistor outputs, sinking vs sourcing inputs) against your I/O list before paying — a 14-I/O brick cannot run a 20-signal sequence.

Free simulators: learn ladder before you touch hardware

  • CODESYS — free development environment with a built-in soft-PLC simulator; IEC 61131-3 ladder, generous for learning.
  • OpenPLC — free and open-source; runs on a Raspberry Pi, so you can build a near-zero-cost hardware rig.
  • PLC Fiddle — browser-based ladder simulator; useful for testing a seal-in or timer rung in minutes with no install.
  • TIA Portal trial — 21-day trial of Siemens' official software; enough for one project cycle if you plan the install date.
  • Delta WPLSoft/ISPSoft — free downloads with simulation mode for the DVP series.

Simulate every sequence before wiring. A rung that misbehaves in simulation will misbehave identically on hardware, minus the smoke.

Analog inputs and scaling: turning raw counts into engineering units

So far everything has been digital — on or off. Real processes also need analog values: temperature, pressure, level, speed. A PLC analog input module reads a 4–20 mA current loop or a 0–10 V voltage signal and converts it to a raw integer (for a Siemens S7-1200, typically 0–27648 for the full range).

The 4–20 mA loop deserves a sentence of respect: 4 mA represents zero, not 0 mA, so a broken wire (0 mA) is distinguishable from a legitimate zero reading. This "live zero" is why industrial sensors use current loops, and why you should prefer 4–20 mA transmitters over 0–10 V for any sensor more than a couple of meters from the panel — voltage signals pick up noise on long cable runs.

Your program must scale the raw count into engineering units before using it. The formula is linear:

engineering_value = (raw - raw_min) * (eu_max - eu_min) / (raw_max - raw_min) + eu_min

Worked example: a temperature transmitter ranged 0–150 °C on a 4–20 mA loop, wired to a 0–27648 analog input. At a raw reading of 13824 (exactly half scale), the temperature is (13824/27648) × 150 = 75 °C. In TIA Portal the NORM_X and SCALE_X blocks do this in two rungs; in Delta and Allen-Bradley environments the equivalent is a SCP (scale with parameters) instruction or plain math.

Once you have a real engineering value, you can close the loop — which is exactly what a temperature control trainer using PID does: RTD or thermocouple input, scaled to °C, fed into a PID block whose output drives a heater via a solid-state relay. Two practical notes from that build: keep the analog signal cable shielded and grounded at one end only, and never run it in the same trunking as contactor or motor power cables — mains noise on an analog line shows up as a jittery temperature that no amount of PID tuning will fix, because the problem is copper, not control theory.

Structuring bigger sequences: the step-sequencer pattern

A three-step bottle filler fits in a handful of rungs. A railway gate controller — train approaches, gate closes, train passes, gate opens, with flashing signals throughout — does not. For anything beyond a few steps, use a step sequencer: one memory bit per step, exactly one step bit TRUE at a time, each step's rungs gated by its bit, and transitions that clear the current bit and set the next.

Step bits: M10.0 = IDLE, M10.1 = GATE_CLOSING, M10.2 = GATE_CLOSED_WAIT, M10.3 = GATE_OPENING

Rung — Transition: train detected while idle -> start closing
   M10.0           I0.4 (train approach sensor)
  --[ ]------------[ ]----------------( S )--  M10.1
                                      ( R )--  M10.0

Rung — Gate closing: motor runs while in GATE_CLOSING step
   M10.1           I0.5 (gate fully closed limit)
  --[ ]------------[/]-----------------( )--   Q0.4 (gate motor down)

Rung — Transition: gate closed -> wait for train to pass
   M10.1           I0.5
  --[ ]------------[ ]----------------( S )--  M10.2
                                      ( R )--  M10.1

The pattern's power is diagnostic: on demo day, when the sequence stalls, the step bits tell you exactly where it stopped, and the transition rung tells you which condition never became TRUE. Students who write long chains of interlocked timers instead invariably debug by staring; students with step bits debug by reading. Add one HMI lamp or panel LED per step bit and your fault-finding becomes visible from across the room.

Talking to the outside world: HMI and SCADA basics

The PLC does the real-time control; everything above it is supervision. A small HMI panel (or a SCADA package on a PC) connects to the PLC over Modbus RTU (RS-485 serial) or Modbus TCP (Ethernet) and reads/writes registers the PLC exposes — typically holding registers mapped to your M bits, timers, and scaled analog values. Keep the division of labor strict: the HMI displays status and accepts setpoints, but interlocks and safety stay in the PLC. If the HMI cable is unplugged, the machine must still run safely and stop safely. A SCADA screen that can override a hardwired interlock is a design error, not a feature — scope your SCADA to monitoring, alarming, and setpoint entry, and let the ladder own every safety decision.

Interlocks and E-stop: safety is hardwired, never software-only

Interlocks are conditions that must be true before an output is allowed to energize: guards closed, pressure within range, the other axis retracted. Implement interlocks in ladder as series NC/NO contacts ahead of the coil — they are part of the program scan and react within milliseconds.

The emergency stop is different: it must be hardwired. The E-stop mushroom button sits in series with the coil supply of the output contactor (or a safety relay's coil), wired with normally closed contacts so that pressing it — or a wire breaking — drops power to every actuator regardless of what the PLC program is doing. A software E-stop (an input the ladder reads, then turns outputs off) is not a substitute: a crashed CPU, a forced output, or a programming error can defeat it.

Minimum safety wiring for a student panel:

  1. E-stop (NC) in series with the main output contactor coil — pressing it kills all actuator power.
  2. A separate, clearly labeled control-power switch for the 24 V DC circuit.
  3. Fuses or MCBs on every power branch: mains incomer, 24 V SMPS output, each output group.
  4. Indicator lamps showing "control power ON" and "outputs enabled" so the panel state is visible at a glance.
  5. No exposed 230 V terminals — shrouded connectors, panel doors closed during demo.

Non-negotiable: have a faculty member inspect your panel wiring before first power-on, and again before demo day. This guide cannot certify your panel as safe, and no student project should claim safety certification it does not have. Projects like automatic railway gate control and automatic power factor correction involve mains-voltage sections — treat their power wiring with the same respect.

Demo-day commissioning checklist

Commissioning is the unglamorous half of a PLC project and the half that decides your demo. Work through this in order; it mirrors the debugging sequence in the project testing and debugging guide.

  1. Power without the PLC first. Energize 24 V DC, verify the SMPS output with a multimeter, and check every input LED by manually operating each sensor and switch. Fix wiring now, not later.
  2. Force outputs one at a time. Use the software's force table to energize each output individually and confirm the right actuator moves — and nothing else does. This catches crossed wires in minutes.
  3. Test the E-stop under power. With a non-critical output energized, press the E-stop and confirm everything drops. Reset properly and confirm the machine does not restart on its own (no automatic restart after E-stop reset — require a deliberate start press).
  4. Run the sequence dry. Step through the full automatic cycle with no product/material loaded. Watch each transition; use the software's online monitoring to see which rung is TRUE at each step.
  5. Time the real process. Measure actual fill times, cylinder strokes, and sensor response on the real hardware, then set timer presets from measured values — never from guesses.
  6. Back up the program. Save the final program with a versioned filename and keep a copy off the lab PC. A corrupted project file the night before demo day is a preventable disaster.
  7. Label everything. Wire labels, terminal numbers, and a one-page operating procedure taped to the panel. The person demonstrating should not need to remember which button does what.

Common failures: fault, cause, fix

Symptom Likely cause Fix
Output never energizes though the rung looks TRUE online Output forced OFF in the force table, or the output's fuse/MCB tripped Clear all forces; check the fuse and measure voltage at the terminal
Input LED on, but the ladder contact reads FALSE Sensor type mismatch (PNP sensor on a sinking module or vice versa) Rewire the common correctly or swap to the matching sensor type
Motor/contactor chatters rapidly Seal-in contact missing or wired to the wrong address; rung oscillating each scan Add the seal-in branch around the start contact; check for duplicate coils
Timer never reaches preset Timer input drops out before the preset (TON resets on FALSE input) Latch the timer's input condition, or switch to a retentive timer (TP/retentive TON)
Counter counts extra pulses Contact bounce on a mechanical switch, or a pulse shorter than scan time Add a debounce TON (50–100 ms) before the counter, or use a high-speed counter input
Everything works in manual, sequence jams in auto A transition condition never becomes TRUE (sensor misaligned, interlock missing) Monitor online, find the first FALSE rung in the sequence, and fix the physical condition
PLC program lost after power cycle Program not transferred to load memory / memory card, or battery-backed RAM without battery Download to load memory properly; verify by power-cycling and re-checking
230 V contactor hums loudly or welds Under-rated contactor, or missing snubber on an inductive coil driven by a transistor output Size the contactor to the motor's full-load current; add RC snubber/flyback diode per the coil type

Putting it together

A PLC project that demos cleanly is built from a small set of reliable patterns: the scan-cycle mental model, the seal-in rung, TON/TOF/TP and CTU/CTD sequenced from a written I/O list, sinking-sourcing wiring matched before power-on, and an E-stop that works with the PLC unplugged. The Electrical branch catalogue has several complete builds that apply these patterns end to end — the bottle-filling plant for sequencing, the paper cutting machine for pneumatics timing, and the power factor correction system for mains-side interfacing. Pick one as your reference architecture, simulate your logic before wiring, keep your I/O list honest, and get the panel checked by faculty before first power-on.

More project guides

More in Electrical