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

Controlling a Digital Line with Sensor Input

The Arduino contains a number of digital lines that can be used for controlling electronic devices, such as lights, buzzers, and motors. We designed the Vernier Arduino Interface Shield to include a blue LED connected to digital line 13 on the Arduino. You can use this LED as an output device (for example, a threshold indicator) in your projects. To access digital line 13 on the Arduino, you would put this statement in the setup portion of your sketch:


To turn the LED on or off, use statements like:

digitalWrite(13, HIGH); //turns the LED on digitalWrite(13, LOW); //turns the LED off

The sample sketch, VernierLibTutorialAnalogThreshold, will take sensor readings every half second and turn on the blue LED if the reading exceeds a threshold value. For example, if you have a Vernier Dual-Range Force Sensor plugged into the Analog 1 port, the blue LED will light up if the applied force exceeds 5 newtons. Note that this sketch will also work with an Analog Protoboard Adapter since the Arduino itself has an onboard LED wired to digital line D13.

/* VernierLibDemoAnalogThreshold (v2017)
 * This sketch reads a data point from a Vernier Analog (BTA) 
 * sensor and turns on an LED (pin D13) if the sensor reading
 * exceeds a threshold value.
 * 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.

#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
float threshold=5; //set threshold value for sensor
void setup() {
  Vernier.autoID(); //identify sensor being used
  pinMode(13,OUTPUT); //setup digital line 13 for output

void loop() {
  sensorReading = Vernier.readSensor(); //read one data value
  if (sensorReading > threshold) //check if threshold exceeded
    digitalWrite(13,HIGH); //turn LED on
    digitalWrite(13,LOW); //turn LED off
  delay(500); //wait half second



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