Skip to content

Commit 13202e4

Browse files
committed
Added ReadAnalogVoltage example
1 parent 8284571 commit 13202e4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
ReadAnalogVoltage
3+
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
4+
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
5+
6+
This example code is in the public domain.
7+
*/
8+
9+
// the setup routine runs once when you press reset:
10+
void setup() {
11+
// initialize serial communication at 9600 bits per second:
12+
Serial.begin(9600);
13+
}
14+
15+
// the loop routine runs over and over again forever:
16+
void loop() {
17+
// read the input on analog pin 0:
18+
int sensorValue = analogRead(A0);
19+
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
20+
float voltage = sensorValue * (5.0 / 1023.0);
21+
// print out the value you read:
22+
Serial.println(voltage);
23+
}

0 commit comments

Comments
 (0)