Try a PLC free — no signup
Math OperationsIntermediateIEC 61131-3

MOD (Modulo)

Returns the remainder after integer division of two values.

The MOD (Modulo) function returns the remainder after integer division of the first input by the second input. MOD is useful for creating cyclic patterns, detecting even/odd values, implementing circular buffers, and distributing items across lanes. For example, MOD(Count, 4) cycles through 0, 1, 2, 3, 0, 1, 2, 3... as Count increments.

Parameters

Inputs

NameTypeDescription
IN1ANY_INTDividend
IN2ANY_INTDivisor (must not be zero)

Outputs

NameTypeDescription
OUTANY_INTRemainder (IN1 MOD IN2)

Ladder Logic Example

// Ladder Logic - MOD (Lane Distribution)
//
// |----[MOD]----|
// | IN1: Part_Count       |
// | IN2: 4                |
// | OUT: Lane_Number      |

Structured Text Example

Lane_Number := Part_Count MOD 4;
// 0, 1, 2, 3, 0, 1, 2, 3...

Is_Even := (Value MOD 2) = 0;

Free · no signup to try

Run this block in your browser

Try the instruction on a live rung before you copy it into a project — nothing to install.

Try it in your browser — no signup

Opens plcsimulationsoftware.com — same team

Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use MOD instruction in TIA Portal SCL. In LAD/FBD, use DIV and MUL to calculate remainder.

AB

Allen-Bradley (Studio 5000)

No native MOD; calculate using: Remainder = IN1 - (IN1/IN2)*IN2.

C

CODESYS

Use MOD operator in ST. Available as function block in some libraries.

Common Applications

  • Cyclic lane distribution
  • Even/odd detection
  • Circular buffer indexing
  • Periodic event triggering
  • Time-of-day calculations

Frequently Asked Questions

What is MOD (Modulo) in PLC programming?

Returns the remainder after integer division of two values. The MOD (Modulo) function returns the remainder after integer division of the first input by the second input. MOD is useful for creating cyclic patterns, detecting even/odd values, implementing circular buffers, and distributing items across lanes.

What are common applications of MOD (Modulo)?

MOD (Modulo) is commonly used for: Cyclic lane distribution, Even/odd detection, Circular buffer indexing, Periodic event triggering, Time-of-day calculations.

How do I use MOD (Modulo) in different PLC platforms?

Siemens: Use MOD instruction in TIA Portal SCL. In LAD/FBD, use DIV and MUL to calculate remainder. Allen-Bradley: No native MOD; calculate using: Remainder = IN1 - (IN1/IN2)*IN2. CODESYS: Use MOD operator in ST. Available as function block in some libraries.

Free · no signup to try

Wire this block up and run it

Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.

Try it in your browser — no signup

Opens plcsimulationsoftware.com — same team

Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad