Wiring guide

How to wire a potentiometer to an Arduino Nano

To wire a potentiometer to an Arduino Nano, 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 Nano · 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 Nano 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 Nano 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 Nano

Logic level

The Arduino Nano’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 Nano’s 5 V rail, so the part shares the current the board can supply.

This pair

Ten bits against 5 V, 0 to 1023, the same as an Uno. A6 and A7 are extra analog inputs that cannot be digital pins at all. Any value of pot from 1 k to 100 k works; 10 k is the usual one.

Pins to leave alone

A6 and A7 are analog only: pinMode(A6, OUTPUT) does nothing and digitalRead(A7) is not there to call. D0 and D1 are the USB serial port.

The sketch

The working code for the Arduino Nano

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

Reading a potentiometer on Arduino Nano 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. Ten bits against 5 V, 0 to 1023, the same as an Uno. A6 and A7 are extra analog inputs that cannot be digital pins at all.

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 Nano

Reading a digital pin

analogRead() needs one of A0 to A7. 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.