firmwareMIT

Arduino Uno: servo sweep

breadboardhub/arduino-servo-sweep
arduinounoservo
ShareXLinkedInFacebookRedditWhatsApp
B
Mike M
v1.0.0 · UpdatedNov 24, 2026 ·0 downloads ·0 forks
// Servo sweep: the Servo library turns the servo on pin 9.

#include <Servo.h>

Servo arm;

void setup() {
  arm.attach(9);
}

void loop() {
  for (int angle = 0; angle <= 180; angle += 2) {
    arm.write(angle);
    delay(15);
  }
  for (int angle = 180; angle >= 0; angle -= 2) {
    arm.write(angle);
    delay(15);
  }
}
Description

Turn a servo from 0 to 180 degrees and back. It compiles and runs on a virtual Uno in the browser. Make it stop at 90 degrees for a second at each end.

Cite this design
@design{breadboardhub/arduino-servo-sweep,
  title = {Arduino Uno: servo sweep},
  author = {breadboardhub},
  url = {https://www.breadboardhub.com/breadboardhub/arduino-servo-sweep},
  version = {1.0.0}
}