I have two Arduinos connected through Bluetooth. One sends a string of data similar to 506:507:1\r\n. The data can vary similar to 0:1000:0\r\n. I already have functions to break that string down into three variables. I send it from one Arduino over Bluetooth and the second Arduino receives it through Serial. The only problem is that the second Arduino receives this:


At the end it adds a space at the end ("\n") How can I parse this data back into a string similar to 506:507:1\r\n that can still vary in length?

  • Read this: hackingmajenkoblog.wordpress.com/2016/02/01/…
    – Majenko
    Apr 6, 2016 at 22:34
  • I don't see what the problem is? Though, you do seem to miss the \r? And I don't see the space at the end? You can easily make it a string by adding the characters to the string, until you receive your end character \n? Maybe https://www.arduino.cc/en/Serial/ReadStringUntil is an easy to use, "all in one" solution for you.
    – aaa
    May 7, 2016 at 9:35

1 Answer 1


Simply reverse the steps you took on the sending side.

  • Create a char array of sufficient size as well as an index variable to keep track of your position within the array. An Arduino String may be more convenient, though they can cause a lot of problems.
  • In a loop, use available() to wait for incoming chars and add them to the array you've created, using your index variable.
  • Keep going in the loop, while checking for that unique character (\n, perhaps) that signals the end of a packet. Add this last byte to the array and then terminate the string with null or \0.

If you want to re-use the array for another packet, simply set the index variable to 0 and continue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.