ESP32-S3 · Potentiometer

ESP32-S3 Potentiometer Simulator: Wiring, Code and a Live Circuit

This is a 10 k potentiometer wired to an ESP32-S3 DevKitC-1, 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 3V3 and GND and the wiper to GPIO 1.

  • 3.3 V logic
  • No library: analogRead()
  • Wiper on GPIO 1
  • 0 to 4095
ESP32-S3 · 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.

Wiring the Potentiometer to the ESP32-S3

Every connection in the circuit above, with the board’s own pin names.

Potentiometer pinESP32-S3 pinWhy
Pin 1 (one end)3V3The top of the ADC’s range is 3.3 V, so the pot spans 0 to 3.3 V.
Pin 2 (wiper)GPIO 1The middle leg: a voltage between the two ends, set by the shaft.
Pin 3 (other end)GThe bottom of the range.

Run the pot from 3V3, never from 5V: turned to the top, the wiper would put 5 V on an analog input rated for 3.3 V. ADC1 is GPIO 1 to 10: twelve bits, 0 to 4095, with a full scale near 2.9 V at the default attenuation.

Pins to leave alone on the ESP32-S3

GPIO 19 and 20 are the USB port’s data lines, GPIO 35 to 37 belong to the PSRAM on octal-PSRAM boards such as the N8R8, and GPIO 0, 3, 45 and 46 are strapping pins.

On a real bench

The DevKitC-1 has two USB sockets: UART for uploading and the serial monitor, USB for the S3’s own USB device. Plug into UART while you work with the Potentiometer. The board is wide, so a single breadboard leaves only one row free on one side.

The code

The sketch the circuit above runs. Open it in the editor, change a line and press Run: it compiles in your browser.

Reading a potentiometer on ESP32-S3 GPIO 1
const int POT_PIN = 1;   // the wiper, GPIO 1

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

void loop() {
  int raw = analogRead(POT_PIN);            // 0 to 4095
  int percent = map(raw, 0, 4095, 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. ADC1 is GPIO 1 to 10: twelve bits, 0 to 4095, with a full scale near 2.9 V at the default attenuation.

map(raw, 0, 4095, 0, 100) rescales it to a percent with whole-number arithmetic. For a PWM duty use map(raw, 0, 4095, 0, 255), or divide.

Serial.begin(115200) opens the serial monitor. Serial is UART0 on the board’s UART socket, at 115200 baud in this sketch.

Common mistakes with the Potentiometer on the ESP32-S3

Using a pin without an ADC

Only GPIO 1 to 10 reach ADC1 on the ESP32-S3. analogRead() on any other pin returns 0, which looks like a broken pot.

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.

Running the pot from 5V

At the top of the travel the pin would see 5 V, above the ESP32-S3 (Xtensa LX7)’s rating. The pot belongs on 3V3.

Questions and answers

Can I simulate a potentiometer with an ESP32-S3 DevKitC-1?

Yes. The circuit at the top of this page is an ESP32-S3 DevKitC-1 with a potentiometer, running in your browser on a simulated ESP32-S3 (Xtensa LX7). 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 ESP32-S3?

ADC1 is GPIO 1 to 10: twelve bits, 0 to 4095, with a full scale near 2.9 V at the default attenuation.

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, 4095, 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.