Skip to Content

MQTT on an M-Duino Arduino PLC with OpenPLC

Publish an input and receive a command over MQTT with the OpenPLC Editor and a Node-RED dashboard
June 18, 2026 by
Boot & Work Corp. S.L, Arnau Tena

OpenPLC can publish and receive MQTT messages on an M-Duino Arduino PLC over Ethernet. In this example the M-Duino Arduino PLC sends the state of input I0.0 to a Node-RED dashboard, and a switch in the dashboard turns output Q0.4 on and off.

How the M-Duino Arduino PLC, the broker and Node-RED exchange messages

MQTT has no master and no slave. The M-Duino Arduino PLC and Node-RED are both clients of the same broker. One publishes to a topic, and the broker delivers the message to every client subscribed to that topic.

  • Broker: runs on the PC, at 10.10.10.60 in this example. Mosquitto is a common choice. Since Mosquitto 2.0 it only accepts local connections by default, so add listener 1883 and allow_anonymous true to its configuration for a closed test network.
  • M-Duino Arduino PLC: runs the OpenPLC program, with the IP 10.10.10.70.
  • Node-RED: runs on the PC and shows and sends the messages.

Before you start

This post is part of a series about OpenPLC on Arduino and on the M-Duino Arduino PLC. If OpenPLC is new to you, start with these posts:

For Node-RED and MQTT, see the free course Develop your SCADA application based on Node-RED.

Node-RED: show the messages the M-Duino Arduino PLC sends

Create a flow with an mqtt in node subscribed to the topic test and connected to the broker. Connect it to a text node to see the message in the dashboard. A debug node also shows it in the debug panel.

Node-RED flow with an mqtt in node, a text node and a debug node

OpenPLC: publish input I0.0 from the M-Duino Arduino PLC

Start from the MQTT_Send example in the OpenPLC Editor: File, Tutorials and Examples, MQTT_Send.

Create three variables:

  • broker, type STRING, initial value the broker IP: "10.10.10.60".
  • topic, type STRING, initial value "test".
  • msg, type BOOL, location %IX0.0 (input I0.0).

The example variables keep their locations: blink_led at %QX0.0 and mqtt_connected at %QX0.1.

OpenPLC variable table for publishing input I0.0 over MQTT

Then change the ladder diagram:

  • Connect broker to the BROKER pin of MQTT_CONNECT0.
  • Connect topic to the TOPIC pin of MQTT_SEND0.
  • Connect msg to the MESSAGE pin through a BOOL to STRING conversion block.
  • Put a trigger block between the blink_led contact and the SEND pin, so that each pulse of blink_led sends one message instead of sending continuously.

OpenPLC ladder diagram that connects to the broker and publishes input I0.0

When the connection to the broker works, output Q0.1 turns on. Each pulse of blink_led then publishes the state of I0.0 to the topic test.

Compile and upload to the M-Duino Arduino PLC

  • Map your M-Duino Arduino PLC in the OpenPLC Editor, as explained in Mapping any M-Duino Arduino PLC on OpenPLC.
  • In the Transfer Program to PLC window, open the communications tab and enable Modbus TCP with the IP of the M-Duino Arduino PLC, 10.10.10.70 in our test. The program does not use Modbus TCP: in our test this option is what enabled the Ethernet interface that MQTT needs.

OpenPLC Transfer Program to PLC window with the Ethernet settings of the M-Duino Arduino PLC

Upload the program and change input I0.0. The new value appears in the Node-RED dashboard.

Node-RED dashboard showing the state of input I0.0 received over MQTT

Node-RED: send a command to the M-Duino Arduino PLC

Now the direction changes. Replace the mqtt in node with an mqtt out node, and the text node with a switch node from the dashboard.

Node-RED flow with a dashboard switch and an mqtt out node

Set the switch to send strings:

Node-RED switch node configured to send string values

OpenPLC: receive the command and switch output Q0.4

Open the MQTT_Send example again and set up the variables. This time msg is bound to output Q0.4, so Node-RED controls that output.

OpenPLC variable table for receiving a command on output Q0.4

Then build the ladder diagram:

OpenPLC ladder diagram that subscribes to the topic and drives output Q0.4

  • The MQTT subscribe block subscribes to the topic.
  • Once subscribed, the MQTT receive block listens for new messages.
  • The receive block returns a string, so a conversion block turns it into a BOOL.
  • An SR flip-flop keeps the last value of msg between messages.

Upload the program. The switch in the Node-RED dashboard now turns output Q0.4 on and off.

Next in the series: HTTP on an M-Duino Arduino PLC with OpenPLC.

​Search in our Blog

Boot & Work Corp. S.L, Arnau Tena June 18, 2026
Share this post
Tags

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison