Arduino Serial Plotter: The Missing Manual

If you use Arduino, perhaps to handle the lower-level driving work of your DIY Robocar, you may have noticed the Serial Plotter tool, which is an easy way to graph data coming off your Arduino (much better than just watching numbers scroll past in the Serial Monitor).

You may have also noticed that the Arduino documentation gives no instructions on how to use it ¯\_(ツ)_/¯. You can Google around and find community tutorials, such as this one, which give you the basics. But none I’ve found are complete.

So this is an effort to make a complete guide to using the Arduino Serial Plotter, using some elements from the above linked tutorial.

First, you can find the feature here in the Arduino IDE:

It will plot any data your Arduino is sending out in a Serial.print() or Serial.println() command. The vertical Y-axis auto adjusts itself as the value of the output increases or decreases and the X-axis is a fixed 500-point axis with each tick of the axis equal to an executed Serial.println() command. In other words the plot is updated along the X-axis every time Serial.println() is updated with a new value.

It also has some nice features:

  • Plotting of multiple variables, with different labels and colors for each
  • Can plot both integers and floats
  • Auto-resizes the scale (Y axis)
  • Supports negative value graphs
  • Auto-scrolls the X axis

But to make it work well, there are some tricks in how to format that data. Here’s a complete(?) list:

  • Keep your serial speed low. 9600 is the best for readability. Anything faster than 57600 won’t work.
  • Plot one variable: Just use Serial.println()

Serial.println(variable);

  • Plot more than one variable. Print a comma between variables using Serial.print() and use a Serial.println() for the variable at the end of the list. Each plot will have a different color.
Serial.print(variable1);
Serial.print(",");
Serial.print(variable2);
Serial.print(",");
Serial.println(last_variable); // Use Serial.println() for the last one
  • Plot more than one variable with different labels. The labels will be at the top, in colors matching the relevant lines. Use Serial.print() for each label. You must use a colon (and no space) after the label:
Serial.print("Sensor1:");
Serial.print(variable1);
Serial.print(",");
Serial.print("Sensor2:");
Serial.print(variable2);
Serial.print(",");
Serial.println(last_variable); // Use Serial.println() for the last one

A more efficient way to do that is to send the labels just once, to set up the plot, and then after that you can just send the data:

void setup() {
   // initialize serial communication at 9600 bits per second:
   Serial.begin(9600);
   Serial.println("var1:,var2:,var3:");
 }
void loop() {
   // read the input on analog pin 0:
   int sensorValue1 = analogRead(A1);
   int sensorValue2 = analogRead(A2);
   int sensorValue3 = analogRead(A3);
   // print out the value you read:
   Serial.print(sensorValue1);
   Serial.print(",");
   Serial.print(sensorValue2);
   Serial.print(",");
   Serial.println(sensorValue3);
   delay(1);        // delay in between reads for stability
 }
  • Add a ‘min’ and ‘max’ line so that you can stop the plotter from auto scaling (Thanks to Stephen in the comments for this):
Serial.println("Min:0,Max:1023");
  • Or if you have multiple variables to plot, and want to give them their own space:
Serial.print("Min:0,");
Serial.print("Sensor1:");
Serial.print(map(variable1,0,1023,0,100));
Serial.print(",");
Serial.print("Sensor2:");
Serial.print(map(variable2,0,1023,100,200));
Serial.print(",");
Serial.print("Sensor3:");
Serial.print(map(variable3,0,1023,200,300));
Serial.print(",");
Serial.println("Max:300");

Of course, now the numbers on the y-axis don’t mean much, but you can still see the waveforms.

Written by 

19 thoughts on “Arduino Serial Plotter: The Missing Manual”

  1. Thanks for the article. I was trying to find out how to add the labels and your article helped me out.

    A few other things that I have found useful:

    Add a ‘min’ and ‘max’ line so that you can stop the plotter from auto scaling:
    Serial.println(“Min:0,Max:1023”);

    Or if you have multiple variables to plot, and want to give them their own space:
    Serial.print(“Min:0,”);
    Serial.print(“Sensor1:”);
    Serial.print(map(variable1,0,1023,0,100));
    Serial.print(“,”);
    Serial.print(“Sensor2:”);
    Serial.print(map(variable2,0,1023,100,200));
    Serial.print(“,”);
    Serial.print(“Sensor3:”);
    Serial.print(map(variable3,0,1023,200,300));
    Serial.print(“,”);
    Serial.println(“Max:300”);

    Of course, now the numbers on the y-axis don’t mean much, but you can still see the waveforms.

    1. Sorry, I don’t see how this stops the auto scrolling of the x-axis. For me, it only provided each plotted data value its own space. Which is useful, but they scroll out of the window to quickly to capture.

  2. I have found that the x-axis (scrolling speed) for the serial plotter can vary between 2 sketches even when analog input that is chosen for plotting is identical for them. Is there a way to control the scroll speed?

    1. The scroll speed is proportional to the plotting rate. The plotting rate is once every time the sketch has called all the variables that are being sent, ending with Serial.println. Basically once per sketch pass in the simplest case. You can make this happen once a minute (plus sketch scan time and interrupt routine for each pass which should be negligible for simple sketches) by adding

      delay(60000);

      after your line containing Serial.println. Naturally, more complex sketches might have to track time instead of using delay.

  3. There’s a bunch of syntax errors in your last code snippets. The directed quotes (“) are invalid, you should use normal quotes (“) instead.

      1. Still there for the `Serial.println(“Min:0,Max:1023”);` code

        Great article though, thanks!

  4. This does not work for me.

    Serial.println(“Min:200,Max:400”);

    The scaling is still the same and the only difference is that now the curves show some kind of high frequency sinus with the that is really not there, but where the amplitude of the sinus corresponds to the actual value for each curve.

  5. No need to send the labels erverytime with the data.
    Just send them once in setup as a comma-sperated string : Serial.println(“var1:,var2:,var3:”)

  6. When using an ESP32, the “Serial.printf ” command is supported, so you can just do something like…
    Serial.printf(“%.2 %.2f %d \n”,myFloat1,myFloat2,myInteger);
    Note that there spaces before the second and third %s in the above line, and the \n is equivalent to println to finish up a record.
    This seems to be faster than mashing together a bunch of Serial.print commands. Haven’t tried to just create a string with the equivalent format for all variables, so you could print with just a Serial.print command.

    Anyone know how many variables can be plotted simultaneously?

  7. Ive been trying to include the values of the plots in the legend. Its working but doubling up the legend marker and maybe the line for each variable. Here’s an example for one variable.
    Serial.print(“,DHTtemp:”);Serial.print(temp);Serial.print(“,”);Serial.print(temp);
    I tried joining the string together but all that float to string conversion got messy. Turns out Serial.print does it all for us.
    So seems we can have the loop updating the legend everytime following the format
    variable name text, value, delimeter, value
    and it updates the legend every loop with the live value up top and plots.

  8. Hi I am having the problem that ive followed this tutorial and two others and i only have one result at a time being plotted. So I have three analogue inputs being read but they are onlt printed on the graph as a change in one input. When on the serial monitor they come up as three seperate values. Do you have any suggestions where i may be going wrong?

  9. My main prob with serial plotter is that it hangs/freezes when when used with analog data. Inserting a sufficient delay to prevent the serial buffer from being overwhelmed can be problematic bc sometimes the nature of the graph makes long delays undesirable.

Leave a Reply

Your email address will not be published. Required fields are marked *