Hi
One last thing, how would I go about sending the I/O pin data, using Serial data. Using xbee's Dout and Din. Using Baud 9600. So I don't have to use Line Passing.
const int InPin = 3
#define OutPin 4
#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);
}