Sub topic 6
Wiring the Potentiometer to A0
This chapter covers the physical connection between a potentiometer and an Arduino analog input. It assumes you know the basics of an Arduino sketch (setup() and loop()), how to upload a sketch and open the Serial Monitor, what voltage and ground are, and how a breadboard connects its holes. It also assumes you have used pinMode() with digital outputs. Earlier chapters covered how the ADC works and why a potentiometer acts as a voltage divider. Here the focus is on getting the circuit right, checking it, and recognizing the faults that come from wiring mistakes.
What you need
- An Arduino Uno or a compatible 5 V board
- A potentiometer. A 10 kΩ linear (type "B") part is the usual choice.
- A solderless breadboard
- Three jumper wires
- A USB cable
A 10 kΩ value works well for a reason covered later in this chapter. Values from 1 kΩ to 100 kΩ will work, but the extremes cause problems.
The three terminals
A potentiometer has three terminals. The two outer terminals connect to the ends of a fixed resistive track. The middle terminal, called the wiper, connects to a sliding contact that moves along the track when you turn the shaft.
| Terminal | Position | Connects to | Role |
|---|---|---|---|
| Outer 1 | Left, shaft facing you | 5V | One end of the track |
| Wiper | Middle | A0 | Output voltage |
| Outer 2 | Right, shaft facing you | GND | Other end of the track |
The result is a voltage divider. With 5 V across the track, the wiper sits somewhere between 0 V and 5 V depending on shaft position. At one end of travel the wiper voltage is 0 V. At the other end it is 5 V. In the middle it is about 2.5 V.
Swapping the two outer wires does not damage anything. It only reverses the direction: clockwise rotation will lower the reading instead of raising it. The wiper must always go to the middle terminal, because that is the only terminal whose voltage changes with rotation.
Wiring steps
- Unplug the USB cable. Wiring with power on is usually safe at these voltages, but a loose wire touching the wrong pin is easier to avoid with power off.
- Press the potentiometer into the breadboard so each of its three pins sits in a different column. Pins in the same column are shorted together.
- Connect the Arduino 5V pin to the breadboard's power rail with a red jumper.
- Connect the Arduino GND pin to the ground rail with a black jumper.
- Run a jumper from the left pin of the potentiometer to the 5V rail.
- Run a jumper from the right pin of the potentiometer to the GND rail.
- Run a jumper from the middle pin to the Arduino pin A0.
- Reconnect USB.
Use a consistent color scheme: red for 5V, black for GND, and another color (yellow or green) for the signal wire to A0. It makes later debugging much faster.
Why A0 and not a digital pin
On an Uno, pins A0 to A5 connect to the ADC through a multiplexer, which is a switch that selects one input at a time. Only these pins can be read with analogRead(). You can pass either A0 or the number 0 to analogRead(), but the constant A0 is clearer and is the form used throughout this tutorial.
Analog pins are inputs by default. You do not need to call pinMode(A0, INPUT) before analogRead(), though doing so does no harm. This differs from digital pins, which you normally configure explicitly. The same pins can also act as digital pins (as pins 14 to 19 on an Uno), and calling pinMode(A0, OUTPUT) would turn A0 into an output. If you then connect the wiper to it, the pin and the potentiometer would fight each other. Never set a potentiometer pin to OUTPUT.
Why 10 kΩ
The ADC on an Uno is designed for signal sources with an output impedance of about 10 kΩ or less. Impedance here means how strongly the source resists supplying current. The ADC briefly draws a small current to charge an internal sampling capacitor. A high-impedance source cannot refill that capacitor fast enough, so the reading is slightly pulled toward the previous channel's value.
The worst-case output impedance of a potentiometer occurs at mid-travel, where it equals one quarter of the total resistance. For a 10 kΩ part that is 2.5 kΩ, well inside the limit. A 100 kΩ part reaches 25 kΩ at mid-travel, which is above the recommended range and can cause drift and crosstalk when you read several analog pins in turn.
The opposite extreme also has a cost. A 1 kΩ potentiometer across 5 V draws 5 mA continuously. That is wasteful on battery power but harmless for the board. A 10 kΩ part draws 0.5 mA.
A first test sketch
This sketch confirms the wiring. It reads A0 and prints the raw value, the voltage, and the part of the track that value represents.
const int POT_PIN = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int raw = analogRead(POT_PIN);
float volts = raw * (5.0 / 1023.0);
Serial.print("raw=");
Serial.print(raw);
Serial.print(" volts=");
Serial.println(volts, 2);
delay(100);
}Open the Serial Monitor at 9600 baud. Turn the shaft slowly from one end to the other. You should see the reading change smoothly between values near 0 and values near 1023, with the voltage between about 0.00 V and 5.00 V.
Small deviations are normal. A reading of 1 or 2 at one end, or 1021 or 1022 at the other, comes from the wiper contact resistance and ADC tolerance. A tiny amount of flicker in the last digit is also normal. Later chapters address that flicker with averaging and a deadband.
Checking the wiring
If the readings do not match what you expect, compare them with this table.
| Symptom | Likely cause | Fix |
|---|---|---|
| Reading stays at 0 | Wiper not connected to A0, or 5V not connected to an outer pin | Check the signal jumper and the 5V jumper |
| Reading stays near 1023 | GND jumper missing, or A0 wired straight to 5V | Verify the GND connection and that A0 connects only to the middle pin |
| Reading jumps randomly between 0 and 1023 | A0 floating, meaning wired to nothing | Reseat the wiper wire. A floating pin picks up electrical noise. |
| Reading changes only over a small range | Wrong terminals used, such as wiper and one outer wire only | Use all three terminals: both outer pins and the wiper |
| Turning the knob lowers the value when you expected a rise | Outer wires swapped | Swap them back, or invert in software |
| Reading drifts when you touch the part | Loose breadboard contact | Press the pins in firmly or use a different row |
| Sketch fails to upload | Wire on pin 0 or 1 (RX/TX) | Move the signal wire to A0, which is not the same as pin 0 |
The last row is a common confusion. On an Uno, analogRead(0) reads A0, but a wire placed in the digital pin 0 header socket goes to the serial receiver and blocks uploads.
Diagnosing without a meter
You can test the circuit with only the Arduino. Disconnect the wiper from A0 and observe the output. A floating analog input produces unstable values that drift and respond to nearby hands. Reconnect the wiper and the readings settle. This confirms that the pin is working and that the problem lies in the potentiometer wiring.
With a multimeter, set it to DC volts. Place the black probe on GND and the red probe on the wiper. The meter should read 0 to 5 V as you turn the shaft. If it does, the potentiometer is fine and any remaining problem is on the A0 side.
Edge cases
- Linear and logarithmic tapers. A linear taper (B) changes resistance in proportion to rotation. An audio taper (A) changes it logarithmically, so the reading rises slowly then quickly. For control inputs, choose linear.
- Never connect the wiper to 5V and GND at once. Only the outer terminals go to the supply. Connecting the wiper to a supply pin shorts part of the track and can overheat the part.
- Leaving one outer pin unconnected. The potentiometer then behaves as a variable resistor with the wiper tied to nothing useful, and the reading will not sweep the full range.
- Boards at 3.3 V. On a 3.3 V board such as an ESP32 or Arduino Due, connect the outer pin to 3.3V, not 5V. Feeding 5 V into an analog pin on those boards can damage them. Board differences are covered in a later chapter.
- Long wires. Wires longer than about 30 cm pick up noise. Keep the signal wire short or twist it with a ground wire.
- Reading right after switching pins. If your sketch reads several analog pins in turn, the first reading after a switch can be affected by the previous pin. A short delay or a discarded first reading helps.
Exercise
You wire a potentiometer with its left pin to 5V, its right pin to GND, and its middle pin to A0. The Serial Monitor shows a steady 1023 whatever position the knob is in. Name two wiring faults that could cause this and say how you would tell them apart.
Show answer
Either the GND outer pin is not connected, or the A0 wire is connected to the 5V rail (or the left pin) instead of the wiper. To tell them apart, move the A0 jumper to the middle pin and check that the GND jumper reaches the ground rail and that the ground rail connects to the Arduino GND pin. If the reading still sits at 1023 after the wiper is on A0, the GND path is broken. If the reading starts to change, the A0 wire was on the wrong terminal. A multimeter between the wiper and GND gives the same answer directly: a constant 5 V means the ground side of the track is open.
Exercise
Why is 10 kΩ preferred over 100 kΩ for a potentiometer on an Uno analog input, and what is the highest source impedance the potentiometer presents at mid-travel for each value?
Show answer
The Uno ADC expects a source impedance of about 10 kΩ or less so its sampling capacitor can charge in time. At mid-travel the potentiometer's output impedance is one quarter of its total resistance: 2.5 kΩ for a 10 kΩ part, which is within the limit, and 25 kΩ for a 100 kΩ part, which exceeds it and can cause drift and crosstalk between channels.