How to send command to Arduino through serial commend?

I want to use Node-RED: inject node to send commands to Arduino, Below is the code I wrote, but it did not work. Does anyone know how to write? Thank you.

void messageReceived () {
   if (payload = 0) 
   {
     Serial.println("open");
     digitalWrite(pump_in1_sol_A, HIGH); 
     digitalWrite(pump_in2_sol_A, LOW); 
   } 
   else if (payload = 1) 
   {
     Serial.println("closed");
     digitalWrite(pump_in1_sol_A, LOW); 
     digitalWrite(pump_in2_sol_A, LOW);  
   }
}
1 Like

Does the code you posted run on the Arduino?
The statement if (payload = 0) looks wrong. You are assigning a value to payload, not testing the current value.

There is a Serial i/o node which sends msg.payload to the serial port. Are you using that?
Untitled 1

1 Like

@51fei

You should go read this: if - Arduino Reference

1 Like

Should be:

if (payload == 0)

not

if (payload = 0)

1 Like

Thank you, I had solved the problem.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.