Sub topic 3
Reference Voltage and Converting Readings to Volts
Assume you know the basic Arduino sketch structure, can upload a sketch, and understand voltage, ground, and breadboard connections. This chapter focuses on how analogRead() represents voltage and how to convert its result into volts.
What the reference voltage means
An Arduino analog-to-digital converter (ADC) measures an input voltage by comparing it with a reference voltage. The reference voltage is the highest voltage that the ADC can represent as its maximum reading.
On an Arduino Uno, the default reference is usually AVcc, which is close to the board's supply voltage. With a 5 V Uno, the reference is normally about 5 V. The ADC returns a number from 0 to 1023 because the Uno has a 10-bit ADC.
- A reading of
0represents approximately 0 V. - A reading of
1023represents approximately the reference voltage. - Readings between them represent voltages between those limits.
The reference voltage is not automatically a perfect 5.000 V. USB power, the board's regulator, wiring, and electrical noise can change it. Therefore, a conversion that assumes exactly 5 V is an estimate unless you measure the actual reference voltage.
ADC resolution and volts per step
A 10-bit ADC has:
2^10 = 1024possible codes, numbered from 0 through 1023. The voltage represented by one code step is approximately:
volts per step = Vref / (2^N - 1)For a 10-bit ADC with a 5 V reference:
volts per step = 5.0 / 1023
≈ 0.00489 V
≈ 4.89 mVThe conversion formula is:
voltage = raw reading × Vref / maximum ADC readingFor example, a raw reading of 512 on a 5 V, 10-bit system gives:
voltage = 512 × 5.0 / 1023
≈ 2.50 VThe ADC rounds the continuous input voltage to the nearest available code. This process is called quantization. A small change in input voltage might not change the reading if it remains within the same code range.
Convert a reading in an Arduino sketch
This sketch prints both the raw ADC code and an estimated voltage:
const int POT_PIN = A0;
const float REFERENCE_VOLTAGE = 5.0;
const int ADC_MAX = 1023;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN);
float volts = raw * (REFERENCE_VOLTAGE / ADC_MAX);
Serial.print("raw=");
Serial.print(raw);
Serial.print(" volts=");
Serial.println(volts, 2);
delay(100);
}Open the Serial Monitor at 9600 baud. Turn the potentiometer slowly. The raw value should move from near 0 to near 1023, while the voltage moves from near 0 V to near 5 V.
The expression uses floating-point constants. Writing 5.0 instead of 5 ensures that the calculation keeps its fractional part. The final 2 in Serial.println(volts, 2) displays two digits after the decimal point.
Reference choices and board differences
Some boards let you select a different reference with analogReference(). A lower reference improves resolution for low-voltage signals, but an input above that reference can produce incorrect readings or damage the input, depending on the board and configuration.
On an Uno, the internal reference is approximately 1.1 V, not exactly 1.100 V. The external AREF option requires careful wiring. Never apply an external voltage to AREF while using the default reference setting.
ADC resolution and reference voltage vary by board:
| Board or setting | Typical ADC codes | Typical reference behavior |
|---|---|---|
| Arduino Uno default | 0–1023 | Approximately AVcc, often near 5 V |
| Arduino Uno internal | 0–1023 | Approximately 1.1 V |
| Many newer 3.3 V boards | Often 0–4095 | Commonly near 3.3 V, board-dependent |
Always check the board's documentation before choosing ADC_MAX, Vref, or an analogReference() setting. For precise measurements, measure the actual reference or use a calibrated voltage source.
Exercise
A 10-bit ADC uses a 3.3 V reference. What voltage does a raw reading of 204 represent, approximately?
Show answer
Use 204 × 3.3 ÷ 1023. The result is approximately 0.66 V.