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. +++ OK
    ATMY1000 ERROR000
    ATDL1001 OK
    ATID1111, OK
    WR OK

    WAT TO DO..MY FINAL YR PROJECT DEPENDS ON IT :(

    1. hi shreyas.. did u manage to solve the problem? when i follow jeremy, everything ok except ATMY1000.. why is that?

      1. hi leena,
        I’m also facing same problem if you got the solution please share with me.

  2. Hello,

    I am trying to configure two XBee S2 modules to communicate with each other via Ardiono Unos and the XBee Pro shields. My problem is I am new to this and not sure how to configure the XBee modules to talk to each other. I tried using Putty with instruction from Jeremy but I keep getting an error during the ATML1000 configuration portion. (His instructions work great for the XBee S1 but not the XBee S2). I have downloaded the XCTU software but am unsure how to use and the proper procedure to configure S2 modules to talk to each other.

    Any help would be greatly appreciated.

    Cheers,

    Andrew

  3. Dear Sir

    Good day,

    I have been working with my colleages on our graduation project and we happened to use the Xbee S1 module and the Arduino Uno microcontroller.

    We wanted to develop a wireless sensor network as follows:

    The laptop will be used as the coordinator(Arduino) and we will have two end devices in two neighbouring classrooms both of which will be composed of an Arduino Uno mounted on an Xbee shield which has an Xbee antenna on top, these end devices have two sensors and two switches respectively.

    We need help in allowing these two end devices to act as transceivers and send/receive the sensor and switch readings accordingly.

    In addition to this, we are thinking of using another end device as an access point or a repeater that receives a signal and strenghens it in order to be received by a further away coordinator.

    Please present us with any ideas or ways to successfully implement these ideas into action.

    Yours faithfully,
    Saleh Helmy

  4. i need to send the data from two or more zigbee transmitters circuit to one zigbee circuit ca u help me??

  5. Hello.. I am using digital fire sensor at one xbee and an LED on another ..
    I have done the XBEE commuications using putty as those commands are different from yours because i am using XBEE S2….the commands are..

    XBee 1
    +++
    ATDH13A200
    ATDL40B7A19B
    ATWR
    ATCN

    XBee2
    +++
    ATDH13A200
    ATDL40B7A189
    ATWR
    ATCN

    Its done….
    Now will you help me with the CODING part of both the arduino’s & tell me about jumbers on XBEE shield.. should I first keep it to USB and change to XBEE after upload?
    My Codes are:-

    For Arduino and XBEE 1:-

    void setup()
    {
    Serial.begin(9600);
    pinMode(11,INPUT);
    }

    void loop()
    {
    int no=digitalRead(11);
    Serial.println(no);
    delay(500);
    }

    For Arduino & XBEE2 :-

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

    }

    void loop()
    {
    while(Serial.available() ==0);
    if(Serial.read()>0)
    digitalWrite(12,HIGH);

    }
    Is there any bug? And one more thing, When I am conecting two Arduinos to my laptop, it is giving two com ports but only one selected on both IDE’s
    My two ports are COM13 & COM23…
    either COM13 is selected or COM23
    I always have to select the COM port which is perticular..HELP ME!

    1. Hi
      I tried your commands for my XBee S2. But the ATDL command is not working for me. Could you please tell me what the reason may be?
      Cheers,
      Ammu Jose

    2. For Arduino & XBEE2 :-
      void setup()
      {
      pinMode(12,OUTPUT);
      Serial.begin(9600);
      }
      void loop()
      {
      while(Serial.available()>0);
      if(Serial.read()>0)
      digitalWrite(12,HIGH);
      }

  6. Hey Ram,

    I know this a post from two years ago, but I too am having issues with interfacing my ADIS16488 with my arduino. Did you ever get this problem resolved?

    Thank you for your time,
    Sam

  7. hello jermey
    i am using xbee s2 in AT Mode for sending a byte wireless in TX end i hook up accelerometer ti arduino and then sent a byte correspondingly tilting of accelerometer but RX end i am getting byte with some delay i don’t what’s happening is it kind of buffer overflow or something ??
    PLEASE REPLY SOON :)

  8. Hi Jeremy
    I wish to use EZ430-RF2500 for serial transmission of analog values from 5 potentiometers, from the End Ponit target board to the Access point target board, and obtain these values at the respective pins of the target board at receiver end. Is there any way to achieve this? Basically, i want to try substituting XBee with the Ez430 module
    Thanks

  9. hi I am working on control 13 servo motor wireless with potentiometer
    pls send me the correct code

  10. I currently have a similar setup but with 4 dc motors, hardware: 2 arduino UNOs, 2 xbee shields, 2 xbee series 2, 1 motor shield, 4 dc motors, and 1 2 axis joystick, can you help with code to control the motors with joystick wirelessly

  11. Hi Jeremy,

    I currently have a similar setup but with 4 dc motors, hardware: 2 arduino UNOs, 2 xbee shields, 2 xbee series 2, 1 motor shield, 4 dc motors, and 1 2 axis joystick, can you help with code to control the motors with joystick wirelessly. Im not sure where to start. Please help me I cannot find any examples like this online.

  12. Hello, Mr. Jeremy!

    I have some problem with WiFi Bee 2.0 (model RN171-I/NM).
    I have:
    1) Arduino Mega 2560 rev3
    2) Mega Sensor Shield 2.4
    3) WiFi Bee 2.0 shield
    4) usb-cable to connect arduino via USB to computer

    So, I connected Bee to XBee2 port on Mega Sensor Shield and I can’t do any action:
    1) can’t connect to home wifi-network
    2) can’t create an AP
    I need one of this variants to realize connection between PC and Arduino, but WiFly library’s method float WiFly::version() always reports -1.0. I watched the code of library – boolean WiFly::sendCommand(const char *cmd, const char *ack, int timeout) returns “false” because boolean WiFly::ask(const char *q, const char *a, int timeout) returns “false” and so on…

    Google gave me no any usable information, that I can use.

    I will be wery happy to get any advice to fix my problem :-)

  13. Hello there. I am trying to do the same with an uno and a nano board but i have been unsuccessful so far. Do I need a special configuration for nano and uno to talk to each other? (For the nano board I am using an xbee shield offered by Gravitech).

    Thank you

  14. hello sir, plz help me for receiver zigbee interfacing with ardiuno uno r3 and give programe for motor drive

  15. PLEASE HELP!!!! I have two xbee pro s3b high range 900hp radios with two arduino UNOs 1 motor shield controlling 4 dc motors, robot side: xbee s3b with high gain antenna, motor shield, arduino uno with 4 dc motors. My side: xbee s3b 900 hp with high gain antenna xbee sheild arduino uno with two axis joy stick. Here’s what I can’t figure out. How can I control those motors without a computer just a battery powering the arduinos and robots I don’t know how the code looks. I have figured out how to do it serially but I want to cut ties with computer

  16. is there a way i can connect flex sensors to one arduino and have it control servo motors that are connected to another arduino

  17. Can anyone help, I have two xbee s3b 900hp that I am trying to use without computer to control 4 dc motors with a joystick
    2 arduino uno
    2 xbee sheilds
    2 xbee s3b 900hp
    1 motor shield
    1 2 axis joystick

    I am trying to use only battery power to control 4 dc motors through xbees using joystick can some one let me know how to send packets or what is involved in using those types of xbees? Please email me at [email protected] subject xbee
    Thanks

    1. Dear Sir,
      My situation is similar to yours, i have to control 4 dc motor with the wii Nunchuk wirelessly with two arduino Please send me E-mail if you have any idea.My e-mail is [email protected].

  18. How can I use arduino for ” EN 62056-21 ” .It can be used for reading and programing an meter using a optical probe?

  19. Can more than two XBee’s communicate with each other? The project I have undertaken requires three Arduino based bots to communicate with each other and send and recieve data in the form of text files . Can this be done with XBee or I need to use something else like some other transreciever?

  20. Dear Jeremy Blum,
    I’m very glad to meet you, I’m a research scholar, for my project work I need to use the wireless communication system for data tracking from the tractor rear wheels, for that by watching your tutorials I have designed two wireless systems by using Arduino & Two Xbee modules (One as transmitter and other as receiver) for each wheel i.e. finally I have two wireless systems each has One Arduino and two xbee modules and both the systems have been connected to two laptops separately to record the data.

    But its difficult to use two laptops on the tractor, hence we have decided to to collect both the axles data with single laptop, but how to do that I could not understand, basically I’m an Agricultural Engineer…. I request you please help me in this issue.

    Thanks in advance

  21. Hello, thanks for the tutorial. Is there a reason why you don’t use XCTU from Digi to program your XBEE modules? Does that software work with Sparkfun’s XBEE breakout board or does it only work with their own boards? Thanks.

  22. Hi nice information got here, thanks just wondering is it possible to control 5 different servos and send information to a particular servo connected to another device (lilypad to arduino and vice versa) using 2 Xbee??

    Many Thanks for your time

    1. hello,
      Is there something wrong with this website….each time I get the msg that the website can’t be reached.
      Thanx

  23. hello sir…
    Can you please send me the code for interfacing zigbee, lcd and arduino ? I have to print message received from the other zigbee module. Please reply as soon as possible.

  24. hi, jeremy.
    currently, i work on a project that required communication between 2 arduino using zigbee.
    the setting on the zigbee is done, and some simple example (led) is able to perform.
    however, i faced problem on the sensor mpu6050 and 2dc motor.
    how i gonna send the data received from MPU6050 and convert the data into forward,backward,turnleft and turn right motion.
    here is the code without zigbee implemented
    #include
    #include
    #include
    MPU6050 mpu;
    int16_t ax, ay, az;
    int16_t gx, gy, gz;
    const int mtr1_In1 = 3;
    const int mtr1_In2 = 2;
    const int mtr2_In1 = 11;
    const int mtr2_In2 = 12;
    const int flexpin = 0;
    void setup ()
    {
    pinMode(mtr1_In1, OUTPUT);
    pinMode(mtr1_In2, OUTPUT);
    pinMode(mtr2_In1, OUTPUT);
    pinMode(mtr2_In2, OUTPUT);
    mpu.initialize();
    }
    void loop()
    {
    mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
    ax = map(ax, -17000, 17000, -255, 255);
    ay = map(ay, -17000, 17000, -255, 255);
    int flexposition;
    flexposition = analogRead(flexpin);

    if (ax > 100 && flexposition < 800 )
    {
    digitalWrite(mtr1_In2,LOW);
    analogWrite(mtr1_In1,ax);
    }

    if (ax<-100 && flexposition < 800 )
    {
    digitalWrite(mtr2_In2,HIGH);
    analogWrite(mtr2_In1,ax-ax-ax);
    }
    if ( ay< -100 && flexposition 100 && flexposition 800)
    {
    digitalWrite(mtr1_In1, LOW);
    digitalWrite(mtr1_In2, LOW);
    digitalWrite(mtr2_In1, LOW);
    digitalWrite(mtr2_In2, LOW);
    }
    }

    1. can anyone transform the code to both transmitter and receiver?

      #include
      #include
      #include
      MPU6050 mpu;
      int16_t ax, ay, az;
      int16_t gx, gy, gz;
      const int mtr1_In1 = 3;
      const int mtr1_In2 = 2;
      const int mtr2_In1 = 11;
      const int mtr2_In2 = 12;
      const int flexpin = 0;
      void setup ()
      { //Set the mode for each digital pins whether input or output
      pinMode(mtr1_In1, OUTPUT);
      pinMode(mtr1_In2, OUTPUT);
      pinMode(mtr2_In1, OUTPUT);
      pinMode(mtr2_In2, OUTPUT);
      mpu.initialize();
      }
      void loop()
      {
      mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
      ax = map(ax, -17000, 17000, -255, 255);
      ay = map(ay, -17000, 17000, -255, 255);
      int flexposition;
      flexposition = analogRead(flexpin);

      if (ax > 100 && flexposition < 800 )
      {
      digitalWrite(mtr1_In2,LOW);
      analogWrite(mtr1_In1,ax);
      }

      if (ax<-100 && flexposition < 800 )
      {
      digitalWrite(mtr2_In2,HIGH);
      analogWrite(mtr2_In1,ax-ax-ax);
      }
      if ( ay< -100 && flexposition 100 && flexposition 800) // flexposition > 800 mean a bending of flex sensor occurred
      {
      digitalWrite(mtr1_In1, LOW);
      digitalWrite(mtr1_In2, LOW);
      digitalWrite(mtr2_In1, LOW);
      digitalWrite(mtr2_In2, LOW);
      }
      }

  25. Hi

    i am trying to send numbers stored in a variable in to xbee connected to the laptop.When the arduino cable is connected i can view the number correctly in the serial monitor but while sending wirelessly to the xbee,at the xctu the values look like they need to be decoded.Do i have to convert to particular format before transmitting??

    My program for transferrind value

    #include
    #include
    #define echoPin 8 // Echo Pin
    #define trigPin 7// Trigger Pin
    long duration, distance; // Duration used to calculate distance

    SoftwareSerial XBee(11,12); // RX, TX
    void setup()
    {
    XBee.begin(9600);
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);

    }

    void loop()
    {
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);

    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);

    distance = duration/29/2; //Calculate the distance (in cm) based on the speed of sound. //The speed of sound is 340 m/s or 29 microseconds per centimeter.
    //The ping travels out and back, so to find the distance of the
    //object we take half of the distance travelled.
    Serial.println();
    Serial.print(“in= “);
    //Serial.(distance);

    Serial.println(distance);

    while((Serial.available())>0)
    { // If data comes in from serial monitor, send it out to XBee
    XBee.write(Serial.read());
    }

    XBee.write(Serial.read());
    Serial.println();

    while( (XBee.available()>0))
    { // If data comes in from XBee, send it out to serial monitor
    Serial.write(XBee.read());
    }
    delay(2000);
    }

  26. Hi jeremy,

    Please help. The data sent through one xbee-arduino pair is getting communicated to the next arduino-xbee pair and is visible on the serial monitor but when i tried multiplying or adding a value to the received data, only the received data is getting displayed.
    For eg;
    I transmitted a value=3
    I received 3
    but I want to display 3*2=6
    but instead of 6 it always shows 3 in the serial monitor

    AT transmitter:
    int a;
    void setup() {
    Serial.begin(9600);
    }

    void loop() {
    a=3;
    Serial.println(a);
    delay(2000);
    }

    At receiver side:
    void setup() {
    Serial.begin(9600);
    }

    void loop() {
    if (Serial.available()!=0)
    { int n=2;
    int b=Serial.read();
    int c= b*n;
    Serial.println(c);
    }

  27. HI Jeremy,

    Can you provide the code for NRf24l01 transceiver instead of XBee? I am trying to mix and match and run a RC car using steering and pedal system but nothing seems to be working

  28. Hello,
    First of all, congratulation for your great work. I find it really very clear.
    I would like to control a servo motor with on one side an Arduino and a xbee , and the other a xbee and keys of my computer (up, down, left, right).
    Can you help me? Have you got some advices?

    Thank you and good luck for the future!

  29. Hi Jeremy, when I plug my xbee USB interface should I be installing FTDI drivers? Because when I initially plug it in it does not see it as a USB port.

    Thanks
    Nick

  30. sir i an trying to communicate 2 arduino uno with nrf24l01+ by using shield MCU STC15F204 a SPI to UART converter but i am failed to communicate kindlay send me the code to test that how it would be configured or to communicate it with other device. there is no any effective data is available in internet.

  31. Hi Jeremy

    Could you please send me the circuit diagram, because I don´t have the Shield for the Arduino!
    to connect it direct on the breadboard… Pleeease

  32. i need your help
    i’m looking for codes for xbee transmitter and receiver for sending flame sensors value from xbe to another xbee.

  33. I am using XBee S1 modulue to communicate between matlab(Laptop) and arduino, and another XBee S1 module to communicate between arduino and matlab.I implemented Software Serial to communicate between the arduino and XBee. The communication were fine and work perfectly. But the moment i include lcd library in the arduino sketch, i could only communicate one way i.e from (arduino with XBee) to (laptop with XBee) but coudnt communicate the other way. Kindy Help pls

  34. Hi Jeremy,

    I just wanted to know that can we transmit data of five potentiometer at once from 1 Xbee to the other Xbee connected to another Arduino to Drive the 5 independent servo motors respectively.

    It would be helpful, if you could solve my query.

    Thank you

  35. Hey Jeremy! I tried the wireless communication between the two xbees as you demonstrated in your tutorial. The the xbees the working just fine. The transmitter xbee is transmitting the values from 0-9 but the receiver xbee is receiving 3 values at once. Suppose the pot transmitted 3 thorugh the transmitting xbee, the receiving xbee displays 3 along with 2 more values that are -35 and -38. Due to this the servo is just jerking. I tried to solve the problem, but nothing worked! Plz do help. Thank you!

  36. Hello Jeremy,

    That’s a great video.I’m a beginner in using the SPI protocol.
    Im having problem interfacing the current sensor TLI4970 with arduino because not specific library can be found. could you help me?

  37. How can we make 2 way communication between the xbee, that means 2 or 3 routers(transmitter) and 1 coordinator(receiver).

  38. I have made comminucation between the two Xbees but can’t send data through Xbees when connected to the Arduino , please can u help me out with it

Leave a 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