Make a servo motor sweep back and forth like a radar scanner using the Servo library.
Servo motors are precision actuators that rotate to exact angles. The Arduino Servo library makes them simple to control — just tell it what angle you want (0–180°) and it goes there.
What you'll learn: Servo library, attach(), write(), angle control, and PWM signals.
Estimated time: 20–30 minutes. Difficulty: ⭐ Beginner-friendly.
| Component | Specification | Qty | Notes |
|---|---|---|---|
| Arduino Uno R3 | 5V | 1 | |
| SG90 Servo Motor | 0–180°, 5V | 1 | Or MG90S for more torque |
| Breadboard + Wires | Half-size | 1 | |
| USB Cable | Type A to B | 1 |
analogRead(A0) mapped to 0–180 to control angle manually.// Servo Sweeper — Volt X
#include <Servo.h>
Servo myServo;
int angle = 0;
int step = 2;
void setup() {
myServo.attach(9);
}
void loop() {
myServo.write(angle);
delay(20);
angle += step;
if (angle >= 180 || angle <= 0) {
step = -step; // Reverse direction
}
}