The SG90 micro servo is one of the most popular hobby servos used in robotics and automation projects. Here are its key details:
- Weight:
~9 g (very compact and lightweight).
- Operating
Voltage: 4.8–6.0 V.
- Current
Draw: ~100–250 mA under normal load, higher at stall.
- Rotation
Range: ~0° to 180° (limited by internal mechanical stops).
- Control
Signal: Pulse width modulation at ~50 Hz.
- 1
ms pulse ≈ 0°
- 1.5
ms pulse ≈ 90°
- 2
ms pulse ≈ 180°
- Wiring:
- Red
→ VCC (5 V)
- Brown
→ GND
- Orange/Yellow
→ Signal (Arduino digital pin)
This servo is widely used in robot arms, pan-tilt camera
mounts, RC planes/cars, and small automation projects because of its low
cost and ease of use.
Wiring connection
- SG90
Red (VCC) → Arduino 5 V (or external 5 V supply for stability).
- SG90
Brown (GND) → Arduino GND.
- SG90
Orange (Signal) → Arduino Digital Pin 9 (commonly used).
Tip: If you plan to use multiple SG90 servos or apply
load, use an external 5 V supply with sufficient current capacity, and
connect its ground to Arduino’s ground.
Programming
SG90 with Arduino Uno
Arduino provides a built-in Servo library that
simplifies control. Below are two common examples:
1. Sweep
Example (basic test)
#include
<Servo.h>
myServo.attach(9);
// Signal pin connected to D9
}
void loop() {
for (int angle = 0;
angle <= 180; angle++) {
myServo.write(angle); // Move to
angle
delay(15); // Small delay for smooth motion
}
for (int angle =
180; angle >= 0; angle--) {
myServo.write(angle);
delay(15);
}
}
Output: This moves the servo back and forth across its full range.
2. Potentiometer
Control (manual angle)
#include
<Servo.h>
int potPin = A0; // Potentiometer connected to analog pin A0
void setup() {
myServo.attach(9);
}
void loop() {
int potVal =
analogRead(potPin); // Read
0–1023
int angle =
map(potVal, 0, 1023, 0, 180); // Map to 0–180°
myServo.write(angle);
delay(10);
}
How It Works with Arduino
- The
Arduino generates a pulse every 20 ms.
- The pulse
width (1–2 ms) tells the servo what angle to hold.
- The
SG90’s internal control circuit compares the shaft position (via
potentiometer feedback) with the commanded angle and drives the motor
until they match.
- This
closed-loop system ensures precise positioning without external
sensors.
Practical
Tips
- Use
external power if servo jitters or Arduino resets.
- Add
capacitors (100 µF–1000 µF) across supply rails to smooth current
spikes.
- Avoid
forcing rotation beyond 0–180°; it can damage gears.
- Mount
securely using provided horns and screws for stable operation.
No comments:
Post a Comment