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
- Arduino Uno Rev3 x 1
- Trim potentiometer x 1
- Dupont wire x 3
- Arduino USB cable (for powering and programming) x 1
- Breadboard x 1
Tool
- Screwdriver (to turn the trim potentiometer) x 1
Software
Makerguides.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to products on Amazon.com. As an Amazon Associate we earn from qualifying purchases.
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.
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.
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.
You have the details of the serial plotter window in the table below.
Sl. No | Element | Description |
1 | COM port | This is the COM port the Arduino is connected to. |
2 | baud-rate | Set the baud rate to match the serial baud rate you have set in the setup() function |
3 | NC | This 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.
Open a new project on Arduino IDE
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); } }
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.
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.
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:
- Use Serial.print(data1) to send the first data to terminal
- Provide a “tab” Either you can use serial.print(“\t”) or Serial.print(“ “)
- Send the second data to be plotted to the terminal using Serial.print(data2)
- Provide a “tab” Either you can use serial.print(“\t”) or Serial.print(“ ”) or Serial.print(“,”)
- Repeat the process for all the variables except the last data
- 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)
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:
- Connect the Arduino to your PC using a USB cable
- Open Arduino IDE
- Go To “Tools” in the Menu bar
- 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:
- Print the data without a new line (Serail.print)
- Provide a tab or a space between the two data
- 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 Serial 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
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 am Puneeth. I love tinkering with open-source projects, Arduino, ESP32, Pi and more. I have worked with many different Arduino boards and currently I am exploring, Arduino powered LoRa, Power line communication and IoT.
성인망가
Thursday 26th of January 2023
Hello there! I simply wish to give you a huge thumbs up for the great info you have got right here on this post "성인망가"Does running a blog like this take a large attention-grabbing discussion is worth comment. It’s difficult to find knowledgeable people using the same blog platform.