Arduino Nano - Serial Plotter

Hardware Preparation

1×Arduino Nano
1×USB A to Mini-B USB cable
1×(Optional) 9V Power Adapter for Arduino Nano
1×(Recommended) Screw Terminal Adapter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you. We appreciate your support.

Overview of Serial Plotter

Serial Plotter is a feature of the Arduino IDE. It allows Arduino Nano to read data from temperature, humidity or any other type of sensor and transmit it to Serial Plotter. Serial Plotter will then take this data and display it as a waveform. It can even show multiple sensor readings in the same graph.

Data is exchanged between Serial Plotter and Arduino Nano through a USB cable. This same cable is used to upload code to Arduino Nano. Consequently, in order to use Serial Plotter, it is necessary to connect Arduino Nano and PC with this cable.

Serial Plotter has a selection box to pick the serial baud rate and a graph. The X-axis of the graph shows the time, with 500 points. The time between each point is equivalent to the time between two consecutive Serial.println() function calls, which is usually the same as the loop() function. The Y-axis displays the values received from Arduino Nano, and adjusts itself automatically when the value increases or decreases.

How To Open Serial Plotter

Click the Serial Plotter icon on the right side of Arduino IDE.

how to open serial plotter

Plotting of Single Line in Graph

To generate a single graph, we need to send the data and end it with the “\r\n” character.

Specifically, we need to use the Serial.println() function.

Serial.println(variable);

※ NOTE THAT:

Serial.println() adds “\r\n” characters to the end of data.

Example Code

Take the value from an analog input pin and plot it on Serial Plotter. This is an example of doing so.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-serial-plotter */ void setup() { Serial.begin(9600); } void loop() { int y1 = analogRead(A0); Serial.println(y1); delay(100); }

Detailed Instructions

  • Copy the code and open it with the Arduino IDE.
  • Click the Upload button on the Arduino IDE to compile and upload the code to the Arduino Nano.
  • Open the Serial Plotter.
  • Set the baurate to 9600.
  • View the graph on the Serial Plotter.
serial plotter example single line

Plotting of Multiple Lines in Graph

If we wish to plot multiple variables, we must separate them from one another with either a “\t” or " " character. The final value MUST be ended with “\r\n” characters.

  • Printing the first variable:
Serial.print(variable_first);
  • Printing the variables in the middle:
Serial.print("\t"); // or Serial.print(" ") Serial.print(variable_nth);
  • Printing the final variable:
Serial.print("\t"); // or Serial.print(" ") Serial.println(variable_last);

Example Code

Take the value from four analog input pins and display them on the Serial Plotter.

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-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); }

Using Multiple Graphs:. Creating multiple graphs to display data.

serial plotter example multiple lines

Example of 3 Sine Waveforms

/* * This Arduino Nano code was developed by newbiely.com * * This Arduino Nano code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano/arduino-nano-serial-plotter */ void setup() { Serial.begin(9600); } void loop() { for(int i = 0; i < 360; i += 15) { 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); } }

Graph of Multiple Sine Waves:. This graph displays multiple sine waves.

serial plotter sine wave

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!