ESP32 S3 - Joystick - Servo Motor
In this tutorial, you will learn how to use the ESP32 S3 board with a joystick to control two servo motors or a pan-tilt kit. By reading the joystick's analog X and Y axis values, you can precisely drive each servo motor independently for intuitive directional control.
A joystick has two built-in potentiometers arranged at right angles (called X-axis and Y-axis), which output analog values on the VRX and VRY pins. You will use these analog values to control two servo motors independently: the X-value controls servo #1 and the Y-value controls servo #2. When used with a pan-tilt kit, the combined movement of the two servo motors creates smooth 3D motion.
What you'll build:
- A joystick-controlled dual servo system using the ESP32 S3
- Use case 1: Servo motors rotate proportionally to the joystick thumb position and return to center on release
- Use case 2: Joystick commands servo motors step-by-step in four directions with a button to reset center
- Optional pan-tilt kit integration for 3D camera or sensor positioning
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables ESP32 S3 Starter Kit (ESP32 S3 included) | |
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
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 Joystick and Servo Motor
The joystick and servo motor are fundamental components for building motion-control projects with the ESP32 S3. Understanding how each component works individually will help you combine them effectively in this tutorial.
Key Specifications
Wiring Diagram
Connect the joystick's VRX and VRY pins to two ADC-capable GPIO pins on the ESP32 S3, and connect each servo motor's signal wire to separate PWM-capable GPIO pins. Ensure the servo motors are powered with an adequate 5V supply, using an external power source if multiple servos are connected.
Safety Notes
Servo motors can draw significant current, especially under load. Always power multiple servo motors from an external 5V supply rather than the ESP32 S3's onboard 3.3V regulator to avoid damaging the board.

This image is created using Fritzing. Click to enlarge image
If you plan to keep this circuit, think about screw terminals. Put the ESP32 S3 on a Screw Terminal Block for ESP32 S3, then tighten each wire under a screw. See the diagram below for the screw terminal version.

This image is created using Fritzing. Click to enlarge image
Prefer pin headers to screws? Plug the ESP32 S3 into a GPIO Breakout Board for ESP32 S3 instead:

This image is created using Fritzing. Click to enlarge image
ESP32 S3 Code
ESP32 S3 Code - The servo motors rotate according to the movement of the joystick's thumb
The following code reads the joystick's X and Y analog values and maps them directly to servo motor angles, so each servo tracks the joystick position in real time. When the thumb is released and returns to center, both servo motors automatically return to the 90-degree center position as well.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Connect the joystick and servo motors to the ESP32 S3 board as shown in the wiring diagram above.
- Connect the ESP32 S3 board to your PC via a USB Type-C cable.
- Open Arduino IDE on your PC.
- Select the right ESP32 S3 board and COM port.
- Click the Libraries icon on the left bar of the Arduino IDE.
- Type ESP32Servo in the search box, then look for the servo library by Kevin Harrington, John K. Bennett.
- Click Install button to install the servo motor library for ESP32.

- Copy the above code and open it with Arduino IDE.
- Click Upload button on Arduino IDE to upload the code to ESP32 S3.

- Open Serial Monitor.
- Push the joystick in some direction.
- Observe the servo motor's rotation.
- See the result on Serial Monitor.
You may notice that the servo motor does not always move perfectly proportionally to the joystick movement. This behavior is not due to the joystick or the servo motor itself, but rather the ADC characteristics of the ESP32 S3. The end of this tutorial explains why this happens.
ESP32 S3 Code - Use the joystick to command servo motors
The following code uses the joystick as a directional command input, moving each servo motor step-by-step in the pushed direction rather than tracking the joystick's absolute position. Pressing the joystick button resets both servo motors to the center position at 90 degrees.
Detailed Instructions
- New to ESP32 S3? Complete our Getting Started with ESP32 S3 guide first.
- Click the Libraries icon on the left bar of the Arduino IDE.
- Search "ezButton", then find the button library by ArduinoGetStarted.com.
- Click Install button to install the ezButton library.
- Search for ezButton created by ArduinoGetStarted.com and click the Install button.
- Copy the above code and open it with Arduino IDE.
- Click Upload button on Arduino IDE to upload the code to ESP32 S3.
- Open Serial Monitor.
- Push the joystick in some direction.
- Observe the servo motor's step-by-step rotation.
- See the result on Serial Monitor.
Pro Tip: Adjust the step size variable in the code to control how many degrees each servo moves per joystick command. A smaller step size gives finer control, while a larger step size moves the servo more quickly to its target position.
Code Explanation
Read the line-by-line explanation in the comment lines of the source code!
※ NOTE THAT:
This tutorial uses the analogRead() function to read values from an ADC (Analog-to-Digital Converter) connected to a joystick. 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 vary slightly, so you may 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. If you still want to calibrate the ESP32 S3 ADC, refer to ESP32 ADC Calibration Driver
Applications
Joystick-controlled servo motors are used in a wide range of real-world applications, from robotics to camera systems and industrial control panels. Here are some practical examples:
- Robotic Arm Control: Use the joystick to move a robotic arm's pan and tilt joints with intuitive thumb movements.
- Camera Pan-Tilt Platform: Mount a camera on a pan-tilt kit and use the joystick to aim it remotely for surveillance or photography.
- RC Vehicle Steering: Control the steering servo and throttle servo of a remote-controlled vehicle using a single joystick module.
- Antenna Tracker: Automatically or manually aim a directional antenna using two servo motors driven by joystick input.
- Drone Gimbal Control: Stabilize and point a drone camera gimbal using joystick commands during flight.
Video Tutorial
Watch the step-by-step video walkthrough for this ESP32 S3 project below.
Challenges
Now that you have the basics working, try extending the project to deepen your understanding of servo control and joystick input processing.
- Beginner: Modify the code so the servo motors move more slowly by reducing the step size, and add serial output showing the current angle of each servo after every command.
- Intermediate: Add a deadzone to the joystick center position so that small accidental movements do not trigger servo commands, improving the stability of the control.
- Advanced: Build a complete pan-tilt camera mount using two servo motors and the joystick, then add a push-button toggle that switches between proportional mode and step-command mode at runtime.