Learn PLCs free
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;

20 Production-Ready Ladder Logic Templates

Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.

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.

Stop Writing Ladder Logic From Scratch

Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.

20
Ready-Made Templates
LD + ST
Both Languages Included
$29
One-Time Purchase
Get Instant Access -- $29

Instant download - 30-day money-back guarantee - Use on unlimited projects

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →