Using Vernier Analog (BTA) Sensors with Arduino

The majority of Vernier sensors are analog sensors. They typically operate on a 5 volt input, and output a voltage between 0 and 5 volts. The following sections explain how to use standard Vernier analog (BTA) sensors with Arduino microcontrollers.

Reading Analog Sensor Data Using Auto-ID

One of the best features about Vernier sensors is that they have a built-in autoID capability. You can automatically detect which sensor you are using and read a data point with just two simple commands.


The Vernier.autoID() function is placed in the setup() portion of your sketch. This function checks for a standard analog (BTA) sensor connected to the Analog 1 port on the Vernier Arduino Interface Shield or an Analog Protoboard Adapter wired to Arduino pin A0 as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section. (Note the VernierLib library does not support sensors plugged into the Analog 2 port on the Vernier Arduino Interface Shield or a second Analog Protoboard Adapter. To collect data from a second sensor you will need to manually calibrate raw voltage readings as described in Reading Raw Voltage.)

If a sensor is found in the Analog 1 port, it will read information about it, including:

  • sensorName – the full name of the sensor found in the catalog
  • shortName – an abbreviated name often used for labeling columns in data tables
  • sensorUnits – a standard metric measurement
  • sensorNumber – the product identifier
  • calEquationType – the type of equation used for calibration. For most sensors,
  • calEquationType = 1, indicating a linear calibration. A few sensors, such as temperature, require a more complex calibration equation.
  • slope – a linear calibration variable
  • intercept – a linear calibration variable
  • cFactor – a variable used in nonlinear calibrations
  • voltageID – the voltage read from sensors with built-in resistors
  • page – the calibration information stored in sensors with memory chips

To access information about the sensor, you would use a statement like:

Serial.print (Vernier.sensorName());

This statement will print the full name of the sensor on the Serial Monitor. The Serial Monitor is a popup window that allows you to see data sent to and from your Arduino. You can access the Serial Monitor from the Tools menu.

The Vernier.readSensor() function will read one data point from the sensor connected to the Analog 1 port. To continuously read data from the sensor, you should put the function in the loop() portion of your sketch. The sample sketch, VernierLibTutorialAnalogRead, will take sensor readings every half second and print the data with units to the Serial Monitor. You can try out different sensors simply by plugging in a new sensor and pressing the Reset button.

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: Adding this line will cause the graph to fill in with solid color. Eliminating this line will produce a simple line graph.
    1. /* VernierLibTutorialAnalogGraph (v2017)
    1. * This sketch reads a data point from a Vernier Analog (BTA)
    1. * sensor once every half second and graphs the sensor data
    1. * to the Serial Plotter.
    1. *
    1. * Plug the sensor into the Analog 1 port on the Vernier Arduino
    1. * Interface Shield or into an Analog Protoboard Adapter wired
    1. * to Arduino pin A0. Open the Serial Plotter from the Tools
    1. * menu.
    1. */
    1. #include “VernierLib.h” //include Vernier functions in this sketch
    1. VernierLib Vernier; //create an instance of the VernierLib library
    1. float sensorReading; //create global variable to store sensor reading
    1. void setup() {
    1. Serial.begin(9600); //setup communication to display
    1. Vernier.autoID(); //identify the sensor being used
    1. }
    1. void loop() {
    1. sensorReading = Vernier.readSensor(); //read one data value
    1. Serial.println(sensorReading); //graph data point
    1. Serial.println(0); //optional command to create a filled-in plot
    1. delay(500); //wait half second
    1. }