小编
Published2025-09-16
Understanding the SG90 Servo Motor and Basic Wiring
The SG90 servo motor is a compact, affordable, and versatile component widely used in robotics, DIY projects, and automation. Whether you’re building a robotic arm, a solar tracker, or a camera gimbal, mastering its connection is the first step to bringing your ideas to life. In this guide, we’ll break down the SG90’s anatomy, wiring principles, and basic coding to get you started.
What is an SG90 Servo Motor?
The SG90 is a micro servo motor that rotates up to 180 degrees with precise angular control. It operates on a pulse-width modulation (PWM) signal, making it compatible with microcontrollers like Arduino, Raspberry Pi, or ESP32. With a stall torque of 1.8 kg/cm (4.8V) and a weight of just 9 grams, it’s perfect for lightweight applications.
SG90 Servo Motor: The star of the show. Microcontroller (e.g., Arduino Uno): To send control signals. Jumper Wires: For connecting components. Breadboard (optional): For prototyping. Power Supply: A 5V source (USB or external battery).
The SG90 has three wires:
Brown Wire: Ground (GND). Red Wire: Power (VCC, typically +5V). Orange/Yellow Wire: Signal (PWM input).
Connecting the SG90 to an Arduino
Let’s start with a basic circuit:
Power Connections: Connect the SG90’s red wire to the Arduino’s 5V pin. Connect the brown wire to the Arduino’s GND pin. Signal Connection: Attach the orange/yellow wire to a PWM-enabled digital pin (e.g., Pin 9).
Why PWM? Servo motors rely on PWM signals to determine their position. The width of the pulse (usually 1–2 ms) dictates the angle. For example:
1 ms pulse → 0 degrees. 1.5 ms pulse → 90 degrees. 2 ms pulse → 180 degrees.
Let’s write a simple Arduino sketch to sweep the servo from 0 to 180 degrees:
void setup() { myservo.attach(9); // Attach servo to Pin 9 }
void loop() { for (int pos = 0; pos <= 180; pos++) { myservo.write(pos); delay(15); } for (int pos = 180; pos >= 0; pos--) { myservo.write(pos); delay(15); } }
How It Works: - The `Servo.h` library simplifies servo control. - `myservo.attach(9)` links the servo to Pin 9. - The `loop()` function sweeps the servo back and forth. #### Troubleshooting Common Issues 1. Servo Doesn’t Move: - Check wiring (loose connections are common). - Ensure the code uses the correct pin number. 2. Jittery Movement: - Add a capacitor (10µF) between the servo’s power and ground wires. - Use a stable power supply. With these basics covered, you’re ready to explore advanced setups in Part 2! --- ### Advanced Configurations, Power Management, and Project Ideas Now that you’ve mastered the SG90’s basic wiring, let’s dive into advanced topics like external power supplies, multi-servo setups, and real-world applications. #### Why Use an External Power Supply? While the Arduino’s 5V pin works for a single servo, multiple servos or high-torque applications can overload the board. An external power source (e.g., a 5V battery pack or UBEC) ensures stable operation. Wiring with External Power: 1. Connect the servo’s red wire to the external supply’s +5V. 2. Link the external supply’s GND to both the servo’s brown wire and the Arduino’s GND. 3. Keep the signal wire (orange/yellow) connected to the Arduino. This setup separates the motor’s power from the Arduino, preventing voltage drops or resets. #### Controlling Multiple Servos To control multiple SG90s, use a servo shield or PWM driver (like the PCA9685). Alternatively, connect each servo to separate PWM pins. Here’s a code snippet for two servos:
Servo servo1; Servo servo2;
void setup() { servo1.attach(9); servo2.attach(10); }
void loop() { servo1.write(90); // Center position servo2.write(180); // Max position delay(1000); } ```
SG90s may not always align perfectly at 0 or 180 degrees. To calibrate:
Use myservo.writeMicroseconds(1500); for the center (1.5 ms pulse). Adjust values between 500 (0°) and 2500 (180°) microseconds.
Robotic Arm: Combine 4–6 servos for multi-axis movement. Smart Dustbin: Automate lid opening with a motion sensor. Sun Tracker: Use LDR sensors to align solar panels.
Troubleshooting Advanced Issues
Overheating Servo: Avoid continuous force; servos aren’t designed for 24/7 operation. Use a heatsink or cooling fan. Signal Noise: Keep servo wires away from power lines. Use ferrite beads on the signal wire.
The SG90 servo motor is a gateway to countless creative projects. By understanding its wiring, power needs, and control logic, you’re now equipped to tackle everything from simple gadgets to complex automation systems. Ready to innovate? Grab your servo, fire up your Arduino, and start building!
This two-part guide equips you with foundational knowledge and advanced techniques to harness the SG90’s potential. Whether you’re a hobbyist or a future robotics engineer, the journey starts with a single connection—so plug in and let your creativity spin!
Update:2025-09-16
Contact Kpower's product specialist to recommend suitable motor or gearbox for your product.