Parsing Serial Data Sent To Arduino

I use this code constantly. It basically packages serial data for strtok_r to split into pieces paced on predefined deliminators. Each bit of data is separated by a “,” and the end of the set of data is a “.”

If you send in a string like:

You can split it into three varaibles that equate to those different values. In this case:

The Variable x would equate to 10.

Here’s the code:

Here’s an example.

Say you have a serial device hooked up to your softserial port and in inputs “10,50,100.” to the arduino to be split up. If you want to set each of these numbers to separate integers and then print them to the serial console, you’d do it like this.

Hey! This post was written a long time ago, but I'm leaving it up on the off-chance it may help someone. Proceed with caution. It may not be a good idea to blindly integrate this code or work into your project, but instead use it as a starting point.


  1. hi sir,

    sir i have a problem i try your code the and my data coming from serial port is in decimal how do i edit your code so that i can read the whole decimal form of the data that arduino reads


    1. Hi!

      Yeah, unfortunately this doesn’t work with sending decimals back and forth. Could you try changing up your data? Sending the integer part and the decimal part separately?


  2. i am new in arduino programming so a am sorry for this silly question, but if i get something like that 180 0 0 90 90 180, wherе for end i have space how i need to form my code???

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.