#include Servo myservo; // create servo object to control a servo int PIN=A0; // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { pinMode(PIN, INPUT); digitalWrite(PIN, HIGH); myservo.attach(3); // attaches the servo on pin 9 to the servo object } void loop() { if (digitalRead(PIN)) { myservo.write(90); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } else { myservo.write(180); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }