Servo Motor Control Using Potentiometer with Arduino Uno (Beginner Guide)

Servo Motor Control Using Potentiometer | Arduino Tutorial | MakeMindz

What Are We Building?

A potentiometer is an analog knob that changes resistance as you turn it. The Arduino reads this as a value from 0 to 1023, then uses the map() function to convert that range into a servo angle from 0° to 180°. Turn the knob left, the servo turns left. Turn it right, the servo follows. Simple, powerful, and the basis for robotic arm control.

🎙

Analog Input

Read a 0–1023 value from a rotating knob using analogRead().

🔁

Value Mapping

Use the map() function to convert any range to another instantly.

⚙️

Servo Control

Drive precise angular position using the built-in Servo library.

🦾

Robotics Basics

Foundation skill for robotic arms, camera gimbals, and steering systems.

What You Need

#ComponentQtyRole
1Arduino UNO×1Reads knob value & sends angle to servo
2Servo Motor (SG90)×1Rotates to the angle commanded by Arduino
310 kΩ Potentiometer×1Analog input — produces 0–5V as you turn it
4Jumper Wires×~6Connections between all components
5Breadboard×1Optional prototyping platform

Power tip: For high-torque servos (like MG995), power the servo from an external 5V supply and share the GND with Arduino. Powering from the Arduino's 5V pin can cause resets due to current draw.

Wiring It All Together

🎙 Potentiometer

Left Pin5V on Arduino
Right PinGND on Arduino
Middle (Wiper)Analog Pin A0 on Arduino

⚙️ Servo Motor (SG90)

Red Wire5V on Arduino
Brown / Black WireGND on Arduino
Orange / Yellow WireDigital Pin 9 on Arduino (PWM)

💡 Why Pin 9? Servo motors are controlled by PWM (Pulse Width Modulation) signals. On Arduino UNO, pins 3, 5, 6, 9, 10, and 11 support PWM — marked with a ~ symbol on the board.

Breadboard wiring layout for servo motor and potentiometer with Arduino UNO

How The Knob Controls The Motor

1

Potentiometer Produces Voltage

As you rotate the knob, the wiper pin outputs a voltage between 0V (fully left) and 5V (fully right), acting as a voltage divider.

2

Arduino Reads Analog Value

analogRead(A0) converts that voltage into an integer from 0 to 1023 using the 10-bit ADC built into the Arduino.

3

map() Converts the Range

The map(potValue, 0, 1023, 0, 180) function linearly scales the 0–1023 range into a 0°–180° angle. A reading of 512 becomes approximately 90°.

4

Servo Receives the Angle

myServo.write(angle) sends the command via PWM. The servo's internal feedback circuit holds the shaft precisely at that angle.

5

Loop Repeats Every 15ms

A delay(15) gives the servo time to physically reach its position before the next command is issued — preventing stuttering.

🔁 Visualizing the map() Function — Try It

Drag the slider to see the mapping live

Pot Value
0
Servo Angle

The Program

Paste this into the Arduino IDE or Tinkercad's code editor. The Servo.h library is built into Arduino — no extra installation needed.

servo_pot.ino
#include <Servo.h>   // Built-in Arduino servo library

// ── Objects ───────────────────────────────────
Servo myServo;

// ── Pin Definitions ───────────────────────────
int potPin   = A0;  // Potentiometer wiper pin
int servoPin = 9;   // Servo signal wire (PWM pin)

// ── Variables ─────────────────────────────────
int potValue;
int angle;

void setup() {
  myServo.attach(servoPin);  // Attach servo to pin 9
}

void loop() {

  potValue = analogRead(potPin);          // Read 0–1023

  angle = map(potValue, 0, 1023, 0, 180);  // Convert to 0°–180°

  myServo.write(angle);                   // Send angle to servo

  delay(15);   // Wait for servo to reach position

}

🧮 The map() Formula Explained

map(value, fromLow, fromHigh, toLow, toHigh)

In our code:
map(potValue, 0, 1023, 0, 180)

// potValue=512 → angle ≈ 90°
// potValue=256 → angle ≈ 45°
// potValue=768 → angle ≈ 135°

Simulate Before You Build

The full circuit is pre-wired in Tinkercad. Hit Start Simulation, then click and drag the potentiometer knob to watch the servo rotate in real time.

Open in Tinkercad Simulator

No components needed — run the entire project in your browser. The potentiometer knob is interactive and the servo animates live.

▶ Launch Simulator ↗
🧪 Challenges to try in the simulator:
  1. Start simulation and turn the potentiometer knob — observe the servo angle changing.
  2. Change map(..., 0, 180) to map(..., 0, 90) — what changes?
  3. Add Serial.println(angle) and open the Serial Monitor to see live angle data.
  4. Challenge: Can you control TWO servos with ONE potentiometer moving in opposite directions?

Quick Quiz

Tap an option to check your answer instantly.

Q1. What does the map() function do in this project?

Reads the potentiometer value
Converts 0–1023 into 0°–180°
Sends the angle command to the servo
Prints values to the Serial Monitor

Q2. If the potentiometer reads 512, what angle will the servo be at?

45°
~90°
180°

Q3. Why is the servo signal wire connected to Pin 9 and not Pin 4?

Pin 4 is reserved for other uses
Pin 9 is a PWM pin; Pin 4 is not
Pin 9 is closer to 5V on the board

Q4. What is the purpose of delay(15) at the end of the loop?

To improve potentiometer reading accuracy
To save power
To give the servo time to physically reach its position

Where Is This Used?

🦾Robotic ArmsManual joint control using multiple potentiometers
📷Camera GimbalAdjust pan/tilt angle precisely
🚗Steering SystemsRC car steering linked to a control knob
🔧DIY RoboticsPrototype any joint-based mechanism
🎮Game ControlsJoystick-style interfaces for simulators
🔌AutomationManual override for automated actuators
🔌
Servo jitters or vibrates

Use an external 5V power source for the servo and share GND with the Arduino. The Arduino's onboard 5V may not supply enough current.

📌
Compilation fails with "Servo.h not found"

Go to Sketch → Include Library → Manage Libraries and search for "Servo". In Tinkercad, it is already included automatically.

Servo moves only in one direction

Check that the potentiometer's outer pins are connected to 5V and GND (not reversed). Reversed polarity gives a very limited voltage swing.

🚀 Ready to level up? Try these extensions:
  • Add a second potentiometer + servo to control 2 axes (like a pan-tilt camera mount)
  • Display the live angle on a 16×2 LCD screen
  • Replace the potentiometer with an ultrasonic sensor to control angle by distance
  • Chain 3+ servos to build a simple robotic arm with manual control
  • Add limit switches to prevent the servo going past safe angles

Comments

try for free