i dont get why this wont work.

 #include <Servo.h> 
 
Servo myservo;
int ledPin = 13;                // choose the pin for the LED
int inputPin = 2;               // choose the input pin (for a pushbutton)
int val = 0;                    // variable for reading the pin status
int pos = 0; 

void setup() 
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
     // declare LED as output
  pinMode(inputPin, INPUT);     // declare pushbutton as input
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
  for(pos = 0; pos < 180; pos += 8)  // 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 
  }  // turn LED OFF
  } else {
  for(pos = 180; pos>=1; pos-=8)     // 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 
  } 
  }
}

its a function for my auto dog feeder
what it does is when odie is nearby(odie = my dog) and the motion sensor isint covered in food(i programmed it by hacking it so it knows when he is eating)

but when he is nearby, the arduino feeds him by droping food in his dish!

this might help.

what is your specific question? you just seem to be detailing your project. Do you have coding issues, or queries as to how to organize your hardware?