The SG90 is a small hobby servo actuator that moves to commanded positions using a PWM control signal. It typically requires three connections: a PWM signal, power supply (VCC 3–6V), and a common ground (GND) tied to the driver. The servo is commonly used with microcontrollers like Arduino and ESP32 for precise angle control.
| Pin | Signal | Description |
|---|---|---|
GND |
Ground | GND |
VCC |
Power VCC | 3V - 6V |
PWM |
PWW signal | PWM signal |
Requires PWM (signal), VCC (3–6V), GND. All three must be connected. VCC and GND go to driver V+ and GND.
| From | To | Wire |
|---|---|---|
board:GND |
x1:GND |
black |
board:5V |
x1:VCC |
red |
board:D9 |
x1:PWM |
green |
This example was written and compile-checked for the arduino-uno. Codey Online adapts it to any other supported board for you.
#include <Servo.h>
Servo sg90;
const int servoPin = 9;
void setup() {
Serial.begin(9600);
sg90.attach(servoPin);
Serial.println("SG90 servo demo starting.");
}
void loop() {
Serial.println("Moving to 0 degrees");
sg90.write(0);
delay(1000);
Serial.println("Moving to 90 degrees");
sg90.write(90);
delay(1000);
Serial.println("Moving to 180 degrees");
sg90.write(180);
delay(1000);
}
Describe what you want to build. Codey Online writes the code, draws the wiring diagram, compiles it and flashes your board straight from the browser.
Start for free