Category: Industrial Automation

  • PLC Code: How to Start With Your First Ladder Program

    PLC Code: How to Start With Your First Ladder Program

    PLC code is a repeating control routine that reads physical inputs, evaluates logic, and updates physical outputs. The most practical way to learn it is to follow that scan cycle while building one small start-stop control in a simulator.

    Unlike ordinary desktop code, a PLC program does not run once from top to bottom and then finish. The controller scans the logic continuously, so an input can change the result on the next scan. Begin with ladder logic, a clear I/O map, and a test sequence that predicts every state.

    Understand PLC code through the scan cycle and I/O model

    Connect physical inputs to input addresses

    A sensor or pushbutton connects to an input terminal, which the controller represents with an input address such as I0.0. Create an I/O list that names each device, its address, and its normal state. For a start-stop circuit, use one start input and one stop input. A normally closed stop circuit should produce a true Stop_OK condition while the button is released.

    Evaluate rung conditions on every scan

    During each scan, the PLC first updates its input image, then evaluates ladder rungs from left to right. Contacts represent conditions, and a rung becomes true only when its series conditions are satisfied. The controller repeats this process continuously rather than executing the logic only once.

    Write rung results to output addresses

    A coil writes the rung result to an output address such as Q0.0. That address controls an output module, relay, or simulated motor. The physical output is updated after logic evaluation, so a change normally appears by the next scan. Contacts referencing an output or internal bit can then provide memory for a control sequence.

    How to learn PLC programming: Choose one language and development environment

    Prepare a simulator, I/O table, and test checklist

    Choose one PLC family and its matching development environment or simulator. Avoid switching between controller dialects at the start. Before writing logic, record the device name, address, electrical or simulated type, normal state, and expected output. Add a checklist for initial, start, run, and stop conditions.

    Use ladder logic to mirror physical control

    Ladder logic is the best first language for this project because its contacts and coils resemble relay control diagrams. It makes input conditions, seal-in paths, and output status visible during monitoring.

    Recognize when other languages help

    Function block programming connects reusable blocks and suits analog processing, motion, and repeated control structures. Structured text is useful for calculations, data handling, and complex algorithms. Learn those after the scan model and basic ladder behavior are clear.

    Build a first ladder program: PLC programming for beginners

    1. Assign start, stop, and motor addresses

    This is a practical first project in PLC programming for beginners. Assign I0.0 to the start pushbutton, I0.1 to the stop circuit, and Q0.0 to a simulated motor. Define Stop_OK as true when the stop button is released and healthy.

    2. Build the start-stop seal-in rung

    Place the Stop_OK condition in series with a parallel branch containing the Start contact and a Q0.0 holding contact. Drive the Q0.0 coil at the right side of the rung. In logic terms, the rung is: Stop_OK AND (Start OR Q0.0) → Q0.0. Pressing Start turns on Q0.0; its holding contact keeps the rung true after Start is released.

    3. Define expected states: off, on, latched, and stopped

    1. Initial off: Start is false, Stop_OK is true, and Q0.0 is off.
    2. Starting: Start becomes true, the rung becomes true, and Q0.0 turns on.
    3. Latched run: Release Start. Its contact opens, but the Q0.0 holding contact keeps the motor on.
    4. Stopped: Press Stop. Stop_OK becomes false, the rung opens, and Q0.0 turns off.

    Simulate, test, and diagnose the start-stop control

    4. Simulate the input and output states in order

    1. Start with both buttons released. Confirm I0.0 is false, Stop_OK is true, and Q0.0 is off.
    2. Momentarily set I0.0 true. Confirm power flows through the rung and Q0.0 turns on.
    3. Return I0.0 to false. Confirm the holding contact keeps Q0.0 on.
    4. Set the stop input to its pressed state. Confirm Stop_OK becomes false and Q0.0 turns off.

    Diagnose address, logic, and scan faults

    Use the monitor view to compare each physical or simulated input with its assigned address. If an input never changes, check the mapping and normal-state definition. If the input changes but the rung remains false, inspect each contact from left to right, especially the stop condition and holding contact. If Q0.0 is true but the simulated device remains off, check the output mapping. A change that seems delayed by one scan usually reflects normal input sampling and output updating, not a failed rung.

  • G and M codes: Practical CNC Reference

    G and M codes: Practical CNC Reference

    G and M codes divide CNC instructions into two practical groups: G codes prepare motion, positioning, and cutting behavior, while M codes control machine actions such as the spindle, coolant, tool changes, and program flow. Use this G-code chart to identify motion commands, then use the M-code list for machine-control commands.

    The entries below reflect common milling conventions. Extended G and M code assignments can differ by controller, machine builder, and machine type, so confirm specialized commands in the relevant programming manual.

    How do G and M codes differ in a CNC program?

    A G code tells the control how to interpret movement or preparation. For example, G01 X40.0 F120 commands a straight feed move to X40.0 at a feed rate of 120. An M code triggers a machine function: M03 S2500 starts the spindle clockwise at 2,500 rpm.

    Many G codes are modal. A modal command remains active until another command in the same group cancels or replaces it. After G01, later coordinates continue using linear feed moves until G00, G02, or G03 changes the motion mode. Unit selection, work offsets, and absolute positioning are also typically modal.

    Non-modal, or one-shot, commands apply only to the block where they appear. G04 dwell is a common example. Most M codes are block-specific machine actions rather than continuously active modes, although exact behavior depends on the control.

    G90 selects absolute positioning: X and Y values refer to the active work coordinate zero. G91 selects incremental positioning: each value specifies a distance from the current location. A program should establish the intended mode explicitly.

    What belongs in a G-code chart for motion, coordinates, and units?

    • G00 X__ Y__ Z__ — rapid positioning without a cutting feed; modal.
    • G01 X__ Y__ Z__ F__ — straight-line interpolation at feed rate F; modal.
    • G02/G03 X__ Y__ I__ J__ F__ — clockwise or counterclockwise arc movement; modal. Arc syntax varies by plane and control.
    • G17/G18/G19 — select the XY, XZ, or YZ arc plane; typically modal.
    • G20/G21 — select inch or metric units; typically modal.
    • G54–G59 — select a stored work coordinate offset; modal.
    • G90/G91 — select absolute or incremental positioning; modal.
    • G04 P__ — dwell for a specified time or control-specific value; non-modal.
    • G40 — cancel cutter compensation; typically modal cancellation.
    • G43 H__ Z__ — apply tool-length compensation using offset H; modal until canceled.

    For example, G21 G90 G54 establishes metric units, absolute coordinates, and work offset 54. A later G01 X25.0 normally means “feed in a straight line to absolute X25.0,” provided G01 remains active.

    What should an M-code list show for spindle, coolant, and programs?

    • M03 S__ — start the spindle clockwise at the programmed speed.
    • M04 S__ — start the spindle counterclockwise.
    • M05 — stop the spindle.
    • M06 T__ — perform a tool change to the specified tool; syntax and sequencing vary.
    • M08 — turn coolant on.
    • M09 — turn coolant off.
    • M00 — mandatory program stop.
    • M01 — optional stop when the control’s optional-stop switch is enabled.
    • M30 — end and usually reset or rewind the program.
    • M98 P__ — call a subprogram; M99 commonly returns from it.

    Unlike G-code groups, M codes are often executed as discrete actions. A machine may restrict which M codes can share a block, so follow the controller’s documented sequencing rules.

    How do you read a short CNC program line by line?

    • % — program delimiter on controls that use it.
    • O1001 — program number.
    • G21 G17 G90 G54 — select metric units, the XY plane, absolute positioning, and work offset 54. These settings are modal.
    • T01 M06 — select tool 1 and execute the tool change.
    • S2500 M03 — set spindle speed to 2,500 rpm and start clockwise rotation.
    • G00 X0 Y0 Z5 — rapidly move to absolute X0, Y0, Z5, usually a clearance position.
    • G01 Z-2.0 F120 — feed down to absolute Z-2.0 at 120 units per minute.
    • G01 X40.0 — continue the modal linear move to absolute X40.0.
    • G00 Z5 — retract rapidly to absolute Z5.
    • M05 — stop the spindle.
    • M30 — end and reset the program.
  • Ladder Logic Symbols Explained: A Practical PLC Reference

    Ladder Logic Symbols Explained: A Practical PLC Reference

    Ladder logic symbols form a visual language for PLC programs. Read each rung from the left rail to the right: contacts and instruction blocks evaluate conditions, while coils write results. A rung is logically true when its path has continuity from the left rail to the output instruction.

    The most useful reference separates ladder diagram symbols by their job: carrying conditions, creating output actions, or changing a path based on time, counts, or values.

    Ladder Logic Symbols: How Rails, Rungs, and Branches Carry Logic

    Vertical rails represent the two sides of the control circuit, and each horizontal rung represents one logic statement. The left rail is the logical starting point; the right side usually contains an output coil or instruction. A PLC scans the program repeatedly, evaluating each rung with the current input and memory values.

    • Series path: Conditions are evaluated in sequence. Every contact in the path must be true for continuity to reach the output, which creates an AND relationship.
    • Parallel branch: Two or more paths provide alternate routes. If any complete branch is true, the output can be reached, creating an OR relationship.
    • Branch connection: A branch starts and rejoins at points on the rung. It can combine permissive conditions, create a seal-in path, or bypass one condition under a defined circumstance.

    Branches do not automatically mean that every instruction runs independently. The PLC evaluates the instructions in their program order, and the resulting Boolean state continues through the connected path.

    Ladder Diagram Symbols: Normally Open and Normally Closed Contacts

    Contacts test a Boolean address, such as a physical input, internal bit, timer status, or counter status. Their drawn appearance describes the instruction’s test, not necessarily the physical position of a field device.

    • Normally open contact: Drawn as –| |–. It evaluates true when its addressed bit is 1 or on, allowing rung continuity. When the bit is 0, the contact is logically open.
    • Normally closed contact: Drawn as –|/|–. It evaluates true when its addressed bit is 0 or off, allowing continuity. When the bit is 1, the contact is logically open.

    For example, an open contact tied to a Start input passes logic while Start is on. A closed contact tied to a Stop input passes logic until Stop becomes on. This distinction matters because a closed contact in the ladder does not mean the monitored device is physically closed; it means the instruction is testing for a false bit.

    Output Coils: Ordinary, Latched, Set, and Reset Actions

    Coils write the result of a rung to an output or internal Boolean address. The common ordinary coil, shown conceptually as –( )–, turns on while the rung is true and turns off when the rung becomes false. It reflects the rung continuously during the scan cycle.

    • Ordinary coil: Directly follows rung continuity. Use it when the output should track its conditions.
    • Latched output: Uses a holding, or seal-in, branch so the output remains on after the initiating contact turns off. A separate break condition removes the holding path.
    • Set coil: Writes the addressed bit on and leaves it on after the rung goes false. A separate reset action is required.
    • Reset coil: Writes the addressed bit off, normally overriding a previously set state or clearing a retained condition.

    Latch, set, and reset behavior can differ in naming and priority across PLC platforms. Treat the instruction’s documented write behavior as authoritative, especially when set and reset commands can be true in the same scan.

    PLC Symbols for Timers, Counters, and Comparison Blocks

    Timer, counter, and comparison instructions do more than represent a simple on-or-off input. They calculate a status that later contacts can test, so they alter when continuity is available.

    • Timer: A timer starts or maintains elapsed-time tracking when its enabling rung is true. A typical on-delay timer turns its Done status on after the preset time expires. A nonretentive timer usually clears its elapsed value when the enabling rung goes false; a retentive timer keeps it until reset.
    • Counter: An up counter increments on qualifying input transitions, while a down counter decrements them. Preset, done, and accumulated-value statuses can control later contacts or outputs. A reset instruction clears the count according to the configured behavior.
    • Comparison block: A block tests values such as greater than, equal to, or less than. Its Boolean result allows a rung to continue only when the comparison is true, such as when tank level is above a limit.

    These are core PLC symbols, but extended instruction shapes and names are not identical across vendors. Identify the instruction by its evaluated inputs, status outputs, preset values, and reset behavior rather than by its graphic alone.

  • Ladder Logic for PLC Beginners: Read a Basic Control Rung

    Ladder Logic for PLC Beginners: Read a Basic Control Rung

    Ladder logic is a graphical language for controlling machines with a programmable logic controller (PLC). It uses relay-style symbols so you can follow a control decision from input conditions to an output.

    In PLC ladder logic, the controller repeatedly reads field inputs, evaluates instructions, and updates outputs. Learning to follow that sequence makes a basic ladder logic diagram predictable rather than a collection of unfamiliar symbols.

    Ladder logic in the PLC scan cycle

    A ladder diagram is arranged between two vertical lines called rails. The left rail represents the beginning of logical power flow, and the right rail represents the destination. Horizontal lines between them are rungs. Each rung contains instructions that determine whether an output instruction becomes true.

    The PLC does not physically send power through the drawing as a relay panel would. Instead, it evaluates each instruction as a Boolean condition. A rung is true when at least one complete path from the left rail to the output is true. A rung is false when every possible path is blocked.

    The controller generally evaluates rungs from top to bottom and instructions from left to right. The exact scan details vary by PLC, but this ordering is the essential model for following control logic.

    Contacts, coils, rails, and rungs in a ladder logic diagram

    A contact tests a Boolean value, usually an input, internal bit, timer, counter, or output status.

    • Normally open (NO) contact: This instruction is true when its referenced bit is on. It passes logic when the bit equals 1.
    • Normally closed (NC) contact: This instruction is true when its referenced bit is off. It passes logic when the bit equals 0.
    • Output coil: This instruction writes the rung result to an output or internal bit. A true coil turns its assigned bit on; a false coil turns it off.
    • Rail: A vertical boundary that frames the logical path.
    • Rung: A horizontal line containing the conditions and result for one control decision.

    “Normally open” and “normally closed” describe the instruction’s logic behavior or the associated device’s unactuated design. The drawn contact does not prove the live field device’s current state. Check the referenced input or bit to know whether the instruction is currently true.

    How ladder logic programming follows input, logic, and output stages

    Ladder logic programming follows a repeating PLC scan with three practical stages:

    1. Input read: The PLC samples connected input devices, such as push buttons, switches, and sensors, and stores their current states in an input image or memory area.
    2. Logic execution: The PLC evaluates the program, including ladder rungs, using the stored input states and current internal values. It calculates whether each contact path and output coil is true.
    3. Output update: The PLC transfers calculated output states to physical outputs, energizing or de-energizing devices such as contactors, solenoid valves, and indicator lamps.

    Because outputs are commonly updated after logic execution, a change at a push button normally affects the controlled device during the scan in which the PLC reads that change and completes the program. The next scan then uses the updated output or internal status where applicable.

    How to read ladder logic in a simple start-stop circuit

    Consider a motor-control rung with this arrangement:

    Left rail → NC Stop → (NO Start in parallel with NO Motor Auxiliary) → Motor coil → Right rail

    The parallel branch is a seal-in, or holding, circuit. The motor’s auxiliary status keeps the motor command true after the Start button is released.

    1. At rest: The Stop button is not pressed, so its physical input is on when the button uses normally closed wiring. The NC Stop instruction is therefore true. Start is not pressed, so the NO Start instruction is false. The motor auxiliary bit is also false, leaving both parallel paths open. The rung is false, and the Motor coil is off.
    2. When Start is pressed: The input read stage records Start as on. During logic execution, the NC Stop instruction remains true and the NO Start instruction becomes true. A complete path now reaches the Motor coil, so the coil becomes true. During output update, the motor output energizes.
    3. After Start is released: The Start input returns off, making its NO instruction false. The energized motor’s auxiliary bit becomes on during the relevant scan, so the parallel auxiliary contact becomes true. The rung remains true and the motor stays energized.
    4. When Stop is pressed: The Stop input changes off. The NC Stop instruction becomes false, breaking the rung before either start path can reach the coil. The Motor coil becomes false, and the output update de-energizes the motor. On a later scan, the auxiliary bit also returns off.

    This left-to-right trace is the core method for how to read ladder logic: identify each referenced bit, determine whether each instruction is true, follow every complete path, and then check which output coil receives the rung result.