Reading multiple sensors values from Arduino through Serial Communication

Hi all! I have hooked up a distance sensor and a button to my arduino and managed to successfully send values over to UE5.1.1 via Serial Com plugin. However, right now, I can’t seem to split the lines coming in, such that the individual sensors has different functions within UE. Nothing happens after ‘Switch on String’ node, and nothing is printed. But if I was to just hook to Split, individually it works. I am not sure if its a formatting issue?

I have attached my blueprint screencapture and the following is from my Arduino:

// reading distance sensor
if (distanceCm <= 0)
  {
    Serial.println("Out of range");
  }
  else 
  {
    Serial.print("distance ");
    Serial.print(distanceCm);
    Serial.print("cm");
    Serial.println();
  }

  // read the state of the pushbutton value:
  buttonState = digitalRead(BUTTON_PIN);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    Serial.print("button ");
    Serial.print("on");
    Serial.println();
  } else {
    Serial.print("button ");
    Serial.print("off");
    Serial.println();
  }
  delay(100);

}

Would appreciate if anyone can point me in the right direction! Thank you in advance :slight_smile:

why are you sending "button " (with a SPACE char in the end) ?

and why you split the received string ? when you split, right side of the
split is the remaining string AFTER the split. In you case nothing or a space char.

also your loop will STOP after distance or button is in the string because you sare printing
‘nothing’ and then the flow of the logic ends there (no loop recall)

also, Serial read string node has a bool output. You can also put a branch there and run next code only if success = true. if not call SerialReadLoop again.

Also if what you want is detect ‘button’ and ‘distance’ you can use FIND SUBSTRING instead. it will give you the position of the find in the string. if return is -1 then find failed (no find).