VoltageTest.ino (908B)
1 /* 2 ReadAnalogVoltage 3 4 Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor. 5 Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). 6 Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. 7 8 This example code is in the public domain. 9 10 http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage 11 */ 12 13 // the setup routine runs once when you press reset: 14 void setup() { 15 // initialize serial communication at 9600 bits per second: 16 Serial.begin(9600); 17 } 18 19 // the loop routine runs over and over again forever: 20 void loop() { 21 // read the input on analog pin 0: 22 int sensorValue = analogRead(A0); 23 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): 24 float voltage = sensorValue * (5.0 / 1023.0); 25 // print out the value you read: 26 Serial.println(voltage); 27 }