Vernier Software and Technology
Vernier Software & Technology
Arduino and Vernier Sensors

Graphing Sensor Data

In the previous section, we described how to display data on the Serial Monitor. The same sketch can be used to graph data on the Serial Plotter. The Serial Plotter is a Tool that comes pre-installed with the Arduino IDE. When the Serial Plotter is open, print commands will plot sensor data on the vertical Y axis. The scale automatically adjusts to fit your data. Note you cannot have the Serial Monitor and the Serial Plotter open at the same time.

The sample sketch, VernierLibTutorialAnalogGraph, will take sensor readings every half second and graph them to the Serial Plotter. Notice the optional command

Serial.println(0);

Adding this line will cause the graph to fill in with solid color. Eliminating this line will produce a simple line graph.

Graph fill options
/* VernierLibTutorialAnalogGraph (v2017)
 * This sketch reads a data point from a Vernier Analog (BTA) 
 * sensor once every half second and graphs the sensor data 
 * to the Serial Plotter.
 * 
 * Plug the sensor into the Analog 1 port on the Vernier Arduino 
 * Interface Shield or into an Analog Protoboard Adapter wired 
 * to Arduino pin A0. Open the Serial Plotter from the Tools
 * menu.
 */

#include "VernierLib.h" //include Vernier functions in this sketch
VernierLib Vernier; //create an instance of the VernierLib library

float sensorReading; //create global variable to store sensor reading
 
void setup() {
  Serial.begin(9600); //setup communication to display
  Vernier.autoID(); //identify the sensor being used
}

void loop() {
  sensorReading = Vernier.readSensor(); //read one data value
  Serial.println(sensorReading); //graph data point 
  Serial.println(0); //optional command to create a filled-in plot
  delay(500); //wait half second
}


Contents

Introduction

Vernier Engineering Contest

Vernier recognizes instructors for creative uses of Vernier sensors to introduce engineering concepts and/or practices. Vernier Engineering Award »

Go to top