Calibrating Sensors with Linear Calibrations
Fortunately, the vast majority of standard Vernier analog (BTA) sensors have linear calibrations. For these sensors, you need to convert from a raw voltage (described in the previous section) to the sensor value using the following equation:
sensorValue = slope * voltage + slope
You can get the slope and intercept for Vernier sensors with a linear calibration from the sensor’s User Manual. You can download user manuals from any sensor’s web page or from the Vernier Support section of the website.
In the sensor’s User Manual, you will find a section called Specifications that lists the Stored Calibrations (slopes and intercepts) for that sensor. For example, the User Manual for the Vernier Dual-Range Force Sensor ±10N range lists:
Stored calibration
- slope: -4.9 N/volt
- intercept: 12.25 N
To convert Arduino voltages to forces in newtons, you would need to add variables for the slope and intercept, as well as the calibration equation. The sample sketch, VernierTutorialLinearCalibration, will read the raw count from a Vernier Dual-Range Force Sensor once every half second, convert it to a voltage, and then convert it to a sensor value. This sketch assumes the sensor is plugged into the Analog 2 port on the Vernier Arduino Interface Shield or connected to an Analog Protoboard Adapter wired to Arduino pin A2 as explained in the Connecting Vernier Sensors to the Arduino Using a Breadboard section.
/* VernierTutorialLinearCalibration (v2017) * This sketch reads the raw count from a Vernier Analog (BTA) * sensor once every half second, and uses its algebraic slope * and intercept to convert it to standard units. * * Plug the sensor into the Analog 2 port on the Vernier Arduino * Interface Shield or into an Analog Protoboard Adapter wired * to Arduino pin A2. */ float rawCount; //create global variable for reading from A/D converter (0-1023) float voltage; //create global variable for voltage (0-5V) float sensorValue; //create global variable for sensor value float slope = -4.9; //create global variable for slope for a Dual-Range Force Sensor +/-10N range float intercept = 12.25; //create global variable for intercept for a Dual-Range Force Sensor +/-10N range char units = "N"; //create global variable for units for a Dual-Range Force Sensor void setup() { Serial.begin(9600); //setup communication to display } void loop() { rawCount=analogRead(A2); //read one data value (0-1023) voltage=rawCount/1023*5; //convert raw count to voltage (0-5V) sensorValue=slope*voltage+intercept; //convert to sensor value with linear calibration equation Serial.print(sensorValue); //print sensor value Serial.println(units); //print units and skip to next line delay(500); //wait half second }
Previous
Reading Raw VoltageContents
Introduction- Arduino Terminology
- About Vernier Sensors: Analog (BTA) and Digital (BTD)
- Connecting Vernier Sensors to Arduino
- Using the VernierLib Library
- Using Vernier Analog (BTA) Sensors with Arduino
- Using Vernier Digital (BTD) Sensors with Arduino
- Using the Vernier Digital Control Unit (DCU) with Arduino
- Using Motors with Arduino
- Calibrating Vernier Analog Sensors
- Importing Data into Graphical Analysis 4
- Importing Data into Logger Pro®
- Projects and Ideas
- Turn on a Buzzer Based on a Motion Detector Reading
- Produce a Tone Out that Depends on Sensor Reading
- Controlling a RGB LED with a 3-Axis Accelerometer
- Controlling a Mousetrap with a Photogate
- Laser Pointer Controlled by a Motion Detector
- Add a Display For Temperature Readings
- Auto-ID for Analog (BTA) Sensors
- Auto-ID for Digital (BTD) Sensors
- Auto-ID for Analog (BTA) Sensors with Display
- Pendulum Driver
- Levitating Ping Pong Ball
- DCU-Controlled Birthday Candle
Vernier Engineering Contest
Vernier recognizes instructors for creative uses of Vernier sensors to introduce engineering concepts and/or practices. Vernier Engineering Award »