arduino-serial-plotter

Easily Create Graphs in Arduino IDE with Serial Plotter

  • 3 min

We have already learned to use the Serial Monitor to debug our programs. We fill the code with Serial.println(variable) and watch a cascade of numbers fly by at full speed.

But let’s be honest, sometimes seeing a giant list of numbers at 9600 baud doesn’t help much to visualize how a sensor or a PID control is actually behaving.

This is where the Serial Plotter comes in, a tool integrated into the Arduino IDE that turns numbers into real-time graphs.

The Serial Plotter is a native IDE tool that allows you to visually graph data received from the serial port.

Don’t expect it to be MATLAB or a professional analysis tool. It’s simple, basic, and straightforward. But precisely that simplicity is its greatest virtue: there’s nothing to install, nothing to configure.

Where is the Serial Plotter?

You’ll find it in the Tools menu, just below the Serial Monitor. Or, if you’re a keyboard shortcut person like me, by pressing Ctrl+Shift+L.

When you open it, you’ll see a window with an X-axis (time) and a Y-axis (value). The plotter auto-scales vertically to fit the values it receives.

Plotting a Single Variable

To use the Serial Plotter, we only need to send numbers over the serial port ending with a newline. That is, use Serial.println().

Let’s look at a classic example. Instead of random noise, let’s generate a sine wave. It’s the “Hello World” of graphs because it lets us see if the signal is smooth.

void setup() {
  Serial.begin(9600);
}

void loop() {
  // Generate a simulated sine wave
  // Use millis() to advance in time
  float angle = millis() / 1000.0;
  float value = sin(angle) * 100.0;

  Serial.println(value);

  delay(10); // A small pause to avoid saturating
}
Copied!

If you load this code and open the Plotter, you’ll see a perfect wave being drawn on the screen.

Make sure the speed (baud rate) selected in the Plotter (bottom right) matches the one in your Serial.begin(). Otherwise, you’ll see garbage or nothing.

Plotting Multiple Variables

This is where the Serial Plotter becomes really useful. What if we want to compare temperature vs. humidity? Or the “Setpoint” vs. the actual sensor value?

To draw several lines at once, the trick is in the sending format. We must send the values on the same line, separated by commas or spaces, and end with a newline.

The structure is:

Value1 + space/comma + Value2 + Newline

Let’s see it in code. We’ll generate two out-of-phase waves (Sine and Cosine) to see how they are drawn simultaneously:

void setup() {
  Serial.begin(9600);
}

void loop() {
  float time = millis() / 1000.0;

  float variable1 = sin(time) * 100.0;
  float variable2 = cos(time) * 100.0;

  // Send the first variable
  Serial.print(variable1);

  // Send the separator (comma or space)
  Serial.print(",");

  // Send the second variable and the final NEWLINE
  Serial.println(variable2);

  delay(10);
}
Copied!

When you open the Plotter now, you will see two lines of different colors. You will also see a legend at the top identifying each color.

Naming Variables

You can even name the series so they appear in the legend by sending the format Label:Value.

  Serial.print("Sine:");
  Serial.print(variable1);
  Serial.print(",");
  Serial.print("Cosine:");
  Serial.println(variable2);
Copied!

This is super useful when you’re debugging 4 or 5 variables at once and you no longer know which is the blue line and which is the red one.

Use it whenever you work with analog sensors. Your eyes will detect anomalies in a graph much sooner than your brain will in a list of numbers.