Build it step by step
0 of 7 doneWire the servo
Connect power, ground and signal, with the capacitor near the servo.
Sweep first
Set SWEEP_MODE to true and watch the arm move 0 to 180.
Find where it stalls
Listen for buzzing at either end.
Narrow the limits
Raise MIN_US and lower MAX_US until the buzzing stops.
Switch to pot control
Set SWEEP_MODE to false and turn the pot.
Check the range
The pot's full travel should use the whole safe servo range.
Remove the capacitor
See if the Uno resets or the servo jitters when it moves.
How do you build a servo sweep and calibration?
Sweep a servo, find its real end points and map a pot to the full safe range. You need Arduino Uno R3, SG90 Micro Servo, Potentiometer 10 kΩ, Electrolytic Capacitor 100 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 7 steps and about 30 minutes.
- Level
- Beginner
- Time
- About 30 min
- Parts
- 6
Parts list
- Development BoardsBuyArduino Uno R3 × 1
- Motors & ActuatorsBuySG90 Micro Servo × 1
- PassivesBuy
- PassivesBuy
- PrototypingBuy
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Servo red wire | Uno 5V | Servo power |
| Servo brown or black wire | Uno GND | Ground |
| Servo orange or yellow wire | Uno D9 | Signal |
| 100 µF capacitor | Across 5V and GND near the servo, + on 5V | Absorbs the current surge |
| Potentiometer outer pins | 5V and GND | Reference |
| Potentiometer wiper | Uno A0 | Position input |
Code
Hobby servos are driven by a pulse every 20 ms whose width sets the angle, about 1 ms for one end, 1.5 ms for the middle and 2 ms for the other, but cheap servos differ. MIN_US and MAX_US set the limits the library uses. If the servo buzzes at an end, it is pushing against its stop: reduce the limits a little. A small servo like an SG90 can run from the Uno 5 V pin for light loads; for larger servos use a separate 5 V supply with a shared ground. Keep the servo clear of obstacles when testing, and do not hold the horn. Arduino IDE, board "Arduino Uno" (or "Arduino Nano" with processor ATmega328P).
Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Sweep, then pot control, with pulse limits you can change after finding the real end points.
#include <Servo.h>
Servo s;
const int MIN_US = 600; // start safe, then widen: standard is about 544
const int MAX_US = 2300; // standard is about 2400
const byte POT = A0;
const bool SWEEP_MODE = false; // true = sweep test, false = follow the pot
void setup() {
s.attach(9, MIN_US, MAX_US);
Serial.begin(9600);
}
void loop() {
if (SWEEP_MODE) {
for (int a = 0; a <= 180; a++) { s.write(a); Serial.println(a); delay(20); }
for (int a = 180; a >= 0; a--) { s.write(a); Serial.println(a); delay(20); }
} else {
int angle = map(analogRead(POT), 0, 1023, 0, 180);
s.write(angle);
delay(15);
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Sweep | Smooth movement from end to end |
| Limits set correctly | No buzzing at either end |
| Pot turned | Servo follows |
| Capacitor removed under load | More jitter or resets |
If it does not work
Servo jitters
Add the capacitor or use a separate 5 V supply.
Buzzes at an end
Narrow the pulse limits.
Does not move
Check the signal pin 9 and the ground connection.
Uno resets
The servo draws too much; use an external supply.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the servo sweep and calibration?
Arduino Uno R3, SG90 Micro Servo, Potentiometer 10 kΩ, Electrolytic Capacitor 100 µF, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).
How long does the servo sweep and calibration take to build?
About 30 minutes for a beginner maker, in 7 steps.
How do I know the servo sweep and calibration works?
Sweep: Smooth movement from end to end. Limits set correctly: No buzzing at either end. Pot turned: Servo follows.
Servo jitters: what should I check?
Add the capacitor or use a separate 5 V supply.
Buzzes at an end: what should I check?
Narrow the pulse limits.
Does not move: what should I check?
Check the signal pin 9 and the ground connection.
Uno resets: what should I check?
The servo draws too much; use an external supply.
