How To Visualise Data On The Arduino Serial Plotter

How To Visualise Data On The Arduino Serial Plotter

Introduction

In this tutorial, I will show you how to access and use the serial plotter on an Arduino. By the end of this tutorial, you will be confident in analysing real-time data on Arduino serial plotter.

I will give a step by step guide to open a serial plotter on Arduino IDE, send data to the serial terminal, and plot multiple variables on the serial plotter.

The first part of the article covers the basics of the Arduino serial plotter. Later, I will give you Arduino serial plotter examples.

By the end of this article, You can plot graphs and visualise the variable values better on the serial plotter.

Components Needed To Use Arduino Serial Plotter

Hardware Components

Tool

Software

For simulating analog values, you can use the trim pot.

To learn how to plot multiple data variables on the serial plotter, you only need the Arduino.

> Check out our guide to the Top 12 Best Arduino Online Courses

What is an Arduino Serial Plotter?

Arduino serial plotter helps you visualize the data graphically. You can use an Arduino serial plotter with all of your sketches.

You will print the data to be plotted to the terminal in the same way where you print the data to the console.

Arduino Serial plotter can plot multiple variable values on the same time scale. This means you will be able to analyze and calibrate multiple sensors easily. 

To open the Arduino serial plotter, I just click on Tools in the menu bar and select Serial Plotter!

Follow the steps below to open the Arduino Serial plotter.

open the Arduino Serial plotter

I will show you how to use the serial plotter in the coming section, followed by several examples.

Step-By-Step Instructions To Plot Data On The Arduino Serial Plotter

I will present to you the essential sections of the Serial plotter window.

Below is the Serial Plotter window screenshot where you can see three critical sections.

Serial Plotter window screenshot

You have the details of the serial plotter window in the table below.

Sl. NoElementDescription
1COM portThis is the COM port the Arduino is connected to.
2baud-rateSet the baud rate to match the serial baud rate you have set in the setup() function
3NCThis is the place where the graph will be plotted. You will see it in action in the sections below.

You will find the Arduino serial plotter examples in the coming sections, where you will plot:

  • a triangular wave on the serial plotter
  • a random noise pattern, and 
  • Multiple sinusoidal signals on the same plotter window

Project 1: How To Print A Triangular Wave On The Arduino Serial Plotter

In this step, I will show you how to plot a variable to generate a triangular wave on the serial plotter.

Step 1: Open a new project on Arduino IDE

Open a new project on Arduino IDE

Step 2: Add the below code into your new sketch

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

void loop() {
  for (int n = 0; n <= 100; n = n + 1)
  {	
    Serial.println(n);
    delay(1);
  }
  for (int n = 100; n >= 0; n = n - 1)
  {
    Serial.println(n);
    delay(1);
  }
}

Step 3: Program the Arduino and open the Serial Monitor Window

The COM port is used to exchange the data from the Arduino UNO and the IDE (Serial plotter).

Hence, you need to connect the Arduino UNO with a USB cable to program and then later watch the data on the graph. 

As soon as you open the serial monitor, you can see the graph plotted.

Congratulations!

Ensure that the baud rate matches the baud rate you have defined in the setup() function.

graph plotted

In the serial plotter window, you see that the y axis is set automatically to range up to 100.

The plotter automatically sets this based on the maximum value of the data you have sent to the terminal.

In my code, I have sent the numbers from 1 to 100 and vice versa.

Hence, 100 is the maximum value you see in the y axis (vertical axis).

The X-axis represents the time scale. Every time you print the value to the terminal, the plotter updates.

The time scale depends on the rate at which you print the values to the terminal.

The total number of samples you can see at once on the Arduino serial plotter is 500. 

Did you know that you can change the color settings of the serial plotter easily?

You will find this information at the end of the article.

Project 2: How To Visualise Random Data On The Arduino Serial Monitor?

I will plot the random values on the serial plotter in this step.

Step 1: Program the Arduino with the random value generation code

The Arduino code for visualising random variable values is given below. Copy and paste the below code into a new sketch and program the board.

long randNumber;

void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(0));
}

void loop() {
  // print a random number from 0 to 299
  randNumber = random(300);
  Serial.println(randNumber);
  delay(50);
}

Step 2: Open the Serial plotter window

You will see the below window on the Serial monitor.

Open the Serial plotter window

I am sure you can use the same method to print values from different sensors.

You can use this feature to visualise, compare and calibrate various sensors simultaneously.

Project 3: How To Plot Multiple Graphs On the Arduino Serial Monitor

In the previous sections, I showed you how to plot a single variable at a time. It will be beneficial in specific scenarios to plot multiple values simultaneously.

For example, I can measure data from two similar sensors and compare the performance of each other.

You cna also use this to monitor the analog input versus a digital output (temperature monitoring thermostat application, for example).

To plot multiple variables, you have to send the variables to the terminal, but with a slight change in the method you use.

Instead of using the Serial.println command, you have to use just the serial.print command to send the variable value to the terminal.

Step 1: Important steps to plot multiple values on the Arduino Serial Monitor

I will share the steps below:

  1. Use Serial.print(data1) to send the first data to terminal
  2. Provide a “tab” Either you can use serial.print(“\t”) or Serial.print(“ “)
  3. Send the second data to be plotted to the terminal using Serial.print(data2)
  4. Provide a “tab” Either you can use serial.print(“\t”) or Serial.print(“ ”) or Serial.print(“,”)
  5. Repeat the process for all the variables except the last data
  6. Send the last data to the terminal using Serial.println()

Step 2: Example of plotting three variables on the Arduino serial plotter

In this example, you will plot three variables. You will print three sinusoidal signals.

Here is the complete sketch. Serial.println() is only used for the last variable.

This is the Critical point in plotting multiple data on the serial plotter.

In the upcoming sketch example, I have used both “\t” and “ ” to tell the plotter that we are now sending the subsequent data to plot.

You can also mention the name of the data variables you plot by printing the name strings, as in the example below.

Step 3: Arduino Code for plotting multiple variables on Arduino Serial plotter

Copy the code below into an empty Arduino sketch. Connect the Arduino UNO to the PC and program it. To visualise the data, Open the Serial Plotter window.

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

void loop() {
  for (int j = 0; j < 360; j=j+2) {
    Serial.print("data1:");
    Serial.print(sin(j * (PI / 180)));
    Serial.print("\t");

    Serial.print("data2:");
    Serial.print(cos(j * (PI / 180)));
    Serial.print(",");

    Serial.print("data3:");
    Serial.println(4*cos(j * (PI / 180)));
  }
}

Step 4: The plot of three variables on the Arduino serial plotter

The output of the Serial plotter window is shown below. As you can see, The three variables which you transmitted using the print commands are marked (data1, data2, data3)

The plot of three variables on the Arduino serial plotter

-> Read our guide about What You Can Build with Adruino.

FAQ’s About The Arduino Serial Plotter

In this section, you will find answers to the most frequent questions on the Serial plotter.

1) What does Arduino Serial plotter do?

Arduino Serial plotter generates graphs based on the data sent to the terminal.

You can use Arduino Plotter to visualise data from sensors, analog inputs, equations and much more. 

For Example, if you want to decide the noise threshold for incoming sensor data, you can quickly fix it by looking at the plot.

You can also use the plotter to get visual feedback while tuning any sensors.

2) Where is the serial plotter in Arduino Serial?

You can locate the Serial plotter in the Arduino IDE quickly. To open the serial plotter on the Arduino, follow the below steps:

  1. Connect the Arduino to your PC using a USB cable
  2. Open Arduino IDE
  3. Go To “Tools” in the Menu bar
  4. Select “Serial Plotter

3) How do I print multiple lines on the Arduino plotter?

To print multiple lines on the Arduino serial plotter, here is the short summary:

  1. Print the data without a new line (Serail.print)
  2. Provide a tab or a space between the two data
  3. Print the final variable with a new line (Serial.Println).

4) What is the Y-axis on the serial plotter?

Y-axis in the Arduino Serail plotter represents the “value” of the data you transmit.

For example, if you send ADC counts to the serial plotter, you will see the Counts in the Y-axis.

The X-axis on the serial plotter represents the time. Every time you send data to the plotter, the X-axis count increments by one.

Hence the time axis between two sample points depends on the rate at which you send the data onto the terminal.

4) How do I get my graph on the Arduino Serial plotter?

To get the plot on the serial monitor, you have to print the data serial terminal.

Next, you have to open the Serial plotter window (available under the “Tools” menu).

If you want to plot multiple plots in the same graph, follow the steps defined in the article above.

5) Is it possible to change colours in the Arduino Serail plotter?

Yes, You can change the colours of the graphs in the serial plotter. You can also update the colour of the background, grid as well. 

Follow the step below to change the colours to your preferences:

1. Open the following folder: {Arduino IDE installation folder}/lib/theme

2. Open the file theme.txt in a text editor

3. Search for “plotting” you will find lines similar to this

Search for plotting

4. Change the colours to your preference. The colours are in RBG hex format.

If you have any doubts, please feel free to leave a comment. I will be glad to help.

Conclusion

In this article, I covered the basics of Arduino serial plotter with examples of both single and multiple graphs.

I have also shown how to provide the labels for the plots too. This will help in your upcoming projects where you can calibrate or visualise the sensor data or the trim potentiometer values in the future.

I have used the serial plotter to monitor the Light Dependent resistor, temperature sensor, and more.

I will be glad to know how well you will use the serial plotter in your upcoming Arduino projects.

I would love to hear from you.

Did you find this article beneficial? Do you have any feedback to make this article more helpful?

Please reply in the comments. I will be glad to respond to all your comments.

Feel free to share the projects you built using Serial Monitor. I will be excited to know more about it.

Now it is your turn to suggest a topic you would like to learn about next!

Don’t forget to share the article with your friends!