Sub topic 13
Resolution and Voltage on Other Arduino Boards
This chapter assumes that you can upload a sketch, use analogRead(), and explain voltage, ground, and a potentiometer. You should also know how to open the Serial Monitor.
The same potentiometer can produce different readings on different boards. The reason is that boards can use different ADC resolutions and reference voltages.
Resolution is the number of steps
An analog-to-digital converter, or ADC, changes an input voltage into an integer. Its resolution tells you how many binary bits it uses.
A 10-bit ADC has:
2^10 = 1024
possible codes, from 0 through 1023. A 12-bit ADC has 4096 codes, from 0 through 4095. With the same voltage range, a 12-bit ADC gives smaller voltage steps.
Resolution does not guarantee accuracy. A board can report many digits while still having noise, calibration error, or an inaccurate reference voltage.
| Board family | Common ADC resolution | Common input range or reference | Important detail |
|---|---|---|---|
| Uno, classic Nano, Mega | 10 bits | Usually about 5 V | Maximum normal reading is 1023 |
| Due | 12 bits when configured | 3.3 V | Its input pins are not 5 V tolerant |
| Nano 33 IoT and similar 3.3 V boards | Often 10 or 12 bits, configurable | Usually about 3.3 V | Check the board's default settings |
| ESP32 boards | Commonly 12 bits | Board-specific and calibrated | The usable voltage range varies |
These are common configurations, not universal rules. Read the board's technical documentation before connecting a signal.
Reference voltage sets the scale
The ADC compares the input voltage with a reference voltage, called Vref. A reading near zero means the input is near ground. A reading at the largest code means the input is near Vref.
Use this formula:
voltage = raw reading × Vref / (2^bits − 1)For a classic Uno using a 5 V reference:
voltage = raw × 5.0 / 1023A raw reading of 512 represents about 2.50 V. On a 12-bit board using a 3.3 V reference, a raw reading of 2048 represents about 1.65 V.
The reference might come from the board's supply, an internal source, or an external reference pin. The actual supply is not always exactly 5.000 V or 3.300 V. If voltage accuracy matters, measure the reference with a multimeter or use a calibrated reference.
Board voltage limits matter
A 3.3 V board must not receive 5 V on an analog input unless its documentation explicitly permits it. A potentiometer connected between 5 V and ground can therefore damage a 3.3 V board, even if its wiper is connected correctly.
For a 3.3 V board, connect the potentiometer's outer terminals to 3.3 V and ground. The wiper then produces a voltage from 0 to about 3.3 V. Do not assume that a pin labeled A0 has the same electrical limits on every board.
Some boards also let you select the ADC resolution in software:
const int POT_PIN = A0;
const int ADC_BITS = 12;
const float VREF = 3.3;
void setup() {
Serial.begin(9600);
analogReadResolution(ADC_BITS);
}
void loop() {
int raw = analogRead(POT_PIN);
int maximumCode = (1 << ADC_BITS) - 1;
float volts = raw * VREF / maximumCode;
Serial.print("raw=");
Serial.print(raw);
Serial.print(" volts=");
Serial.println(volts, 3);
delay(200);
}Use this sketch only on a board that supports analogReadResolution(). On a classic Uno, remove that call and use 10 bits with the correct reference voltage.
Choosing portable calculations
Avoid assuming that every board returns values from 0 through 1023. Define the bit count and reference voltage for the board you are using. Also check whether the board's core changes the default resolution.
When moving a project, verify:
- The ADC resolution and maximum raw code.
- The default and selectable reference voltages.
- The maximum voltage allowed on the analog pin.
- Whether the analog input range is smaller than the supply voltage.
- Whether the reported value needs calibration.
Exercise
A board uses a 12-bit ADC and a 3.3 V reference. What voltage does a raw reading of 2048 represent?
Show answer
Use 2048 × 3.3 / 4095, which is approximately 1.65 V.