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

Reading Raw Voltage

Arduinos have a built-in 10-bit analog-to-digital converter to read voltages. The voltage is read as a count in the range of 0 to 1023 with 0 representing 0 volts and 1023 representing 5 volts.

The sample sketch, VernierTutorialAnalogVoltage, will read the raw count from a Vernier analog sensor once every half second and convert it to a voltage 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.

/* VernierTutorialAnalogVoltage (v2017)
 * This sketch reads the raw count from a Vernier Analog (BTA) 
 * sensor once every half second, converts it to a voltage, 
 * and prints both values to the Serial Monitor.
 * 
 * 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)
 
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)
  Serial.print(rawCount); //print raw count 
  Serial.print("\t"); //print a tab character
  Serial.println(voltage); //print voltage and skip to next line
  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