小编
Published2025-10-15
Exploring the Basics — What is the SG90 Servo Motor and How Does it Work?
Embarking on a journey into electronic and robotic projects often begins with understanding fundamental components, among which the servo motor holds a special place. The SG90 servo motor, a small yet powerful device, has gained an enormous following among hobbyists, educators, and emerging engineers. Its versatility, ease of use, and affordability make it an ideal starting point for anyone eager to bring movement to their projects.

What is the SG90 Servo Motor?
The SG90 is a micro servo motor made by various manufacturers that follows a standard design, featuring a tiny metal gear train, a coreless DC motor, and internal circuitry. Despite its modest size—roughly 23 mm in length—it can output approximately 1.8 kg/cm of torque and rotate through a range of about 0° to 180°, with some models capable of continuous rotation.
Its shape is typically rectangular with three wire leads: power (red), ground (black or brown), and control signal (yellow, white, or orange). These wires connect to a microcontroller, such as the Arduino Uno, which acts as the brain controlling the motor's position with precise signals.
Why do so many turn to this servo? First, it’s budget-friendly—often costing just a few dollars per unit. Second, it’s remarkably easy to interface with microcontrollers, thanks to a straightforward PWM (Pulse Width Modulation) control method. Third, its compact size makes it suitable for small robotic vehicles, arm projects, or automated devices, where space is at a premium.
Understanding PWM and Servo Control
The key to controlling the SG90 is understanding PWM signals. PWM involves sending pulses of varying width to the servo's control wire, which tell the motor to rotate to a specific angle. A typical PWM signal has a pulse width of 1 ms to 2 ms, repeating every 20 ms (or at a frequency of 50Hz). A pulse of 1 ms corresponds to 0°, 1.5 ms to 90°, and 2 ms to 180°.
This simple but effective method allows for fine positional control, making it ideal for robotic arms, grippers, camera gimbals, and more.
Getting Started with Arduino Uno and SG90
Before diving into the code, gather your materials: an Arduino Uno, an SG90 servo motor, a breadboard, jumper wires, and a power source. Connecting the servo is straightforward:
Connect the red wire to 5V on the Arduino. Connect the black/brown wire to GND. Connect the orange/yellow control wire to a PWM-compatible digital pin (commonly pin 9).
Always consult the datasheet or manufacturer's specifications to ensure correct wiring.
Safety and Power Considerations
Though the SG90 is small and typically draws minimal current, if you're controlling multiple servos or substantial loads, consider using an external power supply rather than powering servos directly from the Arduino’s 5V pin. Overloading the onboard 5V regulator can cause resets or damages.
First Simple Movement: Testing Your Servo
Once wired, testing your servo's movement begins with simple code: instructing the servo to turn to specific angles. This not only verifies your connections but also provides a delightful first experience of robotics automation.
Sample Code for Beginner Testing:
#include Servo myServo; // Create servo object to control a servo void setup() { myServo.attach(9); // Attach control pin 9 } void loop() { myServo.write(0); // Turn servo to 0 degrees delay(1000); // Wait 1 second myServo.write(90); // Turn servo to 90 degrees delay(1000); // Wait 1 second myServo.write(180); // Turn servo to 180 degrees delay(1000); // Wait 1 second }
Upload the code, and watch your servo move smoothly between positions. From here, you can build more complex behaviors.
Building Advanced Projects with the SG90 and Arduino Uno
Now that you’ve got a handle on how to make the SG90 move to predefined positions, the next step is to incorporate sensor feedback, create automated routines, or integrate it into a larger robotic system.
Creating Smooth Movements and Precise Control
One common requirement in robotics is moving a servo smoothly between two points, mimicking natural movement or precise positioning. To achieve this, you can write functions that incrementally change the PWM signal in small steps, creating gradual transitions rather than abrupt jumps.
void moveServoSmoothly(int startAngle, int endAngle, int stepDelay) { int step = (endAngle > startAngle) ? 1 : -1; for (int angle = startAngle; angle != endAngle + step; angle += step) { myServo.write(angle); delay(stepDelay); } }
This approach allows you to define movement speed, which is valuable for delicate tasks or human-robot interaction.
Adding Sensors for Autonomous Control
Enhance your project by integrating sensors like ultrasonic distance sensors, infrared detectors, or potentiometers. For instance, using an ultrasonic sensor, your robot can avoid obstacles by adjusting servo positions dynamically based on proximity.
#include #include #define TRIGGER_PIN 12 #define ECHO_PIN 11 #define MAX_DISTANCE 200 Servo myServo; NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); void setup() { myServo.attach(9); } void loop() { delay(50); int distance = sonar.ping_cm(); if (distance > 0 && distance < 50) { // Obstacle detected, turn servo to scan scanForClearPath(); } else { myServo.write(90); // Default position } } void scanForClearPath() { for (int angle = 0; angle <= 180; angle += 10) { myServo.write(angle); delay(100); // Read sensor again to check for open space } }
Incorporating such logic enables your robot to interact with its environment intelligently, moving beyond simple pre-programmed commands.
You might want to control multiple SG90 servos simultaneously, such as in a robotic arm or a camera gimbal. To do this, assign each servo to distinct pins and write routines that animate them in synchrony for complex tasks like grasping, pointing, or stabilization.
Servo servoBase; Servo servoElbow; void setup() { servoBase.attach(9); servoElbow.attach(10); } void moveArm() { servoBase.write(45); delay(500); servoElbow.write(90); delay(500); // Add more movements for complete sequences }
Timing and sequencing are critical here, but with careful planning, your robotic system can perform fluid and coordinated motions.
Power Management and Real-World Applications
In practical projects, managing power consumption and ensuring reliability are key. For example, in remotely operated vehicles or autonomous systems, dedicating an external power supply for servos prevents brownouts. Additionally, adding feedback mechanisms like potentiometers or encoders can improve precision and repeatability.
Designing with Constraints in Mind
While the SG90 offers many advantages, it also has limitations—torque caps, limited rotation, and sometimes noisy movement. For demanding applications, consider higher-torque servos or digital models. The basic principles remain the same, but you’ll need to adapt your code and hardware to accommodate these differences.
Innovative Project Ideas Using SG90 and Arduino Uno
Robotic Arm: Build a mini arm with multiple servos for picking and placing objects. Pan-Tilt Camera: Use two SG90 servos for horizontal and vertical camera control, perfect for surveillance or wildlife monitoring. Automated Greenhouse Ventilation: Use a servo to open and close vents based on temperature sensors. Musical Instruments: Create robotic melodies by tuning servos to pluck or press keys.
Engaging with online communities such as Arduino forums, Reddit’s r/robotics, or Hackster.io can accelerate your learning curve. Sharing your projects, troubleshooting tips, and innovative ideas will deepen your understanding and inspire others.
Conclusion: Infinite Possibilities
The SG90 servo motor paired with Arduino Uno opens doors to countless creative endeavors, from simple automation to complex robotics. Its simplicity belies its versatility—allowing beginners to dip their toes into the vast ocean of electronics and robotics, and empowering seasoned creators to prototype innovative ideas.
Whether you’re controlling a small robotic arm, building an interactive art installation, or developing a sensor-driven automation system, understanding and harnessing the capabilities of the SG90 opens up a world of possibilities. Small motor, big dreams—turn yours into reality.
Leveraging innovations in modular drive technology, Kpower integrates high-performance motors, precision reducers, and multi-protocol control systems to provide efficient and customized smart drive system solutions.
Update:2025-10-15
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.