Part

Hobby servo

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

or see every part
  • 3 pins
  • 6 properties
Drawn live by the editor's own code, at the size you see it.
Reference

Every one of its 3 pins

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.
This part

What it does

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, about 1 millisecond for one end of its travel and 2 for the other, 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, ignores a width outside its window 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.

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; its default pulse window is the SG90’s 1000 to 2000 microseconds, and attach(pin, 544, 2400) gives the upstream library’s.

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);
  }
}
Reference

The 6 properties you can set

Property
Default
What it means
min_pulse
1000
the pulse widths for the two ends of travel, 1000 and 2000 microseconds by default.
max_pulse
2000
the pulse widths for the two ends of travel, 1000 and 2000 microseconds by default.
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)
rpm
110
How it is modeled

What is true about the Hobby servo, here

What is 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 outside the min_pulse–max_pulse window 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 that wants the Arduino library's default 544–2400 us window, is those three numbers changed and nothing else.

Not modeled

Current. A real SG90 pulls a quarter of an amp when it stalls and can brown out the board driving it (the single most common reason a servo project misbehaves on the bench), but Mokxi's supply rails have no impedance to sag, so a sag here would be a lie about something that cannot happen in this simulator. VCC/GND are read for one thing only: below 4 V 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, no dead band (a real SG90 ignores changes under about 5 microseconds of pulse width) and no gear backlash, so a commanded angle is always reached exactly. 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

Shown here on: Arduino Uno R3

Learn

Where it turns up in a lesson

In a learn article

Wire up the Hobby servo

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