Instructables

how xbee serial work?

hello i read ultrasonic sensor serial connected to arduino but when i connect xbee between sensor and arduino and i configur my and dl matching and same id what i need to config else i work on 3,3v what i need to do to make it same as i read direct from sonar .

this is my code reading from sonar and convert to distance ,i need same work on 2 xbee between sonar and arduino.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(8, 9,true); // RX, TX
int BW=4;
char *buffer;
byte x;
char array[3];
int counter=0;
void setup() {
  // put your setup code here, to run once:
  // set the data rate for the SoftwareSerial port
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(BW,OUTPUT);
  digitalWrite(BW,LOW);
  delay(250);
  Serial.println("Calibrartion Cycle ");
  delay(150);
}

void reading(){

  mySerial.println(1);
while (mySerial.available())
{
   x= mySerial.readBytes(buffer,1);
   if(*buffer==0x52){
   x= mySerial.readBytes(buffer,1);
   array[0]=*buffer;
   x= mySerial.readBytes(buffer,1);
   array[1]=*buffer;
   x= mySerial.readBytes(buffer,1);
   array[2]=*buffer;
   }
}

delayMicroseconds(220);
}
void loop() {
  // put your main code here, to run repeatedly:
  reading();
  int Final_inch=(array[0]-48)*100 + (array[1]-48)*10 +(array[2]-48) ;
  float Final_cm=Final_inch*2.54;
  Serial.print(Final_inch);
  Serial.println(" Inch ");
  Serial.print(Final_cm);
  Serial.println(" cm ");
  delay(200);
}

Just look up how to set your Xbee modules into "transparent" mode. Serial in = serial out to your PC.