Convert serial.read() into a useable string using Arduino?

Joe picture Joe · Apr 18, 2011 · Viewed 341.5k times · Source

I'm using two Arduinos to sent plain text strings to each other using newsoftserial and an RF transceiver.

Each string is perhaps 20-30 characters in length. How do I convert Serial.read() into a string so I can do if x == "testing statements", etc.?

Answer

user1415516 picture user1415516 · Sep 15, 2012

Unlimited string readed

  String content = "";
  char character;

  while(Serial.available()) {
      character = Serial.read();
      content.concat(character);
  }

  if (content != "") {
    Serial.println(content);
  }