Hobby servo
A pulse width, not a duty cycle. The horn turns to wherever you send it.
- 3 pins
- 6 properties
Every one of its 3 pins
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 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.
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.
#include <Servo.h>
Servo myservo;
void setup() {
myservo.attach(9);
}
void loop() {
for (int pos = 0; pos <= 180; pos++) {
myservo.write(pos);
delay(15);
}
}The 6 properties you can set
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.
See the Hobby servo in a project
Shown here on: Arduino Uno R3
Where it turns up in a lesson
In a learn article
The rest of the bench
Every one of these is drawn and simulated the same way.
Wire up the Hobby servo
Open the editor and push it into the breadboard. It is free, and it runs on your own machine.