Node-RED
Automations
Setting up our gateways as a mini PLC with Node-RED
Overview
This tutorial demonstrates how to add PLC Digital IO control to an Amplified Engineering gateway using Node-RED. You'll learn to read digital inputs, apply logic conditions, and control outputs—all through an intuitive visual programming interface.
*note: we are using the nodeG5 gateway for this tutorial, but the same concepts & flow is applicable across our different products.
What you'll accomplish
Create a flow that reads Digital Input 1 every 5 seconds and sets Digital Output 1 to HIGH when the input is active.
Prerequisites
-
Raspberry Pi running Debian Bookworm OS
-
Basic familiarity with terminal commands
-
Physical access to your gateway's digital I/O pins.
Step 1: Installing Node-RED
First, install Node-RED on your Debian Bookworm system. Open a terminal and run:
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
Once installation completes, enable Node-RED to start automatically on boot:
sudo systemctl enable nodered.service
sudo systemctl start nodered.service
Access the Node-RED editor by opening a web browser and navigating to:
http://nodeg5:1880
Replace nodeg5 with your gateway's hostname or IP address.
Step 2: Creating your Control Flow
2.1 Add a Timer Node
From the left panel, drag an inject node onto the canvas. This will trigger your flow every 5 seconds.
Double-click the inject node to configure it:
-
Set Repeat to "interval"
-
Set interval to "every 5 seconds"
-
Click Done
2.2 Read Digital Input 1
Drag an exec node onto the canvas and connect it to your timer node.
Double-click to configure (see Image 2):
-
Command: iotg-imx8plus-dio -i 1
-
Append: msg.payload
-
Output: "when the command is complete - exec mode"
-
Name: "Read Input 1"
-
Click Done
This node executes the command to read the state of Digital Input 1.
2.3 Parse the Input Value
Drag a function node (or i node) onto the canvas. For simplicity, we'll assume the exec output needs parsing. Connect it to the "Read Input 1" exec node.
However, if the output is already numeric, proceed directly to the switch node.
2.4 Add Conditional Logic
Drag a switch node onto the canvas and connect it to the previous node.
Double-click to configure (see Image 3):
-
Property: msg.payload
-
Condition 1: "==" and value "1" → output 1
-
Condition 2: "otherwise" → output 2
-
Name: "If Input = 1"
-
Click Done


This node checks if the input value equals 1 (HIGH).
2.5 Set Output 1 to HIGH
Drag another exec node onto the canvas and connect it to the first output of the switch node (the "= 1" condition).
Double-click to configure (see Image 5):
-
Command: iotg-imx8plus-dio -o 1 1
-
Append: msg.payload
-
Output: "when the command is complete - exec mode"
-
Name: "Set Output 1 HIGH"
-
Click Done

2.6 Set Output 1 to LOW (Optional)
For complete control, add another exec node connected to the second output of the switch node (the "otherwise" condition):
-
Command: iotg-imx8plus-dio -o 1 0
-
Name: "Set Output 1 LOW"
Step 3: Deploy & Test
Click the red Deploy button in the upper-right corner to activate your flow.
Open the debug panel on the right side to monitor activity (see Images 1 and 4). You should see:
-
Input value readings every 5 seconds
-
Output HIGH/LOW commands triggered based on input state
To test physically:
-
Apply a signal to Digital Input 1 (e.g., connect to 3.3V or use a switch)


-
Observe Digital Output 1 responding accordingly
-
Monitor the debug console for real-time message flow

_________________________________________________________________________________________________________
Understanding the Flow
Your completed flow follows this logic sequence:
Timer (5s) → Read Input 1 → Parse Value → Check If = 1 → Set Output HIGH/LOW
This basic pattern can be extended to create complex automation scenarios: multiple inputs, timer-based sequences, data logging, or integration with cloud services.
_________________________________________________________________________________________________________
Next Steps
Now that you've built your first PLC-style flow, consider:
-
Adding multiple input/output controls
-
Implementing latching logic or timing delays
-
Connecting to MQTT for remote monitoring
-
Creating a dashboard using Node-RED Dashboard nodes
-
Logging I/O states to a database
Node-RED's visual programming approach makes industrial automation accessible without traditional PLC programming languages—perfect for rapid prototyping and custom gateway applications.