xbee s2 project


I’m using xbee s2 to send a 4 sensors data form one a arduino to another
but my receiver code had a problem

transmit code

// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include “I2Cdev.h”
#include “MPU6050.h”

// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for InvenSense evaluation board)
// AD0 high = 0x69
MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define LED_PIN 13
bool blinkState = false;

int f2 = A1; //analog pin 0
int f1=A0;
char s_str1[9];
char s_str2[9];
char s_str3[9];
char s_str4[9];
String str1,str2,str3,str4;
void setup(){
// join I2C bus (I2Cdev library doesn’t do this automatically)

// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)

// initialize device
Serial.println("Initializing I2C devices...");

// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

// configure Arduino LED for


void loop(){
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
int flex1 = analogRead(f1);
int flex2 = analogRead(f2);
int flex11= map(flex1, 225, 279, 180, 0);
int flex12 = map(flex2, 225, 279, 180, 0);
int vro = map(ay, -16000, 16000, 0, 179);
int vba=map(ax, -16000, 16000, 0, 179);
int flex112=constrain(flex11,0,180);
int flex122=constrain(flex12,0,180);
int vro2=constrain(vro,0,180);
int vba2=constrain(vba,0,180);
// read raw accel/gyro measurements from device
// Indicates the start of the message (e=motors, s=robot arm)

Serial.print(“z”);Serial.print(vro2); Serial.print("
");// Pinky

Serial.print(“s”);Serial.print(vba); Serial.print("
“);// Pinky
Serial.print(“y”);Serial.print(flex112); Serial.print(”
");// Pinky

Serial.print(“w”);Serial.print(flex122); Serial.print("
");// Pinky


Receiver code
void setup() {
// put your setup code here, to run once:

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>=21)
if (Serial.find(“z”))
int y=Serial.parseInt();
if (Serial.find(“s”))
int r=Serial.parseInt();

i’m a beginner an i’m about to graduated
please what is the problem ?

Most Arduino code and samples I have seen use the XBee modules in API mode. Part of your problem is that you have not indicated what your issue is?

An XBee ZB module is a Zigbee mesh module. In order to form a network and send data, one of the two modules must be a Coordinator. Have you verified that both modules are properly configured with one being a Coordinator and they are on the same network and can see each other?