Part

Hobby servo

A pulse width, not a duty cycle. The horn turns to wherever you send it.

See every part
  • 3 pins
  • 11 settings
  • In 34 projects
  • In 10 lessons
Drawn live by the editor's own code, at the size you see it.
At a glance

The Hobby servo in brief

What it is, and every setting the properties panel gives it.

A hobby servo, SG90 style, turns its horn to an angle and holds it. Its signal wire does not take PWM in the dimming sense: the servo measures the width of each pulse, 544 microseconds for one end of its travel and 2400 for the other by the Arduino Servo library’s numbers, sent roughly fifty times a second. That is why analogWrite() on an Uno cannot drive one and the Servo library makes the pulse itself. Mokxi’s part times each pulse off the pin’s own edges and walks the horn towards the angle at the datasheet’s 0.1 seconds per sixty degrees, holds a width past either end of its window at that end, ignores one longer than 3 milliseconds as noise, and holds its position when the pulses stop. The window, the travel and the speed are all properties. What it does not model is current: a real SG90 can pull enough when it stalls to reset the board powering it, and nothing here will warn you about that.

Family
Outputs
Pins
3
model
custom (or SG90, SG92R, MG90S, FS90R, SG90-360)
min_pulse
544
the pulse widths for the two ends of travel, 544 and 2400 microseconds by default, the Arduino Servo library's MIN_PULSE_WIDTH and MAX_PULSE_WIDTH.
max_pulse
2400
the pulse widths for the two ends of travel, 544 and 2400 microseconds by default, the Arduino Servo library's MIN_PULSE_WIDTH and MAX_PULSE_WIDTH.
range
180
degrees of travel, 180 by default.
speed
600
how fast the horn moves towards a new angle, 600 degrees per second.
mode
positional (or continuous)
positional or continuous (below). rpm, neutral and dead_band are for the continuous kind only.
rpm
110
neutral
1500
dead_band
35
idle_ma
10
the supply current, 10 and 150 mA at 5 V.
moving_ma
150
the supply current, 10 and 150 mA at 5 V.

A circuit built around it, running and explained: the Servo simulator.

Pins

3 pins

Named as the editor names them, so a wire lands where you expect it.

Pin
Role
What it does
GND
Input or output
Ground, brown wire.
VCC
Input or output
Supply, red wire.
PWM
Input
Signal, orange wire: a pulse width, not a duty cycle.
How to use it

How to use a servo with an Arduino

Brown to GND, red to 5 V, orange to any digital pin. Then use the Servo library: attach() the pin once in setup() and write() an angle from 0 to 180 whenever you want the horn to move. The library’s calls compile here as they stand, with its own widths: write(0), write(90) and write(180) send 544, 1472 and 2400 microseconds, which the part reads as 0, 90 and 180 degrees, and attach(pin, min, max) sets another window.

On a real bench, give a servo its own 5 V supply once it is carrying any load, and join the grounds.

Part pin
Board pin
GND (brown)
GND
VCC (red)
5 V
PWM (orange)
Pin 9

ESP32Servo.h is the same class under the name ESP32 tutorials use, and the ESP32-C3 servo example drives one from a hardware PWM channel.

Arduino Uno: servo faderlive0.000 s 0.00x
Click to open it in the editor
This is the simulator itself, running here. Click anything to open it in the editor.
The Servo library sweep, as it compiles here
#include <Servo.h>

Servo myservo;

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

void loop() {
  for (int pos = 0; pos <= 180; pos++) {
    myservo.write(pos);
    delay(15);
  }
}
How it is modeled

What is true about the Hobby servo, here

In its help article’s own words: what the simulation gets right, and where it stops.

Modeled

The part is a stopwatch on one pin and a horn that walks towards the angle the stopwatch names: a rising edge starts the clock, a falling edge stops it, a width past either end of the min_pulse to max_pulse window is that end (the horn stops against its end stop), a pulse longer than 3 ms is treated as noise and ignored, and with no pulses at all the horn stays exactly where it is, the way a real servo does when its signal wire falls off. speed matches the datasheet's 0.1 seconds per sixty degrees. A servo that only sweeps 120 degrees, or one set up for 1000 to 2000 us, is those three numbers changed and nothing else.

Not modeled

The stall current (about 650 mA for an SG90 with the horn held against a stop): nothing here can hold the horn, so a servo pinned at the end of its window just arrives and goes idle. Nor the start-up surge, nor a brown-out of the board that powers it: Mokxi's rails have no impedance to sag. Below 4 V across VCC/GND the servo does not move at all.

No torque, no load and no overshoot. The horn walks to its target at a constant 600 degrees a second and stops dead. There is no acceleration, no settling, no hunting around the target and no gear backlash. A real SG90 ignores changes under about 10 microseconds of pulse width, the datasheet's dead band width. On custom there is no positional dead band, so a commanded angle is always reached. The named models ignore a change of 10 microseconds or less, about a degree on the default window, so a very small step can leave the horn where it was. The 0.1 seconds per sixty degrees is the datasheet's unloaded figure and applies here whatever is on the horn, because there is nothing on the horn.

The stopwatch is also more forgiving than a real servo's: the horn is updated every 20 ms whatever the pulse rate is, a pulse longer than 3 ms is discarded rather than treated as a fault, and a gap in the pulse train is simply held rather than released.

From Servo (hobby, SG90 style), in full.

Projects

See the Hobby servo in a project

34 built-in projects use it. Each opens in the editor, already wired.

Boards

The boards it is shown on

This board has a built-in project with the Hobby servo in it.

Boards

The Hobby servo on each board

The pins, the voltage and the code change from board to board. Each page has that board’s wiring and a circuit you can run.

Libraries

Arduino libraries for the Hobby servo

Built in, so the sketch compiles with nothing to install. Each page has the calls, the wiring and an example to run.

Wire up the Hobby servo

Open the editor and push it into the breadboard. It is free, and it runs on your own machine.