Outputs

Servo motor control with Arduino

A hobby servo turns to a commanded angle rather than spinning freely. It listens for a precise pulse train, not a generic PWM dimming signal.

22 November 20266 min read
A hobby servo motor with signal, power and ground wires connected through a breadboard to an Arduino
A servo connects with three wires: signal, supply and ground. The supply current should not come from the board regulator.

Bu projeyi gerçekten kurmak istersen parçaları hobidevre.com'dan temin edebilirsin →

Build it for real

To build this project for real, get the parts from hobidevre.com → hobidevre.com →

More build guides: hobidevre.com/blog

The pulse that sets an angle

A standard hobby servo expects a pulse every 20 ms, which is a frequency of 50 Hz. The width of the pulse inside that period carries the command: roughly 1.0 ms means 0°, 1.5 ms means 90° (the neutral position), and 2.0 ms means 180°. The mechanism compares that width with an internal feedback signal and drives the motor until the two match.

This is different from LED dimming. A dimmer cares about the percentage of time the pin is high; a servo cares about the absolute width of one pulse. Using analogWrite() will not position a servo reliably.

Power it separately

The three wires are signal, +5 V and ground, though colours vary: signal is often orange, yellow or white; +5 V is usually red; ground is brown or black. Confirm your servo's markings rather than trusting colours alone.

A servo can draw far more current than a board's 5 V regulator can supply, especially when it starts moving or stalls. Use a separate 5 V supply sized for the servo and connect its ground to the Arduino ground. Without that shared ground the signal has no reference and the servo may jitter or ignore commands entirely.

Add a small electrolytic capacitor, for example 100 µF, across the servo supply near the servo to soften current spikes. Check the capacitor polarity: the striped lead goes to ground.

Sweep with the Servo library

#include <Servo.h>

Servo kol;

void setup() {
  kol.attach(9);
}

void loop() {
  for (int aci = 0; aci <= 180; aci += 15) {
    kol.write(aci);
    delay(200);
  }
  for (int aci = 180; aci >= 0; aci -= 15) {
    kol.write(aci);
    delay(200);
  }
}

The library generates the 50 Hz pulse train in the background, so your loop only chooses an angle. Use a PWM-capable pin where the library requires one, and avoid blocking delays if other timing matters in your project.

Mechanical care

  • Let the servo reach its position before applying a load to the horn.
  • Do not command it beyond its mechanical stops; forcing the gear train strips plastic gears.
  • If the servo hums and heats up while held at one angle, it is fighting a load — reduce the load or change the design.
  • Use the supplied horn screws and mount the servo firmly; a loose mount turns small movements into vibration.

Quick fault checklist

  • Jitter or no movement: missing common ground.
  • Board resets when the servo moves: supply current too high; use a separate supply.
  • Moves only one way: check that the signal wire is on the pin used in attach().
  • Buzzes constantly: mechanical stall or a command outside the usable range.

Get the parts

If you want to build this project in real life, you can get the parts from hobidevre.com.

Frequently asked questions

Can I power the servo from the 5 V pin?

Only a very small servo under light load. A separate supply avoids board resets and is the safer default.

Why does it jitter?

Most often a missing shared ground or an unstable supply. Check both before changing code.

Is this the same as PWM dimming?

No. Dimming uses duty cycle; a servo reads the absolute pulse width in a fixed 20 ms frame.

Related reading

Practise in the browser

Open the same layout in the simulator and follow the steps. Sign in to save your work.