Sub topic 4
The voltage divider behind a potentiometer
This chapter assumes you can write a basic sketch with setup() and loop(). It also assumes you know voltage, ground and breadboard wiring, and that you know the ADC turns a voltage into a number from 0 to 1023. Later chapters cover the potentiometer's physical terminals and the wiring to A0. This chapter explains the circuit idea underneath: the voltage divider. Once you understand it, you can predict what analogRead() returns and see why a potentiometer is a safe, accurate input.
What a voltage divider does
A voltage divider is two resistors in series between a supply voltage and ground. The point where they meet sits at a voltage between the two. That voltage depends only on the ratio of the resistors.
The formula is:
Vout = Vin × R2 / (R1 + R2)
Some quick cases show how it behaves:
- If R1 and R2 are equal, Vout is half of Vin.
- If R2 is much larger than R1, Vout is close to Vin.
- If R2 is much smaller than R1, Vout is close to 0 V.
Why the formula works
The same current flows through both resistors, because they are in series and nothing else draws current. Ohm's law gives that current:
I = Vin / (R1 + R2)
The voltage across R2 is that current times R2:
Vout = I × R2 = Vin × R2 / (R1 + R2)
That is the divider formula. Vout is the share of the supply that falls across R2.
A worked example
Take Vin = 5 V, R1 = 10 kΩ and R2 = 20 kΩ.
- Vout = 5 × 20 000 / 30 000 = 3.333 V.
- The fraction of full scale is 20 / 30 = 0.667.
- On a 10-bit ADC with a 5 V reference, the expected reading is about 0.667 × 1023 ≈ 682.
The reading is a ratio of the supply, and the formula gives you that ratio directly.
A potentiometer is a divider with a movable junction
A potentiometer is a resistor of fixed total resistance with a sliding contact, called the wiper. The wiper splits the resistor into two parts. One part runs from the wiper to the supply end, and the other runs from the wiper to the ground end. Those two parts are R1 and R2 in the formula.
The total R1 + R2 never changes. It equals the pot's rated value, such as 10 kΩ. Only the split changes as you turn the knob. If the wiper is a fraction x of the way from the ground end to the supply end, then R2 = x × Rtotal and R1 = (1 − x) × Rtotal. Substituting into the formula:
Vout = Vin × x
The output voltage is linear in the wiper position for a linear-taper pot. The table shows what to expect on a 5 V Uno.
| Wiper position x | Vout | Expected `analogRead()` |
|---|---|---|
| 0 (ground end) | 0 V | 0 |
| 0.25 | 1.25 V | about 256 |
| 0.50 | 2.50 V | about 511 |
| 0.75 | 3.75 V | about 767 |
| 1 (supply end) | 5 V | 1023 |
Values are approximate because the ADC truncates to whole steps and real pots have tolerance. Many pots are only guaranteed to about ±20% of their rated total resistance. That does not matter here, because the output depends on the ratio, not on the absolute resistance.
Ratiometric measurement
If the same supply powers the pot and sets the ADC reference, the reading is ratiometric. It depends on the wiper position and does not depend on the supply voltage. On an Uno, the default reference is the 5 V rail, and the pot is also connected to 5 V. If the rail sags to 4.8 V, Vout drops by the same fraction as the reference, and the raw reading stays the same.
This matters when you convert to volts. The conversion raw * (5.0 / 1023.0) assumes the rail really is 5.0 V. The raw number is more trustworthy than the computed voltage. If you only need the knob position, use the raw value or a scaled version of it.
Predicting readings in code
This sketch assumes a divider built from a fixed 10 kΩ resistor for R1 and a fixed 20 kΩ resistor for R2, with the junction wired to A0. It prints the prediction next to the measurement. The two numbers should differ by only a few counts.
const int SENSE_PIN = A0;
const float VIN = 5.0; // Uno supply and default reference
const float R1_OHMS = 10000.0;
const float R2_OHMS = 20000.0;
void setup() {
Serial.begin(9600);
}
void loop() {
float predictedVolts = VIN * R2_OHMS / (R1_OHMS + R2_OHMS);
int predictedRaw = (int)(predictedVolts / VIN * 1023.0);
int measuredRaw = analogRead(SENSE_PIN);
float measuredVolts = measuredRaw * (VIN / 1023.0);
Serial.print("predicted raw=");
Serial.print(predictedRaw);
Serial.print(" measured raw=");
Serial.print(measuredRaw);
Serial.print(" measured volts=");
Serial.println(measuredVolts, 2);
delay(500);
}With the 10 kΩ and 20 kΩ values, the predicted raw value is 682. Resistor tolerance of 5% can move the measured value by a few percent, so a measured value somewhere in the 650 to 710 range is normal.
Loading: when the divider stops being ideal
The divider formula assumes nothing else draws current from the junction. If you connect a load, the load is in parallel with R2 and lowers the output.
For a load resistance RL from the junction to ground, replace R2 with:
R2_effective = R2 × RL / (R2 + RL)
Loading example
Use a 10 kΩ pot at the midpoint, so R1 = R2 = 5 kΩ, and connect a 10 kΩ load from the wiper to ground.
- R2_effective = 5 kΩ × 10 kΩ / 15 kΩ = 3.333 kΩ.
- Vout = 5 × 3.333 / (5 + 3.333) = 2.0 V.
- The expected reading is about 0.4 × 1023 ≈ 409, not the 511 you would see unloaded.
The knob is physically at the midpoint, but the reading says 40%. The error is also non-linear, so you cannot fix it with a constant offset.
Why the Arduino input is a good load
An analog input pin presents a very high resistance to the divider in steady state. The ATmega328P datasheet gives input leakage of about a microamp at most. At that level, the pin barely disturbs the divider. This is why a pot wired straight to A0 reads accurately.
The ADC does have one more behavior. When it samples, it briefly connects the pin to a small internal sampling capacitor and charges it. The datasheet recommends a source impedance of 10 kΩ or less so the capacitor charges fully within the sample time. A divider's source impedance, seen from the junction, is R1 and R2 in parallel. For a pot, that is largest at the midpoint:
Rsourcemax = R_total / 4
A 10 kΩ pot gives at most 2.5 kΩ, which is well inside the guideline. A 100 kΩ pot gives 25 kΩ, which is outside it. In that case, readings can drift toward the previous channel's value if you switch between analog pins.
Choosing the pot's total resistance
The pot's rated value is a trade-off between wasted current and source impedance.
| Total resistance | Current at 5 V | Worst-case source impedance | Typical verdict |
|---|---|---|---|
| 1 kΩ | 5 mA | 250 Ω | Wastes current. Hard on a battery. |
| 10 kΩ | 0.5 mA | 2.5 kΩ | Standard choice for Arduino. |
| 100 kΩ | 0.05 mA | 25 kΩ | Exceeds the ADC guideline. Expect settling errors. |
The current is simply Vin / R_total. If you need a low-power design, you can use a higher resistance, but you must then add a small capacitor from the junction to ground or take a dummy reading first to let the ADC settle. For a first project, use 10 kΩ.
Other sensors use the same idea
Many analog sensors are variable resistors. A light-dependent resistor and a thermistor both change resistance with the environment. You make them readable by pairing them with a fixed resistor in a divider. The Arduino reads the junction voltage, and you invert the formula to find the sensor's resistance. The pot is the simplest case because the two resistances always add up to the same total.
Common errors
- Reading changes with nothing connected to the junction. If the junction is not firmly connected, the analog pin floats and the reading wanders. In a divider, a broken wire to R2 or to ground causes this.
- Reading pinned at 1023 or 0. Check that both ends of the pot are connected, one to 5 V and one to ground. If one end is missing, the wiper pulls the pin to the connected end.
- Reading never reaches the extremes. A resistor in series with the pot, or a loaded output, compresses the range.
- Computed volts are slightly off. The USB-powered 5 V rail is often 4.7 to 5.1 V. Measure it with a multimeter if you need accurate volts.
Exercise
A divider has Vin = 5 V, R1 = 4.7 kΩ and R2 = 10 kΩ, and the junction is wired to A0 on a 5 V Uno. What voltage and approximate raw reading do you expect? Then a 10 kΩ load is connected from the junction to ground. What is the new voltage?
Show answer
Unloaded: Vout = 5 × 10 / (4.7 + 10) = 3.40 V, and the raw reading is about 3.40 / 5 × 1023 ≈ 696. Loaded: R2_effective = 10 × 10 / 20 = 5 kΩ, so Vout = 5 × 5 / (4.7 + 5) = 2.58 V and the raw reading is about 528.
Exercise
A 10 kΩ potentiometer is powered from 5 V. At which wiper position is its source impedance highest as seen by the ADC, and what is that impedance? Is it within the 10 kΩ guideline?
Show answer
It is highest at the midpoint, where R1 and R2 are both 5 kΩ. In parallel they give 5 × 5 / 10 = 2.5 kΩ, which is R_total / 4. That is well inside the 10 kΩ guideline.