← Back to Basic Projects
Basic . Project #07

πŸ€– Servo Sweeper Bot

Make a servo motor sweep back and forth like a radar scanner using the Servo library.

πŸ“‹ Overview

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.

🧩 Components Needed

ComponentSpecificationQtyNotes
Arduino Uno R35V1
SG90 Servo Motor0???180??, 5V1Or MG90S for more torque
Breadboard + WiresHalf-size1
USB CableType A to B1

πŸ“– Step-by-Step Tutorial

1

Connect the Servo

Servo has 3 wires: Brown/Black -> GND, Red -> 5V, Orange/Yellow -> pin 9.
2

Upload the Code

The Servo library is built into Arduino IDE. No installation needed.
3

Watch It Sweep

The servo will sweep from 0?? to 180?? and back continuously.
4

Control with a Potentiometer

Replace the auto-sweep with analogRead(A0) mapped to 0???180 to control angle manually.
πŸ’‘
Powering a servo directly from the Arduino 5V pin is fine for SG90 (light load). For stronger servos, use an external 5V supply to avoid browning out the Arduino.

πŸ’» Arduino Code

servo_sweeper.ino
INO
// 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
  }
}

⭐Reviews & Ratings

β€”0 reviews
5β˜…
0
4β˜…
0
3β˜…
0
2β˜…
0
1β˜…
0
⏳

Loading reviews…