learning

Controlling an SG90 Servo with a Potentiometer

2026-08-31

Platform: Arduino UNO R3 Hardware: SG90 Servo Motor, Potentiometer Language: C/C++

What I built

I built a small Arduino project where a potentiometer controls the position of an SG90 servo motor.

Turning the potentiometer changes its analog voltage. The Arduino reads that voltage, converts the resulting value into a range from 0 to 180, and uses that value as the servo's angle.

The result is a simple physical control system:

Human input
    ↓
Potentiometer
    ↓
Analog signal
    ↓
Arduino UNO
    ↓
0° - 180°
    ↓
SG90 Servo
    ↓
Physical movement

How I approached it

I didn't write the entire program from scratch.

Instead, I broke the problem into two smaller problems.

First, I looked at a basic servo motor example to understand how to initialize a servo and move it to a particular angle.

Then I looked at an example showing how to read a potentiometer using the Arduino's analog input.

Once I understood both pieces individually, I combined them.

The important part was connecting the two concepts:

potValue = analogRead(potPin);
potValue = map(potValue, 0, 1023, 0, 180);

myservo.write(potValue);

The potentiometer produces a value between 0 and 1023.

The map() function converts that into 0 to 180, which can then be used as the servo's position.

What I learned

This experiment helped me understand a basic embedded-systems pattern:

Read → Process → Act

The Arduino reads an input:

analogRead(potPin);

Processes the value:

map(potValue, 0, 1023, 0, 180);

And produces an output:

myservo.write(pos);

This is a very simple example, but the same general pattern appears in much larger embedded systems.

A sensor provides data, software processes that data, and an actuator or another system responds to it.

Something important I learned

I used web references while building this project.

Rather than treating the examples as a complete solution, I used them as references for individual concepts:

  1. Understand the basic Servo example.
  2. Understand how to read a potentiometer.
  3. Understand the values produced by the Arduino ADC.
  4. Combine the two.
  5. Test the physical behavior.
  6. Use the Serial Monitor to see what the program was doing.

This is something I want to continue practicing: taking small pieces of existing knowledge and combining them into something that behaves differently.

Hardware Setup

The project uses:

  • Arduino UNO R3
  • SG90 Servo Motor
  • Potentiometer
  • Breadboard
  • Jumper wires

The potentiometer is connected to A0, while the servo signal is connected to digital pin 9.

Result

The servo follows the position of the potentiometer.

Approximately:

Potentiometer        Servo

Minimum       →       0°
Middle        →       90°
Maximum       →       180°

Next Step

The next step would be to move beyond directly mapping an input to an output.

Some experiments I'd like to try are:

  • Smoothing noisy sensor input
  • Controlling servo speed
  • Using multiple sensors
  • Creating feedback-based control
  • Replacing the potentiometer with an actual sensor
  • Building a small closed-loop control system

This project is simple, but it is a useful first step toward understanding how software interacts with physical systems.