Wiring guide

How to wire a potentiometer to an Arduino Uno

To wire a potentiometer to an Arduino Uno, connect 1 to 5V, 2 to pin A0 and 3 to GND. Run the pot from 5 V: the wiper then swings from 0 to 5 V, which is exactly the range of the board’s converter. The sketch below uses no library beyond what the board includes. It reads the wiper and prints the raw reading and a percentage.

  • 5 V logic
  • Library: none
  • 3 wires
Arduino Uno · potentiometerlive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running on the simulator with the sketch below. Press what can be pressed; click anything else to open it in the editor.
Pin to pin

Potentiometer to Arduino Uno wiring table

Every wire in the circuit above, with the part’s pin names and the board’s own labels. The wire colors are the ones the circuit uses; on a real bench any colors work.

Potentiometer pinArduino Uno pinWire colorWhy
Pin 1 (one end)5VredThe top of the range: the ADC measures against 5 V.
Pin 2 (wiper)pin A0amberThe middle leg: a voltage between the two ends, set by the shaft.
Pin 3 (other end)GNDblueThe bottom of the range.
Voltage

Power and logic levels for potentiometer and Arduino Uno

Logic level

The Arduino Uno’s pins are 5 V logic. A 5 V part can drive them directly; a part whose signal pins are limited to 3.3 V needs a level shifter.

Supply

The potentiometer takes 5 V from 5V. That is the Arduino Uno’s 5 V rail, so the part shares the current the board can supply.

This pair

The Uno’s ADC is ten bits against its 5 V rail, so analogRead() gives 0 to 1023. Any value of pot from 1 k to 100 k works; 10 k is the usual one.

Pins to leave alone

Pins 0 and 1 are the USB serial port on a real Uno, so anything wired there fights the upload and the serial monitor. Pin 13 carries the onboard LED.

The sketch

The working code for the Arduino Uno

Library: none, the sketch reads the wiper with analogRead(). This is the sketch the circuit above runs.

Reading a potentiometer on Arduino Uno pin A0
const int POT_PIN = A0;   // the wiper, pin A0

void setup() {
  Serial.begin(9600);
}

void loop() {
  int raw = analogRead(POT_PIN);            // 0 to 1023
  int percent = map(raw, 0, 1023, 0, 100);
  Serial.print("Raw: ");
  Serial.print(raw);
  Serial.print("  Percent: ");
  Serial.println(percent);
  delay(200);
}
Output

What you should see

Open the serial monitor at 9600 baud and turn the knob: each line shows the raw reading and a percentage that follow it. The Uno’s ADC is ten bits against its 5 V rail, so analogRead() gives 0 to 1023.

A reading that jumps around or stays at zero means the wiper is not on the analog pin, or the outer legs are not on power and ground.

The serial monitor prints this, recorded from the circuit above with the knob at its middle:

Raw: 511  Percent: 49
Pitfalls

Common mistakes wiring a potentiometer to an Arduino Uno

Reading a digital pin

analogRead() needs one of A0 to A5. On a digital pin it reads nothing useful.

Wiring the wiper to an end

The middle leg is the wiper. With an end leg on the analog pin the reading never moves, or jumps from 0 to the top at one end of the travel.

Trusting the last count

A real pot’s reading wobbles by a count or two. Average a few readings, or ignore changes smaller than 3, before driving something the eye or ear will notice.

Build your own potentiometer project

Open this circuit in the editor, change the wiring or the code, and keep your version in a free account.