Connecting Arduino to Node-RED
This documentation explains how to use Node-RED to interact with an Arduino board via serial communication using the Firmata protocol. It covers how to write to and read from digital and analog pins using the node-red-node-arduino
package.
Requirements
- An Arduino board connected via USB to the device running Node-RED.
- The StandardFirmata sketch uploaded to the Arduino board.
- Node-RED installed and running on the connected device. The quickest way to set up and run Node-RED is FlowFuse.
- The Node-RED package
node-red-node-arduino
installed.
Step 1: Install Arduino Nodes
- Open the Node-RED editor.
- Open the main menu and select Manage Palette.
- Switch to the Install tab.
- Search for
node-red-node-arduino
and install it.
This will add arduino in
and arduino out
nodes to the palette.
Step 2: Configure Arduino Connection
- Drag either an
arduino in
orarduino out
node onto the canvas. - Double-click the node to open the configuration window.
- Click the pencil icon next to the Arduino board field.
- Enter the correct serial port:
- Windows:
COMx
(e.g.,COM5
) - Linux/macOS:
/dev/ttyUSB0
,/dev/ttyACM0
, etc.
- Windows:
- Click Add and then Done.
- Click Deploy. A green status indicator confirms successful connection.
Step 3: Write to Arduino Pins
3.1 Write Digital Output
To write a digital value (0
or 1
) to a pin:
- Drag an
arduino out
node to the canvas. - Double-click and set:
- Pin: e.g.,
13
- Type:
Digital
- Pin: e.g.,
- Use
inject
nodes to sendtrue
(HIGH) andfalse
(LOW) payloads. - Connect the inject nodes to the
arduino out
node. - Deploy and test.
3.2 Write Analog Output (PWM)
To write a PWM signal (0–255
) to a supported pin:
- Use an
arduino out
node. - Set:
- Pin: e.g.,
5
(PWM-capable) - Type:
Analog
- Pin: e.g.,
- Use an
inject
node to send a numeric payload (e.g.,128
). - Connect and deploy.
3.3 Write Servo Angle
To control a servo:
- Use an
arduino out
node. - Set:
- Pin: e.g.,
9
- Type:
Servo
- Pin: e.g.,
- Use
inject
nodes to send values between0–180
. - Connect and deploy.
Step 4: Read from Arduino Pins
4.1 Read Digital Input
To read a digital value from a pin:
- Drag an
arduino in
node. - Set:
- Pin: e.g.,
9
- Type:
Digital
- Pin: e.g.,
- Connect the output to a
debug
node. - Deploy to see input values in real-time.
4.2 Read Analog Input
To read from an analog input pin:
- Use an
arduino in
node. - Set:
- Pin: e.g.,
A0
- Type:
Analog
- Pin: e.g.,
- Connect to a
debug
node. - Deploy and monitor readings in the debug sidebar.
Once you have basic read/write functionality working with inject
and debug
nodes, you can easily build a dashboard interface using ui_button
, ui_slider
, or ui_gauge
nodes to control and monitor your Arduino through a web-based UI.
🔗 If you are looking for a more practical, step-by-step article with examples and a video demo, refer to this guide:
Interacting with Arduino using Node-RED