Servo with a Potentiometer
Beginner25 minAs you turn a potentiometer's knob, an SG90 servo motor turns with it: one end of the knob is 0°, the other 180°. The angle the servo stops at is also written to the Serial Monitor. It teaches adding a library (Servo) to a project, turning a value read with analogRead into an angle with map, and sending a motor to the angle you want with servo.write. The Servo library comes with the Arduino IDE, so there is nothing to install.
Build it step by step in the appWhat you need
1 × Arduino Uno R3
1 × Breadboard 830 Points (MB-102)
1 × SG90 Micro Servo Motor
1 × 10K Potentiometer
8 × Jumper Wire - Male/Male
Wiring steps
- 1
Connect the power rails (5V and GND)

Plug a black jumper wire into one of the GND pins on the Arduino's power header and connect its other end to the breadboard's top blue (−) rail. Plug a red jumper wire into the 5V pin on the same header and connect its other end to the top red (+) rail. Both the potentiometer and the servo are powered from these two rails.
- Arduino GND → the top blue (−) rail (black wire)
- Arduino 5V → the top red (+) rail (red wire)
- 2
Add and wire the potentiometer

Plug the potentiometer's three legs into columns 20, 21 and 22 in the top half. Connect column 20 to the top (−) rail with a short black wire and column 22 to the top (+) rail with a short red wire. Then connect the Arduino's A0 pin to the middle leg's column, column 21, with a yellow jumper wire (POT_PIN A0). As you turn the knob, the middle leg's voltage moves between 0 V and 5 V, which the Arduino reads as a number from 0 to 1023.
- potentiometer left leg → column 20, top half
- potentiometer middle leg → column 21, top half
- potentiometer right leg → column 22, top half
- column 20, top half → the top blue (−) rail (black wire)
- column 22, top half → the top red (+) rail (red wire)
- Arduino A0 → column 21, top half (yellow wire)
- 3
Connect the servo

Push one end of three male-male jumper wires into the three-hole plug at the end of the SG90's cable. Connect the one facing the brown (GND) wire to the top (−) rail, the one facing the red (5V) wire to the top (+) rail, and the one facing the orange (signal) wire straight to the Arduino's pin ~9 (SERVO_PIN 9). The servo works out which angle to turn to from the length of short pulses on its signal wire; the Servo library makes those pulses.
- servo brown (GND) lead → the top blue (−) rail (black wire)
- servo red (5V) lead → the top red (+) rail (red wire)
- Arduino pin 9 → servo orange (signal) lead (orange wire)
Arduino sketch
// The Servo library ships with the IDE
#include <Servo.h>
// Middle leg of the potentiometer: A0
const int POT_PIN = A0;
// The servo's orange (signal) wire
const int SERVO_PIN = 9;
Servo servo;
int lastAngle = -1;
void setup() {
servo.attach(SERVO_PIN);
Serial.begin(9600);
}
void loop() {
// From 0 (one end) to 1023 (the other)
int potValue = analogRead(POT_PIN);
// Turn 0–1023 into 0–180 degrees
int angle = map(potValue, 0, 1023, 0, 180);
servo.write(angle);
// Write the angle when it changes
if (angle != lastAngle) {
Serial.print("Angle: ");
Serial.println(angle);
lastAngle = angle;
}
// Give the servo time to get there
delay(15);
}
What the Serial Monitor shows
Angle: 0 Angle: 45 Angle: 90 Angle: 135 Angle: 180
What you will see
As you turn the knob the servo's arm turns too: 0° at one end of the knob, 90° in the middle, 180° at the other end. The angle in the Serial Monitor changes with the knob. If the angle changes but the servo does not move, check that the orange wire is on pin ~9 and the red and brown wires are in the right rails. If the servo jitters or the Arduino restarts on its own, the servo is not getting enough current from USB: do not load the arm, and power the Arduino from an adapter if needed. If the angle never changes, check that the yellow wire is in the middle leg's column (21).
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
Build it step by step in the app