Servo Motor Control
Overview
A library for controlling the position or speed of servo motors. Primarily used for steering in radio-controlled model cars and aircraft, also known as RC servo motors.


This is a different type of motor from industrial servo motors used in factory automation.
Compatible Modules
All RC servo motors including SG90, MG90S, MG996R, etc.
Supported GPIO
- Raspberry Pi 0~4
- Raspberry Pi 5
- BeagleBone Black/Green
- Jetson Nano
Commands
[INIT]
Configures initial settings for the servo motor.
Item | Type | Description |
---|---|---|
GPIO Pin or PWM Selection * | WRITE | Enter the GPIO pin number connected to the servo motor’s SIGNAL wire (orange or yellow) or select a PWM pin. |
Type | WRITE | Select servo motor type (Positional Rotation, Continuous Rotation). |
* Raspberry Pi 0~4: Enter GPIO number directly (all GPIO pins available)
Raspberry Pi 5, BeagleBone Black/Green, Jetson Nano: Select one of the PWM pins shown in the combo box.
Raspberry Pi 5, BeagleBone Black/Green, Jetson Nano: Select one of the PWM pins shown in the combo box.
Type: Positional Rotation
Item | Type | Description |
---|---|---|
Min Position Pulse Width(ms) * | WRITE | Enter the input pulse width when the servo motor is at minimum position. |
Max Position Pulse Width(ms) * | WRITE | Enter the input pulse width when the servo motor is at maximum position. |
Min Position(º) | WRITE | Enter the servo motor’s minimum position in degrees (e.g., 0º). |
Max Position(º) | WRITE | Enter the servo motor’s maximum position in degrees (e.g., 180º). |
Type: Continuous Rotation
Item | Type | Description |
---|---|---|
Min Speed Pulse Width(ms) * | WRITE | Enter the input pulse width when the servo motor is at minimum speed. |
Max Speed Pulse Width(ms) * | WRITE | Enter the input pulse width when the servo motor is at maximum speed. |
Min Speed(%) | WRITE | Enter the servo motor’s minimum speed as a percentage. For reverse rotation, negative values are possible (e.g., -100%). |
Max Speed(%) | WRITE | Enter the servo motor’s maximum speed as a percentage (e.g., 100%). |
* Pulse width according to servo motor angle or speed may vary by product, but typically:
– 1ms (min position) ~ 2ms (max position) or 0.544ms (min position) ~ 2.4ms (max position)
– If the motor doesn’t rotate to the specified angle, adjust the input pulse width according to the product specifications.
– 1ms (min position) ~ 2ms (max position) or 0.544ms (min position) ~ 2.4ms (max position)
– If the motor doesn’t rotate to the specified angle, adjust the input pulse width according to the product specifications.
[SET_POS]
Sets the position or speed of the servo motor.
Item | Type | Description |
---|---|---|
Position(º) | WRITE | Enter the servo motor position. Displayed when type is “Positional Rotation”. |
Speed(%) | WRITE | Enter the servo motor speed. Displayed when type is “Continuous Rotation”. |
Example
Objective
When the user changes the dashboard slider widget value between 0-180, the servo motor rotates to the corresponding angle.
Parts
Part | Quantity |
---|---|
Raspberry Pi 4 * | 1 |
Servo Motor (SG90) | 1 |
DC Power Supply | 1 |
* Other compatible hardware may be used. See Supported GPIO for details.
Wiring
Connect each pin to the corresponding connection as listed in each row below.
DC Power Supply * | Servo Motor | Raspberry Pi |
---|---|---|
+ | VIN (Red) | |
– | GND (Black or Brown) | GND |
| SIGNAL (Orange or Yellow) | 17 |
* Use an appropriate external DC power supply considering the servo motor’s voltage and current consumption.
