小编
Published2025-10-15
In this article, we explore how to control a servo motor with a potentiometer using an Arduino. The combination of a servo motor, potentiometer, and Arduino provides an accessible yet powerful way to create precise motion control systems for robotics, automation, and DIY projects. Learn step-by-step how to set up and program the system for accurate and smooth motor movements.

servo motor, potentiometer, Arduino, motion control, robotics, DIY, automation, Arduino project, servo motor control, precise movement, electronics project
Introduction to Servo Motors, Potentiometers, and Arduino
When it comes to creating interactive electronics projects, the combination of a servo motor, potentiometer, and an Arduino is one of the most versatile setups. Whether you’re building a simple robotic arm or designing a custom automation system, this trio forms the backbone of precise control and smooth, accurate movements.
A servo motor is a small, compact motor used in robotics and automation that is designed to turn to a specific position based on an input signal. Unlike standard motors that rotate continuously, servo motors have a limited range of motion (typically 0° to 180°) and are capable of very precise control. They are widely used in applications that require exact positioning, such as steering systems in cars, camera gimbals, or robotic arms.
A potentiometer is a variable resistor, often referred to as a "variable dial" or "adjustable resistor," that changes its resistance based on its rotation. As you turn the potentiometer’s knob, the resistance value varies, which in turn alters the voltage output that can be read by a microcontroller like the Arduino. This makes it an ideal component for creating a user interface for controlling servo motors, where the potentiometer’s position directly influences the motor’s angle.
Why Use Arduino for Control?
Arduino, a popular open-source electronics platform, allows anyone to easily interact with hardware components like motors and sensors. Its simplicity and accessibility make it a favorite choice among hobbyists and engineers alike. The Arduino microcontroller reads input data (like the varying voltage from the potentiometer) and processes it, converting it into an output signal that controls the servo motor. The beauty of Arduino is its straightforward programming environment, meaning that even beginners can quickly learn how to write code that commands hardware.
The Concept of Using a Potentiometer to Control a Servo Motor
When you connect a potentiometer to an Arduino and a servo motor, you can create a system where the position of the potentiometer’s knob directly determines the angle at which the servo motor moves. This setup is often used in applications where precise positioning is necessary. For example, a potentiometer can be used to control the tilt of a camera, the position of a robotic arm, or even adjust the throttle in a remote-controlled vehicle.
By turning the potentiometer, the resistance changes, which is translated by the Arduino into an appropriate control signal for the servo motor. In essence, this allows you to control the servo with the precision and ease of a simple turning knob.
Components Required for the Project
To build this simple yet powerful system, you’ll need a few key components:
Arduino Board (Uno, Nano, or similar): The heart of the system that reads inputs and outputs commands to the servo.
Servo Motor (SG90 or similar): The motor that will rotate based on the Arduino’s control signals.
Potentiometer (10kΩ is ideal): Used to provide variable input to control the servo’s position.
Jumper Wires: For making connections between components.
Breadboard (optional): For easy prototyping and connecting components without soldering.
The wiring for this setup is fairly simple:
Potentiometer: Connect the potentiometer’s middle pin (wiper) to an analog input pin on the Arduino (A0, for example), the other two pins to 5V and GND.
Servo Motor: The servo motor has three wires: one for power (5V), one for ground (GND), and one for the signal (PWM pin, such as D9 on the Arduino).
The rest is standard wiring for the power and ground connections for the Arduino.
Once everything is connected, we can move on to programming the Arduino to control the servo motor.
Writing the Code and Controlling the Servo
Now that the hardware setup is complete, it’s time to dive into the code. The beauty of this project is that the code to control the servo motor is relatively simple, thanks to the easy-to-use Servo library provided by Arduino.
To control a servo with a potentiometer, you’ll use the Servo library to easily manage the movement of the motor. Here’s the basic code structure for the project:
#include // Include the Servo library
// Define pin connections
int potPin = A0; // Potentiometer connected to analog pin A0
int val = 0; // Variable to store the potentiometer value
Servo myServo; // Create a Servo object
myServo.attach(9); // Attach the servo to pin 9 on the Arduino
val = analogRead(potPin); // Read the potentiometer value
val = map(val, 0, 1023, 0, 180); // Map the value to an angle between 0 and 180 degrees
myServo.write(val); // Move the servo to the corresponding angle
delay(15); // Wait for the servo to reach the position
Servo Library: The code begins by including the Servo library, which provides functions to control the servo motor.
Pin Setup: The potentiometer is connected to analog pin A0, and the servo motor is controlled by digital pin D9.
Reading the Potentiometer: In the loop() function, the potentiometer's value is read using the analogRead() function. This returns a value between 0 and 1023, corresponding to the resistance (and thus the position) of the potentiometer.
Mapping the Input: The value from the potentiometer (ranging from 0 to 1023) is mapped to a range of 0 to 180 degrees, which is the typical range for most servo motors.
Controlling the Servo: The mapped value is then passed to the myServo.write() function, which moves the servo to the desired position. A short delay of 15 milliseconds ensures the motor has enough time to reach the target position before the next iteration.
While the basic system works well, there are a few tweaks you can make for smoother operation:
Adding a Smooth Transition: If you want the servo motor to move more smoothly between positions, you can gradually change its position instead of jumping directly. You can do this by using a for loop to incrementally adjust the angle over time.
Adjusting for Different Servo Models: Some servo motors may have slightly different ranges, or they might not be as responsive at certain angles. Experimenting with the map() function values can help fine-tune the motor’s performance.
Adding More Functionality: You can combine the potentiometer with other sensors, such as temperature or distance sensors, for more complex projects. For instance, you could control the servo’s movement based on environmental changes, like adjusting the position of a fan based on temperature readings.
Possible Applications of the Project
Robotic Arms: This setup is commonly used in robotics for controlling the joints of a robotic arm. With multiple servos and potentiometers, you can create a highly functional robot capable of performing precise tasks.
Camera Gimbals: Servo motors controlled by potentiometers are used in camera gimbals to adjust the tilt or pan of cameras, giving smooth and stable video footage.
Remote-Control Vehicles: If you’re designing a custom remote-control vehicle, the potentiometer can act as a throttle, allowing you to control the speed or direction with a turn of a knob.
Automation Systems: Whether it's adjusting the angle of solar panels or controlling a valve in a smart irrigation system, this project serves as a foundational step for various automation applications.
Using a potentiometer and an Arduino to control a servo motor is one of the most fundamental and powerful setups for DIY electronics projects. It offers precise control over motion, is simple to implement, and has countless applications in robotics, automation, and beyond. Whether you're a beginner or an experienced maker, this project is an excellent way to learn about the basics of motion control and get hands-on with real-world electronics.
Established in 2005, Kpower has been dedicated to a professional compact motion unit manufacturer, headquartered in Dongguan, Guangdong Province, China.
Update:2025-10-15
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.