Quick answer: to read Arduino sensor data in Node-RED over USB, make the sketch print one line per reading (ideally a small JSON object) with Serial.println(). Install node-red-node-serialport from the palette, then add a serial in node set to the Arduino's port (COM3, /dev/ttyACM0 or /dev/ttyUSB0) and the same baud rate (115200 here), splitting input on the newline character \n. Connect it to a json node and a debug node. Close the Arduino IDE Serial Monitor first, because only one program can open the port. To send commands back, use a serial out node on the same port.
A USB cable is the simplest link between an Arduino Uno or Nano and Node-RED: no Wi-Fi, no broker, and it works with boards that have no networking at all. This guide sends a potentiometer reading to a Node-RED dashboard and switches the Arduino's LED from a dashboard button, covering both directions and the gotchas most tutorials skip (auto-reset, partial lines, Linux permissions).
| What you need | Notes |
|---|---|
| Arduino Uno, Nano or Mega | Any board with USB serial works |
| 10 kΩ potentiometer (or any analog sensor) | Middle pin to A0, outer pins to 5V and GND |
| Computer or Raspberry Pi running Node-RED | Same machine the Arduino is plugged into |
| node-red-node-serialport | Installed from Manage palette |
| Optional: @flowfuse/node-red-dashboard | For the gauge and button |
1. Choose a line format
Serial is just a stream of bytes, so Node-RED needs to know where one reading ends and the next begins. The rule: one complete reading per line, ending in a newline. Two common formats:
| Format | Example line | Parse in Node-RED with |
|---|---|---|
| JSON (recommended) | {"pot":512,"n":42} | json node |
| CSV | 512,42 | csv node, or msg.payload.split(",") in a function |
JSON is self-describing, so adding a field later doesn't break the flow. Keep the line short: an Uno has only 2 KB of RAM.
{"pot":512,"n":42}Never mix human-readable debug text ("Starting…", "Reading sensor") into the same stream: the json node will throw an error on every such line. If you need debug messages, prefix them (for example # starting) and filter lines that start with # in Node-RED.
2. Upload the Arduino sketch
This sketch sends the potentiometer value and a counter once per second, and listens for LED:1 / LED:0 commands from Node-RED to switch the onboard LED (pin 13).
const int POT_PIN = A0;
const int LED_PIN = LED_BUILTIN; // pin 13 on Uno/Nano/Mega
unsigned long n = 0;
unsigned long lastSend = 0;
String cmd;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Send one JSON line per second (no delay(), so commands are read promptly)
if (millis() - lastSend >= 1000) {
lastSend = millis();
Serial.print("{\"pot\":");
Serial.print(analogRead(POT_PIN)); // 0-1023 raw ADC counts
Serial.print(",\"n\":");
Serial.print(n++);
Serial.println("}");
}
// Read commands like "LED:1\n" from Node-RED
while (Serial.available()) {
char c = Serial.read();
if (c == '\n') {
cmd.trim();
if (cmd == "LED:1") digitalWrite(LED_PIN, HIGH);
else if (cmd == "LED:0") digitalWrite(LED_PIN, LOW);
cmd = "";
} else if (cmd.length() < 16) {
cmd += c;
}
}
}Open the Serial Monitor at 115200 baud once to check you see lines like {"pot":734,"n":12}, then close it before starting Node-RED.
analogRead() returns raw counts from 0 to 1023. To show volts on a 5 V Uno, multiply by 5.0 / 1023 (in the sketch or in Node-RED), and label the value accordingly.
3. Install and configure the serial nodes
- In Node-RED: Menu → Manage palette → Install, search node-red-node-serialport, install. You get serial in, serial out and serial request nodes.
- Drag in a serial in node and click the pencil to add a serial port:
| Setting | Value |
|---|---|
| Serial Port | Click the magnifier to list ports, or type it (see table below) |
| Baud Rate | 115200 (must match Serial.begin) |
| Data bits / Parity / Stop bits | 8 / None / 1 (the Arduino default) |
| Input: Split input | on the character \n |
| Deliver | ASCII strings |
| Add character to output messages | \n (used by the serial out node when sending commands) |
| Operating system | Typical Arduino port |
|---|---|
| Windows | COM3, COM4… (check Device Manager → Ports) |
| Raspberry Pi / Linux, genuine Uno or Mega | /dev/ttyACM0 |
| Linux, Nano clone with CH340 chip | /dev/ttyUSB0 |
| macOS | /dev/cu.usbmodem… or /dev/cu.usbserial… |
On Linux, port numbers can change when you replug. For a fixed name, use the path under /dev/serial/by-id/.
- Wire serial in → debug and deploy. The node shows a green connected status, and lines appear in the debug sidebar every second.
4. Parse and validate each line
Build: serial in → json → function "validate" → debug. Set the json node's action to Always convert to JavaScript Object. The function drops anything incomplete:
const d = msg.payload;
if (!d || typeof d !== "object" || !Number.isInteger(d.pot) || d.pot < 0 || d.pot > 1023) {
node.warn("Bad line: " + JSON.stringify(d));
return null;
}
msg.payload = Math.round(d.pot * 5000 / 1023) / 1000; // volts, 3 decimals (5 V board)
msg.topic = "pot_volts";
return msg;Watch out for auto-reset. On most Uno and Nano boards, opening the serial port resets the Arduino, so after every deploy or reconnect the first line may arrive half-written, and the board takes about 1–2 seconds to start sending. The validation above simply drops that first broken line. Add a catch node wired to a debug node to see json parse errors instead of letting them fail silently.
5. Show it on a dashboard and send commands back
With @flowfuse/node-red-dashboard (Dashboard 2.0) installed:
- validate → gauge (min 0, max 5, unit V) and validate → chart for a live trend.
- button "LED on" (payload
LED:1) and button "LED off" (payloadLED:0) → serial out node using the same serial port config. The port config's "add character" setting appends the\nthe sketch waits for.
Press the buttons and the Arduino's onboard LED follows. New to dashboards? See Node-RED Dashboard 2.0 setup.
Request/response instead of streaming: if the Arduino should only answer when asked, use the serial request node: send READ\n, have the sketch reply with one line, and the node returns that reply as the response to your request.
Storing the readings
To keep history beyond the dashboard chart's memory, send the validated values to a file (file node appending CSV lines), to SQLite, or to InfluxDB: Node-RED, InfluxDB and Grafana sensor logging uses the same validate-then-write pattern. One reading per second is about 86,400 rows a day, so sample only as fast as you need.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
Node status "error" / Error: Opening COM3: Access denied | Arduino IDE Serial Monitor or another program has the port | Close Serial Monitor (and Arduino IDE uploads), then redeploy |
Error: Permission denied, cannot open /dev/ttyACM0 | The Linux user running Node-RED isn't in the dialout group | sudo usermod -a -G dialout $USER, then log out/in or reboot |
Garbage characters (ÿ⸮⸮) | Baud rate mismatch | Same baud in Serial.begin() and the port config |
| One character per message | Split option set to none, or wrong character | Split on the character \n |
| Readings arrive merged or cut in half | Splitting on timeout, or sketch uses print without println | Use println at the end of each reading; split on \n |
| json node: "Unexpected token" | A debug line or a partial first line after reset | Keep the stream JSON-only; validation drops the partial line |
| Port not listed | Charge-only USB cable, missing CH340 driver, board not powered | Try another cable; install the CH340 driver for clones |
| Works, then stops after replugging | Port name changed (ttyACM0 → ttyACM1) | Use /dev/serial/by-id/… on Linux |
| Can't upload a new sketch | Node-RED holds the port | Disable the serial nodes (or stop Node-RED) while uploading |
| Commands from Node-RED ignored | No newline appended | Set "add character to output messages" to \n in the port config |
FAQ
Do I need Firmata to use Arduino with Node-RED? No. Firmata (node-red-node-arduino) lets Node-RED control the pins directly, but your sketch can't do anything else. The serial approach in this guide keeps your own sketch in charge and is more flexible.
Can a Raspberry Pi running Node-RED read an Arduino over USB?
Yes. Plug the Arduino into the Pi's USB port and select /dev/ttyACM0 or /dev/ttyUSB0. The Pi also powers the Arduino.
What baud rate should I use? 115200 is a good default for a few readings per second. Both ends must use the same value.
Can I read several sensors?
Yes. Put them all in one JSON line, for example {"t":23.4,"h":51,"pot":512}, and read each field in Node-RED.
Why does my Arduino restart when Node-RED connects? Opening the port toggles the DTR line, which resets most Uno and Nano boards. It's normal; just expect a short gap and a possibly broken first line.
Next steps
- Your first Node-RED flow: inject, function and debug, if the flow editor is new to you.
- Node-RED Dashboard 2.0: buttons, switches and gauges.
- Going wireless? ESP32 DHT11 + BMP280 dashboard over MQTT replaces the USB cable with Wi-Fi.
- Arduino Uno pinout: find the analog pins for more sensors.
Official references: node-red-node-serialport and Node-RED messages.
Make serial ingestion tolerant of real-world data
A USB serial connection is a byte stream. A single read can contain half a line, one complete line or several lines, depending on timing and buffer state. Use a newline delimiter as the record boundary and make sure the Arduino sends one complete record per line. On the Node-RED side, configure the serial node to split on the same delimiter before parsing JSON. Do not assume that one USB packet equals one sensor reading.
Validate every record after parsing. Check that required fields exist, are numeric and fall within application-specific ranges. Handle an empty line, malformed JSON and an incomplete record without stopping the entire flow. A useful pattern is to route valid readings to the dashboard or storage branch and invalid records to a separate debug branch that records the reason and a short, sanitized sample.
The serial configuration must match the sketch: port, baud rate, data bits, parity, stop bits and line ending. Close Arduino Serial Monitor and other terminal programs before Node-RED opens the same port; most operating systems allow only one application to own a serial device at a time. On Windows, the COM number can change when the board is moved to another USB socket. On Linux, device permissions and changing /dev/tty names can also cause a flow to stop working after a reboot.
Plan for disconnects and long-running collection
USB serial devices can disappear during a reset, cable movement or power interruption. Decide how the flow should recover: detect the disconnected state, wait before retrying, and avoid creating a tight reconnect loop. When the port returns, verify that the first line is complete before treating it as a valid reading. If the Arduino prints startup messages before the first JSON record, either parse those messages separately or keep them off the data channel.
For long-running measurements, store a timestamp with each accepted reading and monitor the time since the last valid record. A dashboard that still shows the last number can otherwise look healthy after the USB cable has been removed. Keep raw serial logs only as long as needed, and avoid logging credentials or personal information. Export the Node-RED flow and document the board, port, baud rate and expected line format so the setup can be reproduced on another computer.




