BLOG > Tutorial 9 for Arduino: Wireless Communication

This tutorial was featured on the official Arduino blog on 3/9/2011

This week, we go wireless! We’ll be using a set of arduino Unos, XBee shields, and XBee Transceivers that will create a Personal Area Network (PAN) for wireless serial communication. By the end of the episode, we will be able to turn a potentiometer on one arduino, and have it adjust a motor connected to a another arduino – all wirelessly! I suggest you pick up one of these Sparkfun XBee USB Breakout Boards to get your XBee addresses set up. Enjoy the video :)

EDIT:
Serial.flush() has changed in Arduino 1.0.  You can use the following instead:
while(Serial.available()>0) Serial.read();

You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.

387 comments

1 2 3 6
  1. I’ve been waiting for new part whole day today! Keep the spirit and make 2.000.000 parts of it :-) Thanks and kind regards from Slovakia!

  2. i m new to arduino and want to kno all arduino function used for arduino programing so that i can make my own program

  3. Hey! I ordered a couple of of Xbees a while ago and I am still waiting for them to get here. In your video, you connected 2 arduinos together via xbee and serial communication. What I was wondering is if you can connect the xbee to your computer and arduino, to have your computer and arduino transmit data wirelessly. For example, In your tutorial about serial communications (tutorial 6 i think), could you attach an xbee to the arduino and have an xbee connected to the computer, so that you could either turn on the LED (pin 13) from your computer wirelessly. OR . commuicating wirelessly to use that ‘processing’ program to change the colour of the window.
    thanks fro the help
    -brandon

  4. Hey Jeremy,

    Just wanted to let you know that your tutorials are the best that I’ve seen. Good work and thanks for all your efforts. Please don’t stop making these! Why only 10?

  5. Hi Jeremy, I have 2 of the XB24-Z7WIT-004 modules and trying to replicate your session, but the ATMY field is read-only according to both the device and manual. I was wondering what the difference is between your modules used in the session and mine.

    Regards,

    Kiwi

  6. Hi,

    Thanks for the great tutorials.
    Is it possible to use xbees for simple communication without any configuration?

    dan

  7. Jeremy, you freakin’ rock. I’ve been farting around with learning electronics from the ground up (Ohm’s Law and going from there), but it was great to take a little jump straight into the fun stuff for a while. Got my XBees programmed and talking to each other. I really appreciate you putting these tutorials online.

  8. Hi Jeremy,

    I wanted to know if the XBee shield is necessary to use those Xbee modules. I am planning on a project that requires wireless communication between my arduino and computer. I plan on buying an XBee USB Dongle to communicate with the a 1mW Antenna module on the arduino.

    -Ian

    1. You don’t need the shield. You can wire the radio to the arduino TX/RX lines directly. Just make sure you use a seperate 3.3V supply to power the Xbee – it will not run on the 5V that the arduino does. Its comm lines are 5V tolerant though.

  9. hey ,
    i have two xbee s1, they are config right because the test program from digi works. plus when i program on xbee i can see the assembly code on the other terminal. but ur example for doesnt work, 9600 baud rate

    i can see the 0-9 on the serial terminal

    when i dont use the xbees, it works just using the tx rx connected to the opposite on the other ardunio

  10. Hi Jeremy,
    If i am setting up the Xbee with arduino uno board then do i have to remove the microcontroller during setting up the xbees ?

  11. Hi Jeremy,

    I’m currently trying to read the value of a switch from one wireless xbee to turn on an LED on the other. whilst it kind of works it sometimes throws up some strange values when reading. Do you still need to add debounce to the switch?

  12. Hi

    When I connect the sparkfun useb adaptor with the Xbee on I cant find any COM Port connection shown in my device manager…any ideas why? I am running on windows7 64bit

      1. yes I do and it is the one with the FTDI chip..because this doesnt work I am using the arduino board to programm them by removing the processor and also placing the pins on the shield on the outer ones. this seems to work fine as it is recognised in putty. on the other hand i have a new problem as I type ATMY1000 it shows an error…..I dont know if it is coz of my xbees as they are the pro 2zb…if you could help me with this it will be greatly appreciated…PS:
        by the way thanks for your reply – awsome work

        1. If your sparkfun board isn’t being recognized at all by the computer, there could be something wrong with it? You should speak with Sparkfun about a replacement or refund.

          What is the error message you get using ATMY?

  13. Is it a Series 2 xbee as I believe these are programmed differently and require one as a coordinator and the other as a end device. I used x-CTU to program them on windows instead of terminal in mac, which was a lot easier.

  14. Is it possible that one Arduino board communicates with computer via serial port and at the same time communicates with another Arduino board via xBee?

    1. Yes, but you’ll need multiple serial ports, which the mega offers, but the uno does not. You’ll need to manually wire an XBee up to TX and RX 1 on the Mega without using a shield. RX and TX 0 will be used for communication with the computer. You can also accomplish this on the Uno using the software serial library.

  15. Hey there Jeremy,

    Wicked tutorials thanks for the info.

    Im an electrician first time user into this programming business and am getting it slowly.
    I was wondering to write from my Arduino Uno via Ethera net cable to router to Wifi Iphone application?? Ive seen this done on YouTube but have no idea where to start.

    Im looking into writing an app for iphone and also looking into this Arduino programming…

    Keep up the good work

  16. Oh P.s im trying to switch domestic lighting throughout the house is my main goal and on from there…

    cheers

  17. Can I use this set up to control 2 servos form the one board for a camera controller? Also what will I need to do the code to replace the inputs from the pots with acceleration sensor data?

    1. Yes, you’ll just set up two servos objects, each with a different name and pin. Are you getting the acceleration data from an accelerometer as analog inputs? If so, you would read it the same way.

      1. Yes, I plan on the acceleration data being put in through the analog inputs on a nano. Thanks for the amazing info and videos. Oh also, have you heard any thing about the XBee alternative called the RFBee? I was thinking of using this with a XBee adapter instead since it would be cheaper,smaller and is compatible with all XBee shields. I was hoping there would also be not as many problems.

  18. I have a question.
    I somehow can’t get OK when I type three +s at the beginning
    do u know what’s wrong?

      1. I am having the same problem. When I type the three +’s I never get the ok. This has happened with both Xbee modules. There is a light on on the sparkfun board but no blinking. What would you suggest?

  19. Hi Jeremy, great tutorials!
    Is it possible to use one receiver and several transmitters? How the transmitter can know from which XBee module the date is coming from?

    1. Yes that is possible, and I have done it, but you have to be careful to avoid data collisions. You can identify where the data came from by transmitting an id before each chunk of data, and reading it on the receiving end.

  20. Hi Jeremy. Awesome stuff! Do the two XBee’s constantly communicate? If you haven’t moved the POT is there still data being transmitted between the two? Is there a way to limit that so that the POT board only transmits when the POT is changed?

  21. Hi,
    I have xBee s2 module ant the ATMY command does not return an Ok. It returns an Error. I red on some forum that ATMY command is not supported on xBee second series. Is there any work around?

    Regards

  22. Hi,
    I managed to configure the xbees at 57600 baud rate.I used 57600 because xtcu was not able to communicate with xbee at 9600.
    Does this make any change ?

  23. Hey Jeremy,

    Thanks for the tutorials – I’m reasonably new to Arduino’s after doing a lot of ‘conventional’ programming and your stuff is very nice to follow.

    I was wondering, here you have 2 xbees communicating and you had to tell each the ID of the other so they would communicate. Can you have multiple xbees talking? Say have 4 talking to each other? How would you do this?

    1. Thanks James.

      With the Series two Xbee’s you can do a complete mesh network – so yes.

      With the series 1 Xbees, you can’t quite do that (easily) but you can have one master and several slaves. By giving each of the slaves the same ID, I’ve been able to get a bunch talking. You just have to be careful for conflicting signals if you are allowing the slaves to transmit as well as receive.

  24. Thanks for the tutorial! Very helpful. I have an arduino uno, sparkfun XBee shield and an Xbee s1 tranceiver. I should be able to communicate with the Xbee (as long as I tell my Xctu to look for those default config settings) without configuring anything with the explorer correct?

  25. Hi Jeremy, first of all: AWESOME tutorials! thanks for all the info and specs about Arduino’s programming, hardware, sensors, etc. Secondly, I have a question: is the Xbee Shield compatible with the Mega? I’m currently using an Uno board, but I’m going to buy a Mega for a project I’m working on that involves wireless communication and I haven’t found info about compatibility between that board and that shield. You would save my life, LOL!!!

  26. Hi Jeremy! I really like the tutorial video #9. You explained it in the most simple way as possible. Anyway, I just want to ask how I can communicate to my Arduino wireslessly using my PC. I’ve been trying to integrate a GPS system to the project by having the computer as the remote controller for the car while the first XBEE serves as the brain of the car which will then prompt the second XBEE to send the GPS coordinate to the first XBEE. The coordinate value will be viewed from the console of the ARDUINO software. My problem here is that I can’t communicate with the XBEE through my PC without both jumpers being set at USB mode in the XBEE shield. Help please!

  27. Jeremy, this has been an awesome experience thus far.

    I was wondering if you knew if you could host 2 xbee comms on the same board? What I’m thinking is having a wifi board talking to the internet, and a series 2 board talking to a sensor mesh… but I think the boards both use the same pins outs on the Unos, 11 and 12 for the v1.1 xbee shield, and 10-13 with the Wifi shields. Do you know of any way to change what pins it needs to use? Or any other work around?

  28. hola jeremy…

    Quisiera saber si tienes una configuracion arduino xbee..ya que estoy haciendo un proyecto para la captacion de informacion con un sensor de temperatura.

    En estos momentos tengo 2 arduinos uno, 02 xbee serie 1, 02 adaptadores XBee Explorer Regulated.

    he buscado mucho por la web, no encuentro nada como tranferir la informacion del sensor hacia la tarjeta receptora de informacion..

    Agradeceria mucho si me pudieras ayudar.

    buena suerte

    1. hi jeremy …

      I wonder if you have an arduino xbee config .. and I’m doing a project for the collection of data with a temperature sensor.

      Right now I have 2 Arduino Uno, 02 xbee series 1, XBee Explorer Regulated adapters 02.

      I searched a lot for the web, there is nothing as transferable sensor information to the receiver card information ..

      Grateful if you could help me.

      good luck

  29. hi Jeremy,

    Thx for those awesome tutorials! Currently i’m having some issues with my “bluetooth bee”…I bought a xBee shield and bluetooth bee but i really don’t know how to set up a connection with my laptop. Could you help me out?

    grtzz michael

  30. Hey Jeremy,

    We are a group of ECE students studying on a project that expectantly should do these things:

    Monitor soil moisture and soil temperature in a certain plant bed, kind of a plant growth monitoring.
    We are considering to transmit our data in wireless considering also we are using an Arduino microcontroller..

    Could we know where we could start?

    Thanks…

  31. Hi Jeremy,

    Thanks for the tutorial. It was excellent. I am trying the same for a project I am doing and having trouble getting it to work. The Sender is sending the number 2 over the Serial port. The receiver is reading the Serial data as -48. Any help would be appreciated. I have copied the Sender and receiver code. Any pointers on why this is not working would be appreciated.

    Sender:
    ———
    void loop()
    {
    int val = 2;
    Serial.println(val);
    delay(5000);
    }

    Receiver:
    ————
    void loop()
    {
    while( Serial.available() == 0);
    int data = Serial.read() -‘0’;
    int pos = map(data, 0, 9, 0, 180);
    pos = constrain(pos, 0, 180);

    Serial.println(data);
    Serial.flush();
    }

  32. Since I have not heard back on my post I assume the information provided is inadequate. While following your tutorial and configuring the XBee’s I was getting an error when executing the ATMY command. It could be that is the issue with the communication between my 2 Xbee’s. When I read the XBee parameters using X-CTU I do not see a MY parameter. All, I see is the DH and DL parameters which are set to 0 and FFFF respectively. Any tips on how to configure the XBee since the ATMY command is erroring out. Also, I have the XBee Pro 900 and it seems to be different from the one you used. Could this be a problem?

  33. Hello Jeremy,

    Thanks very much for putting these tutorials together; as others have said, they are great source of information.

    I tried the links to the XBee Shield and Transceiver in the Parts List but it seems as though these parts are no longer carried by element-14. Is that correct and, if so, could you recommend another shield? Could you also indicate which model Transceiver you used?

    Thanks again,
    Rob

  34. Hello Jermy,

    I’m working on a project where there are two Xbee’s connected to lilypad Arduinos. I’m trying to get an LED to turn on on Xbee #1 when a button on the Xbee #2 unit is pressed, and if a button on xbee unit #1 is pressed the light on xbee# 2 would turn on.

    I’m really new to Xbee and arduino, so the code im sure is super hacked, but would be greatfull if you could help me with this bi-directional led project.

    Thanks Randy.

    //led_button_xbee_code

    const int buttonPin = 2;
    const int ledPin = 13;
    int buttonState = 0;
    int incomingByte = 0;

    void setup() {

    Serial.begin(9600);
    pinMode(ledPin, OUTPUT);
    pinMode(buttonPin, INPUT);
    }

    void loop ()
    {

    buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH)
    Serial.print (1);
    else
    Serial.print (0);

    if (Serial.available() > 0)
    incomingByte = Serial.read();

    if(Serial.read() >= 1);
    digitalWrite (ledPin, HIGH);

    }

  35. I appreciate your work on the blog…i would like you to tell me if i can make a repeater kind of a system between the two XBees and also could you tell me that is it necessary that the two modules are placed in line of sight…will the data be transferred even if there is a huge barrier in between…

    1. They do not need to be line-of-sight. Communication distance will depend on the kind of antennae your xbee has, and what material the obstacle is made out of. It should be possible to do a repeater…

      1. thanks alot…could i make one repeater without using uno…i want the repeater cost to be as low as possible…

  36. hello Jeremy,

    I added the while serial.read() into the begining of the void loop, but still doesn’t work.

    With the code writen as it is above, pin 13 LED comes on right away without the button pressed on.
    With the code modified to have the serial.read() the led doesnt light up at all even if the button is pressed.

    Any suggestions what working code might look like or where i could find out?

    Thanks again, I think your tutorials are great.. keep up the good work.

    Randy

    1. Put it at the end of the loop. By putting it at the beginning, you’re emptying the buffer before you even read. You should put a delay at the end too.

  37. Hi Jeremy,

    All my hardware was delivered and I built the project in your tutorial–works great! However, I’m wondering if you could explain what would be required to send more than 1 char over wireless.

    What I’m trying to do is control 2 servos, mounted together as a tilt/pan camera mount, via a joystick. I have this built on 1 Arduino, but would like to do it using wireless.

    Thanks for any guidance.

    Rob

    1. issue the read() command twice. The first time will get the first char from the buffer, the second time, it will grab the second char. Use serial.available to ensure that there are 2 things in the buffer before you try to read.

  38. Hi Jeremy

    I have two XB24-ZB’s with Chipped Anttena’s, 2.4′ TFT LCD Touch Shield v1.0 with SD Slot and Arduino R3 Board.

    Please can you explain, how you go about uplaoding images to the SD Card via xbee and display it on the TFT Touch?

    thanks
    Vaughn

  39. Hi jeremy

    I was wondering how to control several Xbee using just my arduino one
    how can you program this problem?

    I’d been trying whit a waspmote control and I’m able to do it
    but I haven’t been able to do it with arduino one

    would you be so kind to help me out
    by the way your tutorials rock!!!

    1. Do you mean attaching multiple radios to one arduino? You can do it by using software serial ports, or the multiple serial ports on the mega, but I wouldn’t recommend it – the XBees are very power hungry.

  40. is it possible to read an array? cause i’ll be sending [8byte 8byte 8byte] array using bluetooth module. how can i get the three values and store it?

  41. hi , i m harpreet , i m doing a project on developing a wireless gamepad using arduino , in oder to play java based games on pc , but i m finding difficult to develop communication link between my blutooth UART module and my pc .
    i was hoping that you can give me some idea(coding) how to go about !!!!!

  42. Hi Jeremy,

    So the problem I’m facing is trying to get raw data (specifically off of a sparkfun product used to obtain heart rate data) onto another arduino that would be located at another location. I was wondering if you knew how we can get the two arduino boards to communicate with each other whenever they are in range. It would only need to be a one way communication with the raw data being transmitted to the other location which would receive the data

    1. Just have the transmitting arduino send data once per second (for example), and the receiving arduino always checking and clearing its buffer for data.

  43. I see I should not use serial.flush. Could you please show me what the entire motor arduino program would look like with the change? Thanks in advance. Love your tutorials.

  44. Pingback: Must-See Beginner Tutorials For Arduino | dev.SquareCows.com
1 2 3 6

Leave a Reply to Donna Carter Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement