ESP32 - Serial Plotter

Hardware Required

1×ESP-WROOM-32 Dev Module
1×Micro USB Cable
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

About Serial Plotter

Serial Plotter is one of the tools in Arduino IDE. ESP32 can read the temperature, humidity or any kind of sensor data, and send it to Serial Plotter. Serial Plotter receives data from ESP32 and visualizes data as waveforms. Serial Plotter can visualize not only single but also multiple sensor data in the same graph.

Data is exchanged between Serial Plotter and ESP32 via USB cable, which is also used to upload the code to ESP32. Therefore, To use Serial Plotter, we MUST connect ESP32 and PC via this cable.

Serial Plotter includes a selection box to select the serial baud rate and a graph:

  • X-axis: represent the time. It has 500 points. The time between each point is the time between two consecutive Serial.println() function calls. This time is usually equal to the time of loop() function.
  • Y-axis: represents the values received from ESP32. The Y-axis automatically adjusts itself as the value increases or decreases.

How To Open Serial Plotter

On Arduino IDE, Go to Tools Serial Plotter

how to open serial plotter

Plotting of Single Line in Graph

To print a single graph, we just need to send the data and terminate it by “\r\n” character.

In detail, we just need to use Serial.println() function

Serial.println(variable);

※ NOTE THAT:

Serial.println() automatically appends “\r\n” characters after data.

Example Code

This example reads the value from an analog input pin and plots them on Serial Plotter

/* * Created by esp32io.com * * This example code is in the public domain * * Tutorial page: https://esp32io.com/tutorials/esp32-serial-plotter */ void setup() { Serial.begin(9600); } void loop() { int y1 = analogRead(A0); Serial.println(y1); delay(100); }

Quick Steps

  • If this is the first time you use ESP32, see how to setup environment for ESP32 on Arduino IDE
  • Copy the above code and paste it to Arduino IDE
  • Click Upload button on Arduino IDE to compile and upload code to ESP32 board
  • Open Serial Plotter
  • Select baurate 9600
  • See graph on Serial Plotter
  • serial plotter example single line

Plotting of Multiple Lines in Graph

When we want to plot multiple variables, we need to separate variables from each other by “\t” or " " character. The last value MUST be terminated by “\r\n” characters.

In detail:

  • The first variable
Serial.print(variable_first);
  • The middle variables
Serial.print("\t"); // or Serial.print(" ") Serial.print(variable_nth);
  • The last variable
Serial.print("\t"); // or Serial.print(" ") Serial.println(variable_last);

Example Code

This example reads the value from 4 analog input pins and plots them on Serial Plotter

/* * Created by esp32io.com * * This example code is in the public domain * * Tutorial page: https://esp32io.com/tutorials/esp32-serial-plotter */ void setup() { Serial.begin(9600); } void loop() { int y1 = analogRead(A0); int y2 = analogRead(A1); int y3 = analogRead(A2); int y4 = analogRead(A3); Serial.print(y1); Serial.print(" "); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y2); Serial.print(" "); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y3); Serial.print(" "); // a space ' ' or tab '\t' character is printed between the two values. Serial.println(y4); // the last value is followed by a carriage return and a newline characters. delay(100); }

Multiple Graph:

serial plotter example multiple lines

Example of 3 Sine Waveforms

/* * Created by esp32io.com * * This example code is in the public domain * * Tutorial page: https://esp32io.com/tutorials/esp32-serial-plotter */ void setup() { Serial.begin(9600); } void loop() { for(int i = 0; i < 360; i += 5) { float y1 = 1 * sin(i * M_PI / 180); float y2 = 2 * sin((i + 90)* M_PI / 180); float y3 = 5 * sin((i + 180)* M_PI / 180); Serial.print(y1); Serial.print("\t"); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y2); Serial.print("\t"); // a space ' ' or tab '\t' character is printed between the two values. Serial.println(y3); // the last value is followed by a carriage return and a newline characters. delay(100); } }

Multiple Sine Waveform Graph:

serial plotter sine wave

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

※ NOTE THAT:

Note that this tutorial is incomplete. We will post on our Facebook Page when the tutorial is complete. Like it to get updated.

※ NOTICES

  • We are AVAILABLE for HIRE. See how to hire us to do your project
  • If this tutorial is useful for you, please support us to make more tutorials.
  • We spent a lot of time and effort to create the content for this tutorial, please respect our work! Please do not copy the content to share on other websites. Howerver, please feel free to share the link of this tutorial anywhere