Arduino Uno R4 Potentiometer Simulator: Wiring, Code and a Live Circuit
This is a 10 k potentiometer wired to an Arduino Uno R4 Minima, 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. The R4’s converter has fourteen bits; the sketch reads ten, as an Uno does.
- 5 V logic
- No library: analogRead()
- Wiper on pin A0
- 0 to 1023
Wiring the Potentiometer to the Arduino Uno R4
Every connection in the circuit above, with the board’s own pin names.
| Potentiometer pin | Arduino Uno R4 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. |
The RA4M1’s converter is fourteen bits, but analogRead() returns ten (0 to 1023) so Uno sketches keep working; analogReadResolution(14) gives 0 to 16383. Any value of pot from 1 k to 100 k works; 10 k is the usual one.
Pins to leave alone on the Arduino Uno R4
An Uno sketch’s source builds for the R4, but a compiled Uno program will not run on it: different chip. The R4’s pins source less current than an Uno’s, about 8 mA each, so do not drive a relay coil or a motor straight from one.
On a real bench
The Uno R4 Minima fits every Uno shield and every Uno breadboard layout, so wire the Potentiometer exactly as you would on an Uno R3. It has a USB-C socket, and its VIN accepts up to 24 V where an Uno R3 stops at 12.
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. The RA4M1’s converter is fourteen bits, but analogRead() returns ten (0 to 1023) so Uno sketches keep working; analogReadResolution(14) gives 0 to 16383.
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; Serial1 is on pins 0 and 1, which on the R4 are free for other serial devices.
Common mistakes with the Potentiometer on the Arduino Uno R4
Expecting 14 bits by default
analogRead() on the R4 returns 0 to 1023 until the sketch calls analogReadResolution(14). Code that assumes 16383 at the top reads a quarter of the scale.
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 Uno R4 Minima?
Yes. The circuit at the top of this page is an Arduino Uno R4 Minima with a potentiometer, running in your browser on a simulated Renesas RA4M1 (Cortex-M4). 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 Uno R4?
The RA4M1’s converter is fourteen bits, but analogRead() returns ten (0 to 1023) so Uno sketches keep working; analogReadResolution(14) gives 0 to 16383.
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 any output pin.
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.