Interfacing Arduino with NodeRed on RaspberryPi


Im just diving into Node-RED and im currently working on a project that involves me to display a PSI sensor data from an arduino onto a raspberry pi running node-red. I have uploaded the standardfirmata sketch to the arduino and I am able to get the node to recognize it, but the value is not correct. I thought adding a function node would help with an equation in order to get the correct value but not sure where to start with coding in the function node.

but not sure where to start with coding in the function node.

Start at the beginning :stuck_out_tongue_winking_eye:

When you say the data is incorrect what do you mean? Can you give an example of what it is and what it should be? And maybe the equation you would use.

You might be able to just use a change node with a JSONata expression

Also add a debug node on the output of the node retreiving the data. That will show the data and it's type which will be needed to determine how to convert it.

Thanks for the reply, i guess my real problem is im lacking in knowledge in javascript but i created a python program to interact with the Arduino and get serial data.

My flow starts with a inject => exce (which contains the python program and an error2?) => then into a function node (which is where im stuck) => into a gauge node and a debug node

my python program is simple as follows

import serial

ser =serial.Serial('/dev/ttyACM0', baudrate = 9600, timeout=1)

while 1:

    arduinoData = ser.readline()

and Arduino code:

int rawValue; // A/D readings
int offset = 102; // zero pressure adjust
int fullScale = 922; // max pressure (span) adjust
float pressure; // final pressure

void setup() {
  // put your setup code here, to run once:

void loop() {

  // put your main code here, to run repeatedly:
  int rawValue = analogRead(A0); 
   pressure = ((((rawValue - offset) * 1.2 / (fullScale - offset))*145.038)-44.64); // pressure conversion
 // Serial.println(pressure, 3);

  if (pressure < 0) {

  } else {

A couple things, some you have covered some you haven't. when you open a thread I find it very helpful to start off detailing the hardware, OS release, version of NR and node.js and a copy of the flow - hopefully reduced to the minimum showing the issue.

Put a debug node (displaying the complete msg object) on the output of the exec node.
What dooes it show?
What are th parameters you ase passing fro the inject node?
What are your settings in the exec node?

I am using a Raspberry Pi 3 B+ running Raspian, and an arduino uno.

  • NR V0.19.4
  • Node.js V8.11.1


  • i get msg.payload : undefined in the debug screen

  • the inject repeats every 1 second

  • the command in my exec node is command: python; append msg.payload is checked and i have it while the command is running - spawn mode.

Some problems with your flow, can't be imported



Welcome to the magic world of Node-Red.

Getting Arduinos talking to Node-Red is fun.

Just on what you said:

The PSI data should be sent out - as it seem reading it: by the serial port? - to the RPI.
That's ok, I guess.

What I would suggest you do is try this first to establish a base line that the Arduino is doing the right thing.

Load the IDE and open the serial port to the Arduino.
You should see the data being sent out line by line.
The exact format is not too important at this stage, other than every line should be the same format.
Say something like:
and so on.
Be it has PSI at the end doesn't matter at this stage.

These data packets are sent to NR and processed.

If that isn't working, you are in trouble before you get started.

If they are all good, maybe then you need to get the serial input node and connect it to a debug node.

This should give you the same results as you did in the Arduino's IDE.

Given that, then you need to look at the flow.

But until then.......

I hope that helps you with finding where the data is going wrong.

All the best.