#include <Arduino.h>
// Servo.h provides the Servo class and its attach() and write() methods.
#include <Servo.h>

// Create a Servo object named servo so we can control one motor.
Servo servo;

// Set the signal pin and command the initial center position.
void setup() {
  // Attach the servo control signal to Mega digital pin 9.
  servo.attach(9);
  // A value near 90 requests the center angle; actual travel varies by servo.
  servo.write(90);
}

// Cycle through four target angles, pausing at each one.
void loop() {
  // Move back to the nominal center.
  servo.write(90);
  delay(500);
  // Move toward one side; do not force the servo horn.
  servo.write(30);
  delay(500);
  servo.write(90);
  delay(500);
  // Move toward the other side. Power the servo from the reviewed external supply.
  servo.write(150);
  delay(500);
}
