Ping servo/motor/led

Hello all, I am new to arduino, just wondering would it be possible to program arduino to activate a servo when an object comes within 2 feet of ping? if so how. Thanks.

Cheers, conner

Here you go! Please note that the PING))) related code is the one originally posted on the Arduino site and is not mine. I just trimmed it a bit for your needs. Hope this helps.
Cetken

#include <Servo.h> 

Servo myservo;

int pingPin = 7;

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  myservo.write(0);   // move the servo to position zero initially
}

void loop()
{
  long duration, inches, cm;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // We give a short LOW pulse beforehand to ensure a clean HIGH pulse.
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the PING))): a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);

  if (inches <= 24) // If object detected closer than 24 inches (2 feet)
  {
    myservo.write(90);   // move the servo to 90 position 
  }
  else
  {
    myservo.write(0);    // move the servo to back to position zero 
  }

  delay(100);
}

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING))), there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  return microseconds / 74 / 2;
}