Этот учебник является частью: Servo Motors
All videos related to servo motors that are related, listed here.
Controlling a Servo with a Potentiometer Using Arduino
In this tutorial, we will learn how to control a servo motor using a potentiometer with an Arduino. The potentiometer allows us to adjust the angle of the servo smoothly, giving us real-time control over its position. By the end of this project, you will have a functional setup that displays the potentiometer value and the corresponding servo angle.

As the potentiometer is turned, the angle of the servo motor changes from 0 to 180 degrees. We will use the Arduino's analog input to read the potentiometer value and then map this value to the servo's range using a simple formula. This project is an excellent way to understand how analog inputs work and how to control motors with them (in video at 01:45).
Hardware Explained
For this project, we need an Arduino board, a servo motor, and a potentiometer. The potentiometer acts as a variable resistor, providing a voltage output that corresponds to its position. This output is read by the Arduino's analog input, allowing us to determine how far to turn the servo.
The servo motor is a type of motor that can be positioned at a specific angle. It receives a control signal, which tells it the desired position. The servo will rotate to that angle based on the input it receives from the Arduino, making it useful for various applications such as robotics and remote control devices.
Datasheet Details
| Manufacturer | Various |
|---|---|
| Part number | Standard Servo |
| Logic/IO voltage | 5 V |
| Supply voltage | 4.8 – 6 V |
| Output current (per channel) | Up to 1 A |
| Peak current (per channel) | Up to 2 A |
| PWM frequency guidance | 50 Hz |
| Input logic thresholds | 0.8 V (low) / 2.0 V (high) |
| Voltage drop / RDS(on) / saturation | 0.5 V |
| Thermal limits | 85 °C |
| Package | Standard size |
| Notes / variants | Available in different sizes and torque ratings |
- Ensure power supply is within limits (4.8 – 6 V).
- Use a suitable resistor value for the potentiometer (10 kΩ recommended).
- Check polarity of connections to avoid reversed operation.
- Be cautious of heat; ensure servo is not overloaded.
- Keep wiring short to reduce interference.
- Use decoupling capacitors across power inputs if needed.
- Verify that the potentiometer is correctly connected to analog pin A0.
Wiring Instructions

To wire the components, first connect the potentiometer. The middle pin of the potentiometer should be connected to the analog pin A0 on the Arduino. The left pin should go to the 5V pin on the Arduino, and the right pin should connect to the ground (GND).
Next, connect the servo motor. The ground wire (typically black or brown) from the servo should be connected to the Arduino's GND. The power wire (usually red) should connect to the 5V pin on the Arduino. Finally, the control wire (often yellow or white) should be connected to digital pin 9 on the Arduino. This setup will allow the Arduino to control the servo based on the potentiometer's position.

Code Examples & Walkthrough
Let's take a look at the key parts of the code. First, we include the Servo library and create a servo object:
#include
Servo myservo; // create servo object to control a servo
This code initializes the servo and prepares it for control. The next step involves reading the potentiometer value:
int val = analogRead(potpin); // reads the value of the potentiometer
Here, the value read from the potentiometer is stored in the variable val. The value will be between 0 and 1023, corresponding to the potentiometer's position. We then map this value to the servo's range:
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo
This line converts the potentiometer's value to a range suitable for the servo motor. Finally, we set the servo to the calculated position:
myservo.write(val); // sets the servo position according to the scaled value
This command tells the servo to move to the specified angle based on the potentiometer's position. You can find the complete code loaded below the article.
Demonstration / What to Expect
When you run the program, turning the potentiometer will adjust the angle of the servo motor smoothly. You should see the angle values being printed in the serial monitor as you turn the knob. If the servo behaves unexpectedly, check your wiring, especially the connections to the potentiometer and the servo (in video at 04:30).
The servo should respond immediately to the changes in the potentiometer's position. If you notice any lag or jumpiness, consider reducing the delay in the code to improve responsiveness.
Этот учебник является частью: Servo Motors
- Controlling a Servo with Push Buttons Using Arduino
- Control a Servo Motor with a Push Button: Move Servo and Return SPB-1
- Control a Servo Motor with a Push Button: Move Servo in One Direction SPB-2
- Controlling a Servo Motor with a Push Button: Move Servo While Button Is Pressed (SPB-3)
- Controlling a Servo with Potentiometer and LCD1602 using Arduino
- Управление сервомоторами с помощью инфракрасного пульта на Arduino
- Управление сервомотором Arduino с помощью потенциометра
- Управление положением сервопривода с помощью жестов рук для Arduino
- Controlling Two or More Servos with Potentiometers Using an Arduino
- How to Control a 360° Servo with Three Push-Button Switches
- How to Use Continuous 360° Servo with Arduino
- Arduino Code and Video for PCA9685 16-Channel 12-Bit Servo Controller V1
- Build an Arduino Servo Toggle Switch with a Push Button
Вещи, которые могут вам понадобиться
-
АмазонкаServo motor on Amazonamzn.to
-
АлиЭкспрессPurchase SG90 Servo motor 180 or 360 from AliExpresss.click.aliexpress.com
Ресурсы и ссылки
-
ВнешнийSG90 servosamzn.to
Файлы📁
Нет доступных файлов.