JeremyBlum.com

v3.1

Tutorial 9 for Arduino: Wireless Communication

| 368 Comments

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.

368 Comments

  1. +++ OK
    ATMY1000 ERROR000
    ATDL1001 OK
    ATID1111, OK
    WR OK

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

  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. Pingback: Xbee lessons | Gnardo Polo

  5. Hello, Sir Jeremy!
    I was wondering If I could just pull the reset of the arduino to ground instead of removing the chip?
    It was suggested on this video http://www.youtube.com/watch?v=odekkumB3WQ. I have an arduino MEGA2560 and an xbee shield but I don’t have an xbee explorer.

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

  7. Pingback: Xbee notes | Grimtech

  8. 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!

    • 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

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

  9. 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

  10. 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 :)

  11. 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

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

  13. Pingback: Tutorial 09 for Arduino: Wireless Communication

  14. 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

  15. 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.

  16. 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 :-)

  17. 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

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

  19. 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

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

  21. 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

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

  23. 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?

  24. I type +++ but there is no response can any one tell me how to do

  25. 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

  26. 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.

  27. 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

  28. This is a great project! My favorite project with the arduino so far though is by far the home automation project with Arduino Uno and the Ethernet shield to control lights and stuff in your room or house. You can find a simplified home automation project at ( http://www.thearduinoscene.com/using-the-arduino-ethernet-sheild/ ) It’s a pretty good tutorial and the code is included!

  29. Witam,czy ktoś może mi wytłumaczyć jak prawidłowo podłączyć i skonfigurować modół NRF24L01 z adaptere STC15L204. Siedzę już kilka dni i ciągle mi nic nie działa. Po podłączeniu 2 Arduino kabelkiem wszystko jest wporządku.
    Podaję link do modułu:
    http://www.ebay.com/itm/NRF24L01-Wireless-Serial-Module-WITH-MCU-STC15L204-Wireless-Development-Board-/161236811905?hash=item258a768081:g:D1QAAOxyJX1TEE4i

  30. Hello, can someone explain to me how to properly connect and configure modół nRF24L01 from the adapter STC15L204. I sit a few days and I still nothing works. After connecting 2 sync cable Arduino everything is okay.
    I’ve included a link to the module:
    http://www.ebay.com/itm/NRF24L01-Wireless-Serial-Module-WITH-MCU-STC15L204-Wireless-Development-Board-/161236811905?hash=item258a768081:g:D1QAAOxyJX1TEE4i

  31. Nice post about “Arduino: Wireless Communication”. Very informative and helpful. This post is helpful in my arduino project. Thanks for sharing.

  32. When I type +++, it does not say OK Why???

  33. 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.

  34. 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);
    }
    }

    • 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);
      }
      }

  35. 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);
    }

  36. 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);
    }

  37. 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

  38. 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!

  39. 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

Leave a Reply

Required fields are marked *.