0
0
AutocadHow-ToBeginner · 2 min read

Arduino How to Convert Analog Value to Voltage

To convert an analog value from analogRead() to voltage, use voltage = (analogValue * 5.0) / 1023.0 assuming a 5V reference and 10-bit ADC.
📋

Examples

InputanalogValue = 0
Outputvoltage = 0.0 V
InputanalogValue = 512
Outputvoltage = 2.502 V
InputanalogValue = 1023
Outputvoltage = 5.0 V
🧠

How to Think About It

The Arduino analog input reads a value from 0 to 1023 representing voltages from 0 to the reference voltage (usually 5V). To find the actual voltage, multiply the analog value by the reference voltage and divide by 1023, which is the maximum analog reading.
📐

Algorithm

1
Read the analog value using analogRead()
2
Multiply the analog value by the reference voltage (e.g., 5.0V)
3
Divide the result by 1023 to scale it to voltage
4
Return or print the calculated voltage
💻

Code

arduino
void setup() {
  Serial.begin(9600);
}

void loop() {
  int analogValue = analogRead(A0);
  float voltage = (analogValue * 5.0) / 1023.0;
  Serial.print("Analog Value: ");
  Serial.print(analogValue);
  Serial.print(" -> Voltage: ");
  Serial.print(voltage);
  Serial.println(" V");
  delay(1000);
}
Output
Analog Value: 512 -> Voltage: 2.502 V
🔍

Dry Run

Let's trace analogValue = 512 through the code

1

Read analog value

analogValue = 512

2

Calculate voltage

voltage = (512 * 5.0) / 1023.0 = 2.502

3

Print result

Prints: Analog Value: 512 -> Voltage: 2.502 V

analogValuevoltage
5122.502
💡

Why This Works

Step 1: Analog reading range

The analogRead() function returns a value from 0 to 1023 representing 0V to 5V.

Step 2: Scaling to voltage

Multiplying by 5.0 and dividing by 1023 converts the raw value to the actual voltage.

Step 3: Floating point for precision

Using float ensures the voltage includes decimal points for accuracy.

🔄

Alternative Approaches

Use 3.3V reference voltage
arduino
void loop() {
  int analogValue = analogRead(A0);
  float voltage = (analogValue * 3.3) / 1023.0;
  Serial.print("Voltage: ");
  Serial.println(voltage);
  delay(1000);
}
Use this if your Arduino board uses 3.3V as analog reference instead of 5V.
Use Arduino's internal reference voltage
arduino
void setup() {
  analogReference(INTERNAL);
  Serial.begin(9600);
}
void loop() {
  int analogValue = analogRead(A0);
  float voltage = (analogValue * 1.1) / 1023.0;
  Serial.print("Voltage: ");
  Serial.println(voltage);
  delay(1000);
}
This uses the internal 1.1V reference for more precise low voltage readings.

Complexity: O(1) time, O(1) space

Time Complexity

The conversion uses simple arithmetic operations without loops, so it runs in constant time.

Space Complexity

Only a few variables are used, so the space needed is constant.

Which Approach is Fastest?

All approaches use basic math and run equally fast; differences lie in accuracy depending on reference voltage.

ApproachTimeSpaceBest For
5V ReferenceO(1)O(1)Standard Arduino boards
3.3V ReferenceO(1)O(1)Boards with 3.3V analog reference
Internal 1.1V ReferenceO(1)O(1)Precise low voltage measurements
💡
Always confirm your Arduino's analog reference voltage before converting values to voltage.
⚠️
Forgetting to divide by 1023 and using 1024 instead, which slightly skews the voltage calculation.