Remote blink with 2 Xbees S1 and one Arduino Uno

Xbee Remote Blink Example

Hello all. After spending countless hours reading over Xbee material, untold examples, including the Digi examples at:
and all the Youtube vids by tunnelsup plus his Xbee S2 Quick Reference Guide, I finally have something to
contribute to help others who may be struggling like me.

I was suucessful at using the Digi 'Getting Started' examples, but I could not get any of the examples by tunnelsup to work because I did not understand what I was doing with the tools I had. Since I have a lot of the Xbee S1's I own, I needed to get these to function right for me no matter what. The race was on.

Also, I own both the Arduino Uno and the YUN. This example is based strictly for the Uno, but should be easy to convert to the YUN. I just haven't done it yet.

What do you need for this project?
1 ea Uno, plus USB connector cable for loading the program sketch
2 ea Xbee S1's (be sure to have antennas of some sort if you want range)
2 ea breakout boards (one for each Xbee-I am using the regulated ones from Sparkfun)

1 ea USB programming controller (mine is a cheap Filopino knockoff bought off Ebay)
X-CTU programming software-download free from Digi-

1 breadboard with power source for the remote Xbee
A handful of breadboard wires
1 led -any color
1 resistor for the led-220-ohm resistor to 330 ohm resistor
Wires and soldering tool if you want to make life easier for yourself-more on this later

I think it would be wise to see the videos from tunnelsup on Youtube to see how he sets up the breadboards and
solder wires onto the Xbees and Uses the X-CTU software. I won't go over all that. Start here at the first video
Please do not program your Xbee S1's according to his video or the code below will not work for you. His are S2 anyways and the X-CTU programming is slightly different, but be forewarned.

On to the Project

Setting up my Xbees-

  1. One is to be a Coordinator
  2. One is to be an Endpoint or Remote
  3. Each one has to be programmed accordingly

Programming using the newest X-CTU software and the USB programming controller is simple and almost painless.
Caveat- be sure the direction of the Xbee matches both the breakout board outline and the programming board outline.

I will not go over every single command available as it is way over my head and not necessary for what I am
showing, but again tunnelsup does a very good job showing some choices and the Digi is so helpful.

First program the Coordinator Xbee in API mode. I prefer to start in an unpowered state, then plug in to my USB port

PanID--choose any numbers appropriate to your example up to 0xFFFF-each Xbee should have the same number though
DH = 0
DL = 2
MY = 1
API = enabled

Next the Endpoint or Remote Xbee in AP mode
PanID - set same as above
DH = 0
DL = 1
MY = 2
IA = FFFF need this to be able to have another Xbee change pin settings
D5 = 4 -set to digital output low initially- will be controlled by our Arduino sketch thereafter

Be sure to use the Write function in X-CTU to get all these changes set on each of the Xbee S1's

The Sketch- modify as you see fit

//beginning of remote xbee blink
int led = 13;  //this is merely used as a condition reached indicator on the Uno board only

void setup() {  
pinMode(led, OUTPUT);

void loop() {
  digitalWrite(led,HIGH);  //turn on Uno LED
  setRemoteState(0x5);  //turning on the remote LED by Xbee for 5 seconds

  digitalWrite(led, LOW);  //turn off Uno LED
  setRemoteState(0x4);  //turning off the remote LED by Xbee for 5 seconds


//this function is used directly from tunnelsup example on Youtube-only modified with my code needs
void setRemoteState(char value) {

//what you are doing here is creating an API frame according to Digi standards and manipulating the remote Xbee
//based on what you desire--in this case, to change the HIGH/LOW state of the digital output pin D5
//Any number of functions like this could be created to deal with different conditions that may need to be
//addressed by your desires within your sketch.

  Serial.write(0x7E); //most commenting will be done below-but you can also read the XBee S2 Reference Guide by tunnelsup
  Serial.write((byte)0x0);  //Frame ID-not used

  Serial.write((byte)0x0);//start of first 4 bytes of 64 bit address =DH

  Serial.write((byte)0x0); //start of 2nd 4 bytes of 64 bit address = DL
  Serial.write(0x01);          //set to the DL of the preprogrammed Endpoint or Remote Xbee

  Serial.write((byte)0x0);      //start of 16 bit address 
  Serial.write(0x02);               //MY set to 2 of the preprogrammed Endpoint or Remote Xbee

  Serial.write(0x02);  //write AT commands
  Serial.write(0x44); //0x44 == 'D'-pin type
  Serial.write(0x35); //0x35 == '5' -pin number
//value is passed through the function when called
  long sum = 0x17 + 0x01 + 0x02 + b 0x02 + 0x44 + 0x35 + value;
//calculates checksum--the sum of the above addition is And'ed with 0xFF, then subtracted from 0xFF
  Serial.write( 0xFF - (sum & 0xFF) );

//end of remote xbee blink

have to post in 2 pieces r/t length requirements

2nd part-Explanation

Here is the data used in the construction of the frame as I removed it from the X-CTU Xbee API Frame Interpreter.

Remote AT Command Request (API 1)// API (1) means ‘without escapes’-please see the Digi manual download for the
Series 1 Xbees–Product Manual v1.xEx - 802.15.4 Protocol, in order to understand what ‘escape’ values are
included in this definition.

//my code below is verbatim pulled from the Serial.write(s) in the sketch shown above from the function
//void setRemoteState(char value)

7E 00 10 17 00 00 00 00 00 00 00 00 01 00 02 02 44 35 04 66

  • Start delimiter: 7E
  • Length: 00 10 (16)
  • Frame type: 17 (Remote AT Command Request)
  • Frame ID: 00 (0)
  • 64-bit dest. address: 00 00 00 00 00 00 00 01
  • 16-bit dest. address: 00 02
  • Command options: 02
  • AT Command: 44 35 (D5)
  • Parameter: 04
  • Checksum: 66 //in our case, the checksum itself will change according to the ‘value’ transmitted by the

void setRemoteState(char value)
But at least initially you should know how to calculate the checksum and use that knowledge when using the X-CTU

Xbee API Frame Interpreter or Generator. It will also change depending on what values are used in building an

API Frame.

Let me clarify some of the code as I used it for my own Xbee Remote Blink which again, was initially
demonastrated on the Youtube videos by tunnelsup. I just had to modify it to suit my needs.

Start delimiter: 7E //this is mandatory by the Digi code and must be included in your frame building at the
beginning of the code

  • Length: 00 10 (16)–//this is actually calcualted as you go along in X-CTU creating your API frame-10 in Hex =
    16 in decimal

  • Frame type: 17 (Remote AT Command Request) //there are 13 Frame types you can build using the 802.15.4
    protocol-this is the one needed to send requests to a remote (Endpoint) S1 Xbee using the API (1) mode from a
    Xbee Coordinator

  • Frame ID: 00 (0)–I did not assign a Frame ID-so no value here

  • 64-bit dest. address: 00 00 00 00 00 00 01 --first 4 bytes (00 00 00 00) are the DH portion of the
    destination address, while the next 4 bytes (00 00 00 01) are the DL portion of the destination address. In my
    example I assigned the DL = 1 when I programmed the Remote Xbee using the X-CTU software

  • 16-bit dest. address: 00 02–this is the MY address chosen arbitrarily when I programmed the Remote Xbee. See
    way above

  • Command options: 02–//this ‘Applies’ the changes to follow, ie ‘forces’ it to the Remote

  • AT Command: 44 35 (D5)–//this uses the digital pin D5–(D = 44 in ASCII Hex, 5 = 35 in ASCII Hex)

  • Parameter: 04 ///In X-CTU the term ‘value’ as we use it, is known as the Parameter value and could be missed
    if you don’t use the slider bar on the right side of the Frame Generator. Our initial value was set to ‘4’ which
    means the Digital Pin 5 was set to ‘Digital output low.’ Several other parameters are available.

Don’t forget-when you’re uploading the code to the Uno, be sure to disconnect the Xbee from the RX/TX pins or you will get an error. After the sketch is uploaded, then connect the Rx/Tx appropriately.

Some important caveats-if you did not see the Youtube vids by tunnelsup, then you will definitely have lots of extra questions. Do yourself a favor and see the vids please.
Going on, you have noticed that I did not use any Arduino shield for my Xbees. They aren’t needed. But something is needed to connect the Xbee to the Uno, right? And how about to the breadboard? Yes, indeed. This is where the wires and soldering came in way at the beginning of this paper.
The Coordinator Xbee which is connected to the Uno needs 4 wires to connect to it. One for Rx, one for Tx, one for power, and one for ground. That is it for this example.
The Remote Xbee only needs 3 wires in this example- one for power, one for ground , and one for the Digital output pin which connects to the LED power side on the breadboard. The easiest way to connect to the D5 of the Xbee is by soldering a short length of small guage wire to the D5 pin hole on the regulated Xbee board, then running that to the LED.

I hope this explanation helps someone who was struggling with this. There is more than one way to skin a cat as they say. Don’t give up. Please forgive any redundancies in explanation

Nice! Thanks for sharing. I wonder if the project will work just the same for XBee S2. We have done a similar project using an example of Faludi’s book “Building Wireless Sensor Networks”.