Reading a potentiometer with an Arduino is one of the first things worth knowing. It's three wires, a few lines of code, and gives you a variable input you can use for almost anything — speed control, brightness, scrolling, whatever.
Parts
- Arduino (any model)
- 10kΩ potentiometer
- Jumper wires
How a potentiometer works
A potentiometer is a variable resistor with three pins. The two outer pins connect to power and ground. The middle pin — the wiper — slides along a resistive track, so as you turn the knob, it outputs a voltage somewhere between 0 and 5 volts. That voltage is what the Arduino reads.
Wiring
Connect the left outer pin to 5V, the right outer pin to GND, and the middle wiper pin to A0 on the Arduino. Any analog input pin works — A0 is just a common choice. That's the whole circuit.
Reading raw values
The analogRead() function returns a value between 0 and 1023, corresponding to 0–5V. Upload the sketch below, open the serial monitor at 9600 baud, and turn the knob — you'll see the number change in real time.
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
Serial.println(value);
delay(100);
}
Mapping to percent
Raw numbers between 0 and 1023 aren't always the most readable. The map() function lets you convert them to any range you want. Here's a version that outputs 0–100%, which is much easier to read at a glance:
void setup() {
Serial.begin(9600);
}
void loop() {
int value = analogRead(A0);
int percent = map(value, 0, 1023, 0, 100);
Serial.print(percent);
Serial.println("%");
delay(100);
}
What you can use this for
Once you have a variable analog input, you can use it to control almost anything: LED brightness with PWM, motor speed via an H-bridge, servo position, or even scrolling through a menu. It's a simple component but it shows up everywhere.
Full code is on my site. If you build something with this, drop it in the Discord — I'd like to see what people make.