Arduino Nano Potentiometer Simulator: Wiring, Code and a Live Circuit
This is a 10 k potentiometer wired to an Arduino Nano, read live: the serial monitor prints the raw reading and a percent five times a second. Open it in the editor and turn the knob to see both change.
The ends go to 5V and GND and the wiper to pin A0.
- 5 V logic
- No library: analogRead()
- Wiper on pin A0
- 0 to 1023
Wiring the Potentiometer to the Arduino Nano
Every connection in the circuit above, with the board’s own pin names.
| Potentiometer pin | Arduino Nano pin | Why |
|---|---|---|
| Pin 1 (one end) | 5V | The top of the range: the ADC measures against 5 V. |
| Pin 2 (wiper) | pin A0 | The middle leg: a voltage between the two ends, set by the shaft. |
| Pin 3 (other end) | GND | The bottom of the range. |
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 on the Arduino Nano
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.
On a real bench
The Nano plugs into the breadboard itself, straddling the center channel, so the Potentiometer goes in a few columns along and every connection is a short jumper. The silkscreen labels its pins D2 to D13 and A0 to A7; in code D2 is simply 2. A Nano clone with a CH340 USB chip needs that driver on a real computer.
The code
The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.
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);
}
analogRead(POT_PIN) converts the wiper’s voltage to a number. 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.
map(raw, 0, 1023, 0, 100) rescales it to a percent with whole-number arithmetic. For a PWM duty use map(raw, 0, 1023, 0, 255), or divide.
Serial.begin(9600) opens the serial monitor. Serial is the USB port, as on the Uno; a clone with a CH340 chip needs that driver on a real computer, which the simulator does not.
Common mistakes with the Potentiometer on the 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.
Questions and answers
Can I simulate a potentiometer with an Arduino Nano?
Yes. The circuit at the top of this page is an Arduino Nano with a potentiometer, running in your browser on a simulated ATmega328P. Drag the knob and the analog pin sees the divided voltage, converted the way the board’s own ADC converts it. Press Run it in the editor to change the wiring or the code; it is free and needs no account.
What range does analogRead() give on the Arduino Nano?
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.
Which way should the pot turn?
Swap the two end wires to reverse it. The wiper stays in the middle either way.
How do I dim an LED with the pot?
Read the pot, then analogWrite(ledPin, map(raw, 0, 1023, 0, 255)) on a PWM pin marked with a tilde.
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.