Skip to content

Arduino PLC: Running Scan-Based Control Logic on MPINO

A PLC owes its reliability to one idea: a deterministic scan cycle that reads inputs, solves logic, and writes outputs over and over. MPINO controllers reproduce that model in an Arduino sketch, letting you write ladder-equivalent machine control on high-density units such as the MPINO-16A8R, MPINO-16A16R and MPINO-16A8R8T.

The Scan Cycle in an Arduino Loop

A traditional PLC executes a repeating sequence: sample all inputs into an image table, evaluate the user program against that image, then write the results to the outputs. The Arduino loop() function maps onto this pattern naturally. At the top of each pass you read every digital and analog input into local variables, in the middle you evaluate your control logic against those stable values, and at the bottom you commit the computed states to the relay or transistor outputs.

Reading inputs once per scan into an image, rather than polling pins ad hoc throughout the logic, is what gives a PLC its predictable behaviour, and the same discipline applies here. On an MPINO-16A16R with 16 digital inputs and 16 relay outputs, you snapshot all 16 inputs at the start of loop(), so that a contact cannot appear to change state midway through a rung evaluation. The result is a scan that behaves consistently cycle after cycle, exactly as a control engineer expects.

Ladder-Equivalent Patterns in C

Ladder logic is, at its core, Boolean algebra evaluated every scan. A series contact is a logical AND, a parallel branch is an OR, and a normally-closed contact is a negation. These translate directly into C expressions. A rung that energises an output coil when a start button is pressed and a stop button is not, becomes a single assignment evaluated each pass through loop(): the output equals start AND NOT stop, latched through its own state.

Common PLC instructions map just as cleanly. A seal-in (latch) rung is an OR with the coil's own previous state. A timer is a comparison against millis() captured when a condition first became true. A counter is an integer incremented on the rising edge of an input, which you detect by comparing the current input image to the previous scan's image. On an MPINO-16A8R8T, you can drive 8 relay and 8 transistor outputs from this logic while also commanding 2 analog outputs for proportional valves or drives, all inside one deterministic scan.

Deterministic Timing and Edge Detection

Determinism comes from keeping the scan free of blocking calls. Avoid delay(); instead, use millis() timestamps so the loop never stalls waiting on a timer, and every output is serviced on every pass. Debouncing field inputs, sequencing steps in a state machine, and enforcing minimum on/off times all become straightforward when each is expressed as a comparison against a captured timestamp rather than a blocking wait.

Edge detection is the second pillar. Because you hold both the current and previous input image, a rising edge is simply current AND NOT previous, and a falling edge is the inverse. This is how you start a one-shot, advance a step, or increment a counter exactly once per transition. On the ATmega2560-based MPINO-16A8R, the additional flash and RAM headroom comfortably hosts multi-step sequencers, several independent timers, and counters running together without the scan time growing unpredictable.

Choosing the Right MPINO for Machine Control

Match the I/O count to the machine. A compact interlock or pump-control panel may need only the 8 inputs and 8 relays of an MPINO-8A8R-S, while a packaging or conveyor station with many sensors and actuators is better served by the 16 inputs and 16 relays of an MPINO-16A16R. When the application mixes slow contactor switching with fast solid-state actuation, the MPINO-16A8R8T pairs 8 relay outputs for AC loads with 8 transistor outputs for high-speed DC devices in a single controller.

Because all of these run the same scan-based sketch in the standard Arduino IDE, you can prototype the control logic on one model and deploy it on another with only the I/O mapping changed. The deterministic loop structure you build on an MPINO-8A8R-S is identical in form to the one running on an MPINO-16A8R8T, so machine control logic scales across the range without a change of programming paradigm.

Related controllers

MPINO-8A8R-S industrial Arduino controller — front view

MPINO-8A8R-S

MPINO-8A8R-S Industrial Arduino Controller

8 DI / 8 Relay / 4 AI / 2 NTC / RS-485 / I²C
$86.00
MPINO-16A8R industrial Arduino controller — front view

MPINO-16A8R

MPINO-16A8R Industrial Arduino Controller

16 DI / 8 Relay / 4 AI / RS-232 / RS-485 / UART / I²C
$92.00
MPINO-16A16R industrial Arduino controller — front view

MPINO-16A16R

MPINO-16A16R Industrial Arduino Controller

16 DI / 16 Relay / 4 AI / 2 NTC / RS-485 / I²C
$109.00

Related guides

FAQ

Can an Arduino really replace a PLC for machine control?

For single machines, skids and distributed nodes, yes. An MPINO controller reproduces the PLC scan cycle (read inputs, solve logic, write outputs) in an Arduino sketch, with opto-isolated inputs and relay or transistor outputs. High-I/O models such as the MPINO-16A16R and MPINO-16A8R8T provide the channel count typical machines require.

How do I implement ladder logic timers and counters on MPINO?

Implement timers as comparisons against a millis() timestamp captured when a condition becomes true, and counters as integers incremented on a detected rising edge. Because the loop holds both the current and previous input image, edge detection (current AND NOT previous) lets you advance counters and one-shots exactly once per transition.

Is the scan cycle on MPINO deterministic?

It is deterministic as long as you keep blocking calls out of loop(). Snapshot all inputs at the top of the scan, avoid delay(), use millis() for timing, and write outputs at the bottom. On ATmega2560 models such as the MPINO-16A8R, the extra RAM and flash let multiple timers, counters and sequencers run together without the scan time growing unpredictably.