Codey OnlineArduino & ESP32 component library › Servo SG90
Servo SG90
Actuators

Servo SG90

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.

Width: 66.3 mm

Pinout — Servo SG90

Pin Signal Description
GND Ground GND
VCC Power VCC 3V - 6V
PWM PWW signal PWM signal

Wiring notes

Requires PWM (signal), VCC (3–6V), GND. All three must be connected. VCC and GND go to driver V+ and GND.

Example wiring diagram — Servo SG90

From To Wire
board:GND x1:GND black
board:5V x1:VCC red
board:D9 x1:PWM green

Example Arduino code — Servo SG90

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

Build your Arduino or ESP32 project with AI

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