Serial Plotting

In addition to sending human readable text messages over your Arduino’s serial communications you can also send and plot numeric data. In this very short tutorial we’ll learn to leverage this and use our Arduino to plot sin(x).

A sin wave plotted in the Arduino serial plotter

We can open the serial plotter via the Arduino context menu under Tools -> Serial Plotter. The serial plotter expects numeric values to be printed to the serial monitor seperated by new lines. For example, if we wrote a program to print

1
2
3
4
...
N

to the serial monitor the serial plotter would plot y = x + 1 on the screen.

For our example let’s plot sin(x). The code to do this is quite straightforward so I’ll just reproduce it below:

float x = 0.0;

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

void loop() {
  float y = sin(x);
  x += 0.05;
  Serial.print(y);
  Serial.print("\n");
}

If you upload this to your Arduino and open the serial plotter you’ll see sin(x) being plotted on the screen.

Next steps

  1. Consider reading this guide to learn about plotting more than one line at a time.
  2. Can you use the serial plotter to communicate information about the state of your Arduino? For example: