Problem in Communicate Arduino UNO with XBee, with API frame packet

Hi everyone . .

I have two XBee PRO-S2B ,an Arduino UNO R3, and LED. I set this XBees to become a Coordinator and End Device XBee.
I use XBee shield for arduino uno, and plug the end device XBee there, and the other one become coordinator XBee that connected to my laptop.
The idea is to remotely send a packet from my coordinator XBee to end device XBee, so when the end device XBee recieve that packet it will turn ON or OFF the LED on the arduino.

I try to send a packet with XCTU software, i want to make the LED on arduino ON when i send '1' in my packet, and when i send '2' the arduino LED is OFF, but it still doesn't work this is the code that i use

const int pin13 = 13;
int myData = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(pin13, OUTPUT);
}

void loop()
{
  if(Serial.available() > 0)
  {
    myData = Serial.read();
    //LED ON
    if(myData == '1')
    {
      digitalWrite(pin13, HIGH);
    }
    //LED OFF
    else if(myData == '2')
    {
      digitalWrite(pin13, LOW);
    }
  }
}

hope there is any information references or guidance to solve this problem.
thanks :slight_smile:

I use XBee shield for arduino uno

Which XBee shield? There are several, some of which are junk.

When in API mode, you are sending packets that contain many bytes of data, including the ID of the sender, etc.

You seem to think that you are reading AT data.

@PaulS

I use XBee shield from seeedstudio

Yes you’re right, i try to learn again about the difference when i use the API and AT mode, and finally understand how to make the program to read the API packet, and finally it works :D.
this is the code that i use

int pin13 = 13;
int readValue = 0;
void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop()
{
  if(Serial.available() > 16)
  {
    if(Serial.read() == 0x7E)
    {
      for(int i = 0; i<15; i++)
      {
        byte discard = Serial.read();
      }
      readValue = Serial.read();
      Serial.print("LED is = ");
      if(readValue == 117)
      {
        Serial.print("ON");
        digitalWrite(13, HIGH);
      }
      else if(readValue == 116)
      {
        Serial.print("OFF");
        digitalWrite(13, LOW);
      }
      Serial.println();
    }
  }
}

thanks :smiley: