Code for button activated servo door. I found it on
forum.arduino.cc/ and hopefully it should work
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0; // variable to store the servo position
const int analogPin = 5; // pin that the sensor is attached to
const int threshold = 20; // an arbitrary threshold level that's in the range of the analog input
int ledPin = 9 ; // LED connected to digital pin 9
int ledPin1 = 10 ; // LED connected to digital pin 10
int ledPin2 = 11 ; // LED connected to digital pin 11
int ledPin3 = 3; // LED connected to digital pin 3
void setup() {
myservo.attach(5); // attaches the servo on pin 5 to the servo object
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
}
void loop() {
int analogValue = analogRead(analogPin); // read the value of the potentiometer
if (analogValue > threshold){
for(pos = 0; pos < 180; pos +=1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos >=1; 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
}
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin1, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin2, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(ledPin3, HIGH); // set the LED on
delay(1000); // wait for a second
delay(999999999); // wait for a lot of seconds
}
else{
myservo.write(0);
}
}