Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reading an analog voltage
void setup()
// Initialise my serial port with 9600 baud
void loop()
// Analog values are read as integer values between 1 and 1023.
// Each 1 is a fraction of 5V. So 0 = 0V, 1023 = 5V, and the scale
// goes in-between.
const float VOLTAGE_MULTIPLIER = (5.0 / 1023.0);
// Read the analog value on pin A0 (as fractions of 5V).
int sensorValue = analogRead(A0);
// Convert to volts using our multiplier.
float sensorVoltage = sensorValue * VOLTAGE_MULTIPLIER;
// Write the current voltage to the Serial port.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment