I'm trying to make project to monitor my home. I am using some gas sensors and temperature and humidity sensors. I want to do this wirelessly and I think the best thing to do that is XBee.

I use this code for the transmitter Arduino:

char dataPacket[64];

int gx = 1;
int gy = 321;
int gz = 456;
int ax = 654;
int ay = 789;
int az = 987; 
int mx = 147; 
int my = 258; 
int mz = 369;

void setup(){



void loop(){

   sprintf(dataPacket, "X%d" ,gx);
    //  sprintf(dataPacket, "A%dB%dC%dD%dE%dF%dG%dH%dI%d", gx, gy, gz, ax, ay, az, mx,     my, mz);


gx gy gz .... these are the sensor reading variables

and in the receiving Arduino I use this code

void setup(){
    // Start up our serial port, we configured our XBEE devices for 9600 bps.

void loop()

    if(Serial.available() > 0)
     while(Serial.available() > 0)
        char dataPacket[64];

for (int i = 0; i < 64; i++)
  dataPacket[i] = Serial.read();


String show = Serial.readStringUntil('C') ;


but i can't split the values from the stream and put them into their variables (gx gy ...)

Does anyone have idea how to split it?


Try a communication protocol with a , as a delimiter like:


And use the Messenger library to parse it.

See my answer on comms protocols here:

Communication Protocol Best Practices and Patterns

An how to use the Messenger library here:

Send Processing color data into Arduino

  • You may be able to use sscanf() which works like a backward sprintf(), to assign the values from the input string into each variable. – JRobert Nov 3 '14 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.