I'm trying to get a servo to move when something is near it

im using a ultra sonic range finder to activate the moving servo. Need help now please.

STEP-1: Post your objective (summary of project objective) STEP-2: Post your code

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott http://people.interaction-ivrea.it/m.rinott

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
Servo myservo2; // servo 2
Servo myservo1; // servo3

int pos = 0; // variable to store the servo position
Servo myservo3;
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object

myservo2.attach(7); // attaches the servo on pin 10 to the servo object
myservo1.attach(12); // attaches the servo on pin 8 to the servo object
myservo3.attach(6); // attaches the servo on pin 11 to the servo objec

}

void loop() {
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}
{
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 160 degrees
{ // in steps of 1 degree
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}

for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 120 degrees
{ // in steps of 1 degree
myservo2.write(pos); // tell servo2 to go to position in variable ‘pos’
myservo3.write(pos);
delay(10); // waits 25ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 120 degrees to 0 degrees
{
myservo2.write(pos);
myservo3.write(pos); // tell servo to go to position in variable ‘pos’
delay(10); // waits 30ms for the servo to reach the position
}

for(pos = 90; pos>=1; pos-=1) // goes from 160 degrees to 0 degrees
{
myservo1.write(pos); // tell servo to go to position in variable ‘pos’
delay(15); // waits 15ms for the servo to reach the position
}

for(pos = 120; pos>=1; pos-=1) // goes from 120 degrees to 0 degrees
{
myservo2.write(pos);
myservo3.write(pos); // tell servo to go to position in variable ‘pos’
delay(10); // waits 30ms for the servo to reach the position
}
for(pos = 0; pos < 90; pos += 1) // goes from 0 degrees to 120 degrees
{ // in steps of 1 degree
myservo2.write(pos); // tell servo2 to go to position in variable ‘pos’
myservo3.write(pos);
delay(10); // waits 25ms for the servo to reach the position
}
}

}

click the MODIFY button in the upper right of the post window. Highlight all you code. click the "#" CODE TAGS button on the toolbar above just to the left of the QUOTE button. click SAVE (at the bottom). When you post code on the forum, please make a habit of using the code tags "#" button.