Arduino Uno SG90 Servo: Precision Robotic Actuator

Professional TowerPro SG90 9g micro servo responds to 50Hz PWM signals (1.0ms=0°, 1.5ms=90°, 2.0ms=180°) achieving ±1° positioning accuracy through internal potentiometer feedback and PID control loop. 1.8kg-cm stall torque at 6V delivers 0.12s/60° no-load speed.

Red=5-6V power (500mA stall), brown=GND, orange=signal (pins 9/10 PWM). External 4xAA supply recommended for continuous operation preventing Arduino USB brownouts.

How It Works

A hobby servo is a closed-loop position system in one package: a DC motor, a reduction gearbox, a potentiometer reading the output shaft angle, and a controller that drives the motor until the measured angle matches the commanded one. You command a position, not a speed, and the servo holds it against load.

The command arrives as a pulse-width signal, and this is the part people most often get wrong — it is not ordinary PWM duty cycle. The frame repeats every 20 ms (50 Hz), and what matters is the width of the high pulse within it: roughly 1000 µs for one extreme, 1500 µs for centre and 2000 µs for the other extreme. The Servo library handles this timing for you.

Current draw is the main practical constraint. A small SG90 draws around 100–250 mA while moving and can spike well above that when it stalls. The board's regulator cannot supply several servos; a separate 5–6 V supply is required for anything beyond one small servo moving lightly.

Standard servos sweep about 180°. Continuous-rotation servos look identical but reinterpret the signal as speed and direction, with 1500 µs meaning stop — a different device despite the same connector.

Components Needed

  • Arduino Uno
  • TowerPro SG90 Micro Servo (1.8kg-cm)
  • 4xAA battery holder + batteries (6V)
  • Male-to-female jumper wires (3 pieces)
  • 220μF electrolytic capacitor (noise filter)
  • Heavy-duty servo horn selection

Wiring to the Arduino Uno

Connect the signal wire to D9, and power the servo from a separate 5–6 V supply rather than the board. The 5 V logic level matches the servo signal input directly.

The grounds must be tied together. The servo supply ground and the board ground have to be common, or the pulse has no reference and the servo will twitch randomly or ignore commands entirely. This single mistake accounts for most "my servo is broken" reports.

Fit a 470 µF or larger capacitor across the servo supply close to the servo. The current surge when a servo starts moving drags the rail down, and on a shared supply that dip can reset the microcontroller mid-sweep.

Servo wireConnects toFunction
Orange / white (signal)D9Pulse-width position command
Red (V+)External 5–6 V supplyMotor power — not the board regulator
Brown / black (GND)Supply GND and board GNDShared reference, essential

Example Code

Smooth servo sweeping with the Servo library, moving in steps rather than jumps. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.

Smooth servo sweeping with the Servo library, moving in steps rather than jumps
#include <Servo.h>

Servo myServo;
const int SERVO_PIN = 9;

void moveTo(int target, int stepDelay) {
  static int current = 90;
  int step = (target > current) ? 1 : -1;
  while (current != target) {
    current += step;
    myServo.write(current);
    delay(stepDelay);          // controls speed; smaller is faster
  }
}

void setup() {
  Serial.begin(9600);
  myServo.attach(SERVO_PIN, 1000, 2000);   // min/max pulse width in microseconds
  myServo.write(90);                        // centre
  delay(500);
}

void loop() {
  Serial.println("sweeping to 0");
  moveTo(0, 15);
  delay(500);

  Serial.println("sweeping to 180");
  moveTo(180, 15);
  delay(500);
}

Applications

A servo motor turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Robot arm and gripper joints
  • Pan-and-tilt camera mounts
  • Steering on model vehicles
  • Valve, damper and vent actuation in automation
  • Animatronics and moving displays

Working with the Arduino Uno

The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.

With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.

The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.

Arduino Uno characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A5 (six channels)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • The servo jitters constantly — the grounds are not common, or the supply is sagging. Tie grounds and add the capacitor.
  • It moves to one end and buzzes — it is being commanded past its mechanical limit. Restrict the angle range in software.
  • The board resets whenever the servo moves — the servo is drawing from the board regulator. Give it its own supply.
  • Writing 90 makes it spin continuously — that is a continuous-rotation servo; 90 means "stop" only after trimming.
  • Range is less than 180° — cheap servos vary. Tune the min and max pulse widths in attach().
  • Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Uno

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:

The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.

Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.

Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.

Notes and Practical Limits

Stepping through intermediate angles, as the sketch does, is not cosmetic. Commanding a large jump makes the servo move at full speed and draw its peak current, which is exactly what browns out a shared supply.

The Servo library disables PWM on pins 9 and 10 on ATmega328P boards because it takes over Timer1 — plan pin assignments accordingly.