Ping Arduino Led and Switch

PaulS

Thank you so much for trying to give me A big Big hand in all of this. I think I got it, working.

The inpin and the outpin will be hooked up to I/O pins on one xbee. Line passing only... On one box=Arduino,xbee,resistor,and led.

#define trigPin 12
#define echoPin 13
const int InPin = 3; 
#define OutPin 4
#define LedPin 5



int buttonState = 0;
void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
 
  pinMode(OutPin, OUTPUT);
  pinMode(LedPin, OUTPUT);
}

void loop() {
  buttonState = digitalRead(InPin);

  int duration, distance;
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
 
 if (distance < 10)
 {
   digitalWrite(OutPin, HIGH);
 }
 else 
 {
 digitalWrite(OutPin, LOW);
 }
  
 if  (buttonState == HIGH && distance < 10) 
 {
        digitalWrite(LedPin, HIGH);
 }
         else
  {
       digitalWrite(LedPin, LOW);
  }
    delay(500);
}

Thank you..............PaulS