Sub topic 2
Potentiometer terminals and how they work
This chapter assumes you know the setup() and loop() structure of a sketch, how to upload one, how to open the Serial Monitor, and basic voltage, ground, and breadboard wiring.
A potentiometer is a variable resistor with three terminals. The two outer terminals connect to the ends of a resistive track. The middle terminal, the wiper, connects to a contact that slides along the track as you turn the knob.
Moving the wiper changes how much of the track lies between the wiper and each outer terminal. Those two resistances add up to the total track resistance, so the pot acts as a voltage divider. The wiper voltage falls between the voltages on the outer terminals, in proportion to the knob position.
| Terminal | Connects to | Role |
|---|---|---|
| Outer terminal 1 | 5V | Top of the voltage range |
| Outer terminal 2 | GND | Bottom of the voltage range |
| Wiper (middle) | A0 | Output voltage that the ADC measures |
Wiring the potentiometer to A0
- Connect one outer terminal to the 5V pin.
- Connect the other outer terminal to a GND pin.
- Connect the wiper to analog pin A0.
Reading the potentiometer with analogRead()
analogRead() asks the ADC (analog-to-digital converter, the circuit that turns voltage into a number) to measure the voltage on a pin. On an Uno, it returns an integer from 0 to 1023.
const int POT_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN);
Serial.println(raw);
delay(100);
}Watching readings in the Serial Monitor
Open Tools > Serial Monitor and set the baud rate to 9600, which must match Serial.begin(9600). Turn the knob slowly. One end of the travel should show values near 0, and the other end values near 1023. If the values run the wrong way, swap the two outer-terminal wires.
Exercise
The knob sits at the midpoint and the sketch prints about 512. If the board reference is 5 V, what voltage is on A0?
Show answer
About 2.5 V, because 512 / 1023 × 5 ≈ 2.5 V.