ESP32 S3 - Potentiometer Servo Motor

This tutorial shows you how to use the ESP32 S3 with a potentiometer to control the angle of a servo motor in real time. By reading the potentiometer's analog value through the ESP32 S3's ADC and mapping it to a servo angle, you create a direct, intuitive link between a physical dial and precise mechanical rotation.

What you'll build:

  1. A circuit connecting a potentiometer and a servo motor to the ESP32 S3
  2. A sketch that reads the potentiometer's analog value (0–4095) on the ESP32 S3
  3. Logic that maps the analog reading to a servo angle between 0° and 180°
  4. Serial Monitor output that displays live analog values and the resulting servo angle
ESP32 S3 - Potentiometer - Servo Motor

Hardware Preparation

1×ESP32 S3 WROOM N16R8
1×Alternatively, ESP32 S3 SuperMini Dev Module
1×Alternatively, ESP32 S3 Uno-form Board
1×Alternatively, ESP32 S3 Camera Board
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×Servo Motor
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
1×Recommended: Screw Terminal Expansion Board for ESP32 S3
1×Recommended: Breakout Expansion Board for ESP32 S3
1×Recommended: Power Splitter for ESP32 S3

Or you can buy the following kits:

1×DIYables ESP32 S3 Starter Kit (ESP32 S3 included)
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 .

Buy Note: For controlling multiple servo motors, use the PCA9685 16 Channel PWM Servo Driver Module to save MCU pins and simplify wiring.

Overview of Servo Motor and Potentiometer

The servo motor and potentiometer are a classic combination for analog-driven motion control with the ESP32 S3. The potentiometer acts as a variable voltage divider that the ESP32 S3 reads through its 12-bit ADC, producing a value from 0 to 4095, while the servo motor converts the mapped angle command into precise physical rotation. Together they form a closed-loop feel in which turning the knob produces immediate, proportional mechanical movement.

Key Specifications

We have dedicated tutorials covering each component in depth. Each tutorial contains detailed information and step-by-step instructions about hardware pinout, working principle, wiring connection to the ESP32 S3, and Arduino code. Learn more about them at the following links:

Wiring Diagram

Connect the potentiometer and servo motor to your ESP32 S3 by following the diagram below. Double-check all connections before applying power, paying particular attention to the servo's power and signal wires.

The wiring diagram between ESP32 S3 Potentiometer Servo Motor

This image is created using Fritzing. Click to enlarge image

Do you want the wiring to stay in place? A Screw Terminal Block for ESP32 S3 solves this. Plug the ESP32 S3 into it and screw the wires in. The pins do not change. Just connect each wire to the matching screw terminal:

The wiring diagram between ESP32 S3 Potentiometer Servo Motor Screw Terminal

This image is created using Fritzing. Click to enlarge image

Or plug the ESP32 S3 into a GPIO Breakout Board for ESP32 S3. The same wiring then looks like this:

The wiring diagram between ESP32 S3 Potentiometer Servo Motor GPIO Breakout Board

This image is created using Fritzing. Click to enlarge image

Safety Notes

Standard hobby servo motors can briefly draw several hundred milliamps during movement, which may exceed what the ESP32 S3's USB supply can safely provide under continuous load. For bench testing, the USB port is usually sufficient; for any load-bearing or extended-run application, power the servo from a dedicated 5 V external supply and share only the GND rail with the ESP32 S3.

Component Pin ESP32 S3 Pin
Potentiometer Left pin 3.3V
Potentiometer Middle pin (wiper) GPIO1
Potentiometer Right pin GND
Servo Motor GND (Brown/Black) GND
Servo Motor VCC (Red) 5V
Servo Motor Signal (Yellow/Orange) GPIO12

ESP32 S3 Code

The following code reads the potentiometer's analog value on the ESP32 S3, maps it to a servo angle between 0° and 180°, and then commands the servo to move to that angle. The ESP32Servo library handles the PWM signal generation so the servo receives a precise pulse-width command on every loop iteration.

/* * 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-servo-motor */ /* * 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-servo-motor */ #include <ESP32Servo.h> #define PIN_POTENTIOMETER 1 // ESP32-S3 pin GPIO1 (ADC1_CH0) connected to potentiometer #define PIN_SERVO 12 // ESP32-S3 pin GPIO12 connected to servo motor Servo myServo; // create servo object to control a servo 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); myServo.attach(PIN_SERVO); // attaches ESP32-S3 pin to the servo object } void loop() { // reads the value of the potentiometer (value between 0 and 4095) int analogValue = analogRead(PIN_POTENTIOMETER); // scales it to use it with the servo (value between 0 and 180) int angle = map(analogValue, 0, 4095, 0, 180); // sets the servo position according to the scaled value myServo.write(angle); // print out the value Serial.print("Analog: "); Serial.print(analogValue); Serial.print(", Angle: "); Serial.print(angle); Serial.println("°"); delay(100); }

Detailed Instructions

  1. New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
  2. Wire the potentiometer and servo motor to the ESP32 S3 following the wiring diagram shown above.
  3. Connect the ESP32 S3 board to your PC using a USB Type-C cable.
  4. Open Arduino IDE on your PC.
  5. Select the correct ESP32 S3 board and COM port from the Tools menu.
  6. Click the Libraries icon on the left bar of the Arduino IDE.
  7. Type ESP32Servo in the search box, then find the servo library by Kevin Harrington, John K. Bennett.
  8. Click Install to install the servo motor library for ESP32.
ESP32 S3 servo motor library
  1. Copy the above code and paste it into Arduino IDE.
  2. Click the Upload button to compile and upload the code to the ESP32 S3.
Arduino IDE Upload Code
  1. Open the Serial Monitor at 9600 baud.
  2. Rotate the potentiometer knob slowly from one end to the other.
  3. Observe the servo motor rotating in proportion to the knob position.
  4. View the live analog readings and servo angles in the Serial Monitor.
  5. Pro Tip: If you notice the servo jittering at rest, add a small deadband check in the code so the servo only updates when the analog reading changes by more than a fixed threshold (e.g., ±10 counts) — this eliminates noise-induced micro-movements.

Line-by-line Code Explanation

The above ESP32 S3 code contains line-by-line explanation. Please read the comments in the code!

Serial Monitor Output

The following Serial Monitor output shows the ESP32 S3 responding to potentiometer rotation in real time. Each line displays the raw analog value read from the ADC alongside the calculated servo angle so you can verify the mapping as you turn the dial.

∞
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:15:22] Analog: 0, Angle: 0° [2026-06-16 10:15:25] Analog: 1024, Angle: 45° [2026-06-16 10:15:28] Analog: 2048, Angle: 90° [2026-06-16 10:15:31] Analog: 3072, Angle: 135° [2026-06-16 10:15:34] Analog: 4095, Angle: 180°
Ln 11, Col 1
ESP32S3 Dev Module on COM15
2

※ NOTE THAT:

This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a potentiometer. The ESP32 S3 ADC is suitable for projects that do NOT need high accuracy. However, for projects that need precise measurements, please note:

  • The ESP32 S3 ADC is not perfectly accurate and might need calibration for correct results. Each ESP32 S3 board can be a bit different, so you need to calibrate the ADC for each individual board.
  • Calibration can be difficult, especially for beginners, and might not always give the exact results you want.

For projects that need high precision, consider using an external ADC (e.g ADS1115) with the ESP32 S3 or using an Arduino, which has a more reliable ADC. If you still want to calibrate the ESP32 S3 ADC, refer to ESP32 ADC Calibration Driver

Application and Project Ideas

Once you master potentiometer-driven servo control on the ESP32 S3, you can apply this analog-to-angle mapping pattern to a wide range of practical motion-control and robotics projects.

  1. Robotic arm joint: Use a potentiometer knob on a control panel to set the angle of a single robotic arm joint in a multi-servo build.
  2. Manual camera pan-tilt: Mount a servo on a camera rig and dial in the exact pan angle using a potentiometer for precise framing.
  3. Adjustable valve controller: Attach a servo to a flow valve and use a potentiometer to set the desired flow rate as a percentage of full open.
  4. Interactive display pointer: Drive a servo-mounted arrow or pointer on a dashboard to a user-selected position using a dial on the ESP32 S3.
  5. Steering servo calibration: Use the potentiometer to manually set neutral and end-stop positions on a remote-controlled vehicle's steering servo.
  6. Prototype door angle setter: Control the opening angle of a servo-driven hatch or door panel with a physical knob for repeatable testing.

Video Tutorial

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

Challenge Yourself

Now that you can control a servo motor with a potentiometer on the ESP32 S3, try these progressively challenging extensions to deepen your understanding of analog input and servo control.

  1. Beginner: Limit the servo range to 0°–90° by adjusting the map() arguments and verify the servo stops at 90° even when the potentiometer is at its maximum.
  2. Beginner: Add a Serial Monitor print statement that shows the raw analog value, the calculated voltage (in volts), and the servo angle on the same line for each reading.
  3. Intermediate: Implement a deadband so the servo only updates when the analog reading changes by more than 20 counts, eliminating jitter at stable potentiometer positions.
  4. Intermediate: Display the current potentiometer value and servo angle on an OLED or LCD screen so you can monitor the system without the Serial Monitor.
  5. Advanced: Add a second potentiometer to control a second servo motor on a separate GPIO pin, building the foundation of a two-axis pan-tilt camera mount.
  6. Advanced: Build a web interface served by the ESP32 S3 that displays the live servo angle on a gauge graphic and lets you set a software angle limit remotely via WiFi.

※ 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!