Arduino Tutorial: Let’s make XBee talk!


I remember when I first was trying to setup wireless connection between two Arduino’s back in 2010. I used a lot of time searching the web for a good tutorial, just to find out there wasn’t any. There may be some tutorial out there now, but with this I want to give back to the internet what it has given me almost every time I can’t figure something out; a tutorial.

Wireless communication is still one of the coolest things I know of, and it opens up for so many possibilities! I will therefore, in this tutorial, show you how to setup and communicate wirelessly between two XBee’s Series 1. I will use OSX 10.8, but you could easily adopt this method to Windows or Linux. We will make a very simple program, because this tutorial will focus on setting up the communication. What you will use the wireless link to make is up to you – be freakin’ creative!

Pre requirements



(Yes, I am a Sparkfun whore, but hey – they have a good community, good customer service and short delivery time. The downside is that they are more expensive than for example Digi-Key. On the other hand, Sparkfun is a great place for beginners and prototypers (as myself).)

Step 1: Program the XBee’s


The first thing we need to do is to setup the XBee’s so they talk to each other. There are different ways to do this, but I found the easiest way is to use CoolTerm.

  1. Place one of your XBee’s in the Explorer board, and connect it to your computer with a USB cable
  2. Open CoolTerm and (1) press the “Option” button. Under “Serial Port Option” (2) press the “Port”-dropdown menu and choose your Explorer. The name is something like usbserial-AD025ES5. If you can’t see it there, press the “Re-Scan Serial Ports”-button. (Still can’t see it?: Are you sure you have installed the FTDI drivers?)
  3. Hit the (3) “Ok”-button and get ready for some quality time with the XBee.
  4. There are the four commands you need, to setup the XBee’s:
    1. ATMY: The XBee address. This needs to be different on the two XBee’s.
    2. ATDL: The destination address (the other XBee’s ATMY address).
    3. ATID: The PAN ID – this is the network the XBee’s will communicate in. This needs to be the same on both XBee’s.
    4. ATWR: Save the changes to the XBee.
    5. We are going to setup the XBee’s like this:
     XBee 1  1234  5678  2244
     XBee 2  5678  1234  2244
  5. Hit the “Connect”-button and write +++.  Don’t press enter, just wait a second and you will see ‘OK’. (The ‘OK’ means that the XBee is ready to receive commands. If you don’t type in a command within 10 seconds, the state will change and you have to write +++ again.)
  6. Write ATMY1234 and hit enter
  7. Write ATDL5678 and hit enter
  8. Write ATID2244 and hit enter
  9. Write ATWR and hit enter
  10. Hit the “Disconnect”-button
  11. Repeat the steps 5 to 10 for the second XBee (the only difference on the second XBee is: write ATMY5678 and ATDL1234 (In other words, the opposite of XBee 1))
  12. Close CoolTerm and remove the XBee Explorer from the USB port
  13. That’s it boy! Your XBee’s is ready.

Step 2: Program the Arduino


On the Arduino there is a built-in LED (digital pin 13). This pin is placed different on the UNO and Leonardo, see picture above. In this tutorial we will make this light up when the Arduino receives a wirelessly signal.

  1. Place one of the XBee’s on the shield and place the shield on the Arduino. On your XBee shield you have a switch where you can choose between DLINE and UART. Set the switch to UART.
  2. Plug your Arduino board to your computer and open the Arduino software
  3. Press “Tools” -> “Serial Port” and choose your serial port. Mine is tty.usbmodem1411 (yours will look the same but probably have different digits).
  4. Press “Tools” -> “Boards” and choose your board (Leonardo, UNO etc.)
  5. Paste in the code under (use the first one if you have Arduino UNO or the second if you have Arduino Leonardo) and hit the upload-button.
    //Arduino UNO XBee Test Code
    int led = 13;
    int temp = 0;
    void setup() {
      pinMode(led, OUTPUT);
    void loop() {
      if (Serial.available() > 0) {
        temp =;
        digitalWrite(led, HIGH);
        digitalWrite(led, LOW);
    //Arduino Leonardo XBee Test Code
    int led = 13;
    int temp = 0;
    void setup() {
      pinMode(led, OUTPUT);
    void loop() {
      if (Serial1.available() > 0) {
        temp =;
        digitalWrite(led, HIGH);
        digitalWrite(led, LOW);
  6. Let the Arduino stay connected to the computer

Step 3: Let em’ talk!


  1. Place the other XBee onto the Explorer and plug it in the computer
  2. Open up CoolTerm, choose the Expolrer board in the options menu and press ‘OK’ (step 2 and 3 in step 1)
  3. Press the “Connect”-button
  4. Write something (doesn’t matter what you write and you won’t see anything in the serial monitor space). You should see led pin 13 on the Arduino blink for a second.
  5. That’s it! You now have two XBee’s talking to each other!


What you will use the wireless connection for is up to you. Be creative, make something insane and give us a link to the creation in the comment field under!

And please, if you have some input to alternative solutions, some questions or if you just can’t make it work. Give us a heads-up in the comment field and we will respond.

Enjoy and Good luck!

  • Nicolas Mrad

    thanks a lot man. The best started tutorial there is :)

    • Norwegian Creations

      Thanks :)