ESP32 S3 - Potentiometer

This tutorial instructs you how to use the ESP32 S3 with a potentiometer. The potentiometer is one of the most versatile input devices, allowing you to translate physical rotation into a digital value your ESP32 S3 can read and act on.

ESP32 S3 - Potentiometer

What you'll build:

  1. A circuit connecting a potentiometer to the ESP32 S3
  2. Code that reads the raw analog value from the potentiometer
  3. A voltage conversion that maps the ADC reading to real volts
  4. Serial Monitor output that displays live analog and voltage readings

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×Potentiometer
1×Alternatively, 10k Ohm Trimmer Potentiometer
1×Alternatively, Potentiometer Kit
1×Alternatively, Potentiometer Module with Knob
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Potentiometer

The potentiometer (also known as a rotary angle sensor) is a three-terminal variable resistor used to control settings such as speaker volume, room temperature, or lamp brightness. By rotating its shaft, you vary the resistance between the output pin and each supply rail, producing a proportional output voltage that your microcontroller can read.

Potentiometer Pinout

Key Specifications

Potentiometer Pinout

A potentiometer usually has 3 pins:

  1. VCC pin: connect this pin to VCC (5V or 3.3V)
  2. GND pin: connect this pin to GND (0V)
  3. Output pin: outputs the voltage to the ESP32 S3's analog input pin
Potentiometer Pinout

※ NOTE THAT:

The GND pin and VCC pin are interchangeable

How Potentiometer Works

The potentiometer's shaft can be rotated from 0° (closest to GND pin) to an angle (closest to VCC pin), called ANGLE_MAX.

The voltage on the output pin is directly proportional to the shaft's angle, varying from 0 V to VCC. The table below shows the relationship between angle and output voltage:

Angle Voltage
0v
ANGLE_MAX°VCC
angle°angle° × VCC / ANGLE_MAX°

※ NOTE THAT:

The ANGLE_MAX value depends on the manufacturer.

How Potentiometer Works

ESP32 S3 - Rotary Potentiometer

The ESP32 S3's analog input pin converts a voltage (between 0 V and 3.3 V) into an integer value (between 0 and 4095), called an ADC value or analog value.

You can connect the potentiometer's output pin to an ESP32 S3 analog input pin and then read the analog value from that pin. The analog value can be rescaled into other useful values:

  • Rescale the analog value to the potentiometer's angle.
  • Rescale the analog value to the potentiometer's voltage.
  • Rescale the analog value to a controllable setting (e.g. speaker volume, room temperature, or lamp brightness).

Rescale Range

FROM TO
Anglerotated by userANGLE_MAX°
Voltagefrom potentiometer's pin 0V3.3V
ADC valueread by ESP32 S3 04095
Setting valueconverted by ESP32 S3 VALUE_MINVALUE_MAX

Wiring Diagram between Potentiometer and ESP32 S3

Connect the potentiometer to your ESP32 S3 using a breadboard and jumper wires as shown in the diagram below. Ensure the potentiometer's output pin connects to an ADC-capable GPIO on the ESP32 S3.

  • How to connect ESP32 S3 and potentiometer using breadboard
The wiring diagram between ESP32 S3 Potentiometer

This image is created using Fritzing. Click to enlarge image

Safety Notes

Always power the potentiometer from the ESP32 S3's 3.3 V rail rather than 5 V, since the ESP32 S3's ADC input is rated for a maximum of 3.3 V. Double-check your wiring before powering up to avoid applying over-voltage to the analog pin.

Potentiometer PinESP32 S3 Pin
VCC3.3V
GNDGND
OutputGPIO5 (or any ADC-capable GPIO)

How To Program Potentiometer

Reading a potentiometer with the ESP32 S3 requires only a few lines of Arduino code. The following code snippets show each step — from reading the raw ADC value to converting it into meaningful units.

  • Read the value from an input pin connected to the output pin of the potentiometer using the analogRead() function.
analogValue = analogRead(5); // GPIO5
  • Rescale to the potentiometer's angle using the map() function.
angle = map(analogValue, 0, 4095, 0, ANGLE_MAX);
  • Rescale to the potentiometer's voltage:
voltage = map(analogValue, 0, 4095, 0, 3.3);
  • Rescale to a controllable value (e.g. volume, brightness, or motor speed):
value = map(analogValue, 0, 4095, VALUE_MIN, VALUE_MAX);
  • For example, rescaling to the brightness of an LED. As mentioned in the PWM tutorial, LED brightness can be controlled with a PWM value from 0 (always OFF) to 255 (always ON). You can map the analog value to LED brightness like this:
brightness = map(analogValue, 0, 4095, 0, 255);

If you want to dim the LED from a nightlight level to the brightest:

nightlight = 100; // depending on your desired brightness brightness = map(analogValue, 0, 4095, nightlight, 255);

※ NOTE THAT:

The map() function can only rescale the analog value to an int or long type value. If the controllable value is a float type, use the floatMap() function instead.

floatMap() function:

float floatMap(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }

ESP32 S3 Code

The following code reads the raw ADC value and the corresponding voltage from the potentiometer, then prints both to the Serial Monitor every 500 ms. Upload the sketch to your ESP32 S3 and open the Serial Monitor to see live readings as you rotate the knob.

/* * This ESP32 S3 code was developed by newbiely.com * * This ESP32 S3 code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-s3/esp32-s3-potentiometer */ /* * This ESP32-S3 code is created by esp32io.com * * This ESP32-S3 code is released in the public domain * * For more detail (instruction and wiring diagram), visit https://esp32io.com/tutorials/esp32-s3-potentiometer */ float floatMap(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; } // the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); // set the ADC attenuation to 11 dB (up to ~3.3V input) analogSetAttenuation(ADC_11db); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin GPIO5: int analogValue = analogRead(5); // Rescale to potentiometer's voltage (from 0V to 3.3V): float voltage = floatMap(analogValue, 0, 4095, 0, 3.3); // print out the value you read: Serial.print("Analog: "); Serial.print(analogValue); Serial.print(", Voltage: "); Serial.println(voltage); delay(1000); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Copy the above code and paste it into the Arduino IDE.
  3. Compile and upload the code to the ESP32 S3 board by clicking the Upload button in Arduino IDE.
Arduino IDE Upload Code
  1. Open the Serial Monitor in Arduino IDE.
How to open serial monitor on Arduino IDE
  1. Rotate the potentiometer knob slowly from one end to the other.
  2. Observe the live readings in the Serial Monitor.
  3. Pro Tip: Try mapping the analog value to an LED brightness using PWM to see a physical effect of the potentiometer in real time.

Serial Monitor

After uploading, the Serial Monitor will display the raw analog value alongside the calculated voltage. Rotate the potentiometer to see the values change in real time. The following readings were captured in 2026:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
ESP32S3 Dev Module
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'ESP32S3 Dev Module' on 'COM15')
New Line
9600 baud
[2026-06-16 10:00:01] Analog: 0, Voltage: 0.00 [2026-06-16 10:00:02] Analog: 312, Voltage: 0.25 [2026-06-16 10:00:03] Analog: 2048, Voltage: 1.65 [2026-06-16 10:00:04] Analog: 4095, Voltage: 3.30
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from the ADC connected to the potentiometer. The ESP32 S3 ADC is suitable for projects that do NOT require high accuracy. For projects needing precise measurements, note:

  • The ESP32 S3 ADC is not perfectly accurate and may need calibration. Each board can behave slightly differently.
  • Calibration can be challenging for beginners and may not always yield exact results.

For high-precision projects, consider using an external ADC (e.g. ADS1115) with the ESP32 S3. If you still want to calibrate the ADC, refer to ESP32 ADC Calibration Driver.

Applications

Potentiometers are commonly used wherever a user needs to dial in a setting interactively. Some practical applications for your ESP32 S3 projects include:

  1. Volume control: Adjust audio output level in a Bluetooth or wired speaker system.
  2. Brightness dimmer: Control the intensity of LEDs or an LCD backlight.
  3. Motor speed control: Set the target RPM of a DC motor via PWM mapping.
  4. Temperature setpoint: Allow users to dial a desired room temperature for a thermostat.
  5. Servo position: Rotate a servo motor to a user-selected angle in a robotic arm.

Video Tutorial

Watch the step-by-step video walkthrough for this ESP32 S3 project below.

Challenges

Now that you have a working potentiometer circuit on the ESP32 S3, try extending the project with these exercises to deepen your understanding.

  1. Beginner: Change the GPIO pin used for the potentiometer and update the code accordingly, then verify the readings still work correctly.
  2. Intermediate: Use the potentiometer value to control the brightness of an LED connected to a PWM-capable pin on the ESP32 S3.
  3. Advanced: Build a simple UI on an OLED display that shows a progress bar representing the current potentiometer position as a percentage.

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!