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:
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.