#include Servo myservo; // create servo object to control a servo #define SERVO_PIN 9 // Servo control pin void setup() { myservo.attach(SERVO_PIN); // attach the servo to the specified pin Serial.begin(9600); } void loop() { for (int pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (int pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }