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.


  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?


Leave a Reply

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