Robotics / Beginner

Power a servo without resetting your Arduino

Build a clear power plan, share a signal ground, and make your first controlled servo movement.

By Harry AvraamidesUpdated 22 November 202635 min activity

Before you start
Arduino UNO R3, a documented positional servo, suitable separate low-voltage supply; upload code with the mechanism detached.

You will leave with
A three-wire power plan, a midpoint test, and an optional knob-controlled movement test.

Before a servo moves a pencil-case hatch, prove that its power and signal work with the mechanism disconnected. This guide separates those jobs into a connection diagram, a single-position sketch and an optional manual control.

The pencil-case design behind this exercise specifies an MG996R-size servo. A tiny SG90 is not a drop-in replacement for that mechanical design. Neither the reference wiring nor the code below establishes how much load your actual servo can safely move.

1. Identify the servo and its supply

Start with the label and supplier documentation, not the shape of the case. The manufacturer's MG996R reference lists a 4.8–6.6 V operating range and a 1.4 A stall current. These are reference specifications, not measurements of a clone or of the pencil-case mechanism. Choose a regulated supply within your unit's range, with current capacity and connectors appropriate to its startup and load. Do not use the no-load current as the supply's required peak capacity.

For a first unloaded trial, a documented regulated 5 V supply is an option only when the exact servo accepts 5 V. A higher current-capacity rating does not increase the voltage or force the servo to draw that current. Stop for overheating, repeated resets, sustained buzzing or binding; deliberately stalling the output is not a sizing method.

Parts for the isolated experiment
PartWhat to verify
Arduino UNO R3 and data cableThis guide targets the classic 5 V ATmega328P board.
One positional servo, original horn removedVoltage, signal requirements, pulse range and lead functions.
Separate regulated DC supplyVoltage and peak-current capability for that servo; enclosed, ready-made adapter.
Rated terminal block or servo breakout and leadsWire/connector ratings, secure joints, and no exposed positive contacts.
Optional 10 kΩ linear potentiometerThree terminals: two ends and a centre wiper.
Blue SG90-labelled micro servo with three-wire connector and a bag of horns and screws.
Component reference photograph

A smaller SG90-labelled servo illustrates the three-wire lead, output shaft and supplied horns. This is not the MG996R-size servo specified by the pencil-case design, and is not a drop-in replacement. Identify your actual servo before using its voltage, pulse or torque ratings. This is a third-party component photo, not a Workbench test.

Photo: Luiz Augusto Souza de Mesquita · CC0 1.0. Wikimedia preview; no further edits. Image credits and scope.

2. Wire one signal and a shared reference

UNO D9 to servo signal; external supply positive to servo positive; external negative to servo ground and UNO GND.
Functional connections, not a drawing of physical connector order. Colours identify nets, not guaranteed cable colours. Save diagram ↓
FromToJob
UNO D9Servo signalControl pulses only
Servo supply positiveServo positiveMotor power
Servo supply negativeServo ground and UNO GNDMotor return and shared signal reference

Build those connections with both supplies off. Run the motor return directly to its supply junction, with a separate reference lead to the UNO. Keep motor current out of the UNO, breadboard power rails and thin signal jumpers. Leave the servo supply's positive separate from UNO 5V, VIN and USB. A shared ground is not a shared positive rail. This follows the separate-supply principle in Adafruit's servo wiring guide.

A ready-made servo breakout and rated screw terminals can avoid soldering for a bench trial. They still need correct polarity and strain relief. A wire twisted around another wire and wrapped in tape is not an equivalent connector.

3. Ask for one position first

Install the Servo library through the Arduino IDE Library Manager if it is unavailable. Select Arduino Uno and the correct port. Upload with servo power off and the horn/linkage removed. The sketch requests 1500 microseconds, a nominal centre command for the documented class of servo—not a measured 90-degree shaft angle. Verify that this command is supported by your servo before applying power.

Download servo-centre.ino ↓

Read the complete sketch
// Workbench — one unloaded positional servo; Arduino UNO R3.
// External regulated supply appropriate for the exact servo; shared ground.
#include <Servo.h>
Servo joint;
const byte SERVO_PIN = 9;
const int CENTRE_US = 1500; // Command only; verify your servo's accepted pulse range.

void setup() {
  joint.attach(SERVO_PIN);
  joint.writeMicroseconds(CENTRE_US);
}

void loop() {
  // Hold a single nominal midpoint. No automatic sweep or lid movement.
}

Once the UNO is running, energise the servo supply with the shaft unobstructed. Record whether it settles, continues rotating, twitches or causes a reset. A continuous-rotation servo interprets the same command differently; stop and identify the unit if behaviour contradicts the intended positional device. Before powering the UNO down, switch off servo power too.

4. Add a knob only after the midpoint works

With power off, connect the potentiometer's outer terminals to UNO 5V and GND, and its wiper to A0. Reversing the outer connections reverses the knob direction. Use the following sketch only with the servo still detached from the mechanism. It samples every 20 ms and maps the input into a deliberately narrow 1400–1600 microsecond window. This is a starting command range, not a guarantee of safe travel for an unidentified servo.

Download servo-knob.ino ↓

Read the complete sketch
// Workbench — detached positional servo controlled by a 10k potentiometer.
// UNO R3: A0 = wiper, D9 = servo signal. See tutorial for separate power.
#include <Servo.h>
Servo joint;
const byte SERVO_PIN = 9;
const byte KNOB_PIN = A0;
const int MIN_US = 1400; // Deliberately narrow starting window; check exact servo.
const int MAX_US = 1600;
const unsigned long SAMPLE_MS = 20UL;
unsigned long lastSampleAt = 0;
int commandUs = 1500;

void setup() {
  joint.attach(SERVO_PIN);
  joint.writeMicroseconds(commandUs);
}

void loop() {
  const unsigned long now = millis();
  if (now - lastSampleAt < SAMPLE_MS) return;
  lastSampleAt = now;
  const int raw = constrain(analogRead(KNOB_PIN), 0, 1023);
  const int targetUs = map(raw, 0, 1023, MIN_US, MAX_US);
  // A small deadband avoids repeatedly changing almost identical commands.
  if (abs(targetUs - commandUs) >= 4) {
    commandUs = targetUs;
    joint.writeMicroseconds(commandUs);
  }
}
What the important lines do
Code ideaPlain-English meaning
analogRead(A0)Read the knob as a number from 0 to 1023 on the UNO R3.
map(..., 1400, 1600)Translate that reading into the chosen pulse range.
now − lastSampleAtRun the update when enough time has passed, including across timer rollover.
abs(target − command) ≥ 4Ignore very small command changes. This does not fix a weak supply.

The Servo library uses Timer1 on UNO R3. Avoid analogWrite on D9/D10 while Servo is attached, even if its signal is moved elsewhere. Servo.read reports the requested command, not a position sensor reading. See the Servo API and timer definitions.

5. Troubleshoot the observation, not the whole project

ObservationFirst isolation step
UNO restarts when motion beginsReturn to midpoint only; inspect the separate power path and connections. Measure supply voltage during movement if you have suitable equipment.
No movementVerify pin functions and the common ground with power off. Confirm successful upload and supply output.
Buzzing or heatingDisconnect power. Remove load and check mechanical travel before another command.
Knob makes the servo jumpTest the potentiometer reading alone; a disconnected wiper may float.

6. Record a result before adding the hatch

Use the servo bench record to note the exact model, supply, pulse range and observations. Only after a repeatable unloaded result should you assess the mechanism's torque, end positions and pinch points. A successful free-running servo test does not validate an automatic closing lid. Continue with the pencil-case power and control plan.

Reference exercise · Read the evidence and checking record.

Your privacy, your choice.

This site currently loads no advertising or optional analytics scripts. Hosting includes aggregate traffic statistics and essential site-delivery functions. Optional services are off by default; changing these preferences does not activate them.

EssentialSite delivery and your saved privacy choices.Always on

Read the privacy notice