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. Greetings jeremy! Im having my thesis right now, and i choose temperature control as my topic and peltier or thermoelectric is my choice, so the thing is i want to control it wirelessly. I found that it can be control by arduino but its not wireless. Do you think it is possible to control it via Xbee base on this video? hoping for your thoughts about this. Thanks a lot.
    p.s. sorry for my bad english :)

    1. There does seem to be a lot of confusion in many people’s minds on the topic of “wireless communication” with Arduino.

      Essentially, the “wireless” means exactly that – it replaces the wire, the cable that connects the Arduino to the PC…

      If you can ‘talk’ to the PC via USB or Serial (to the IDE Serial Monitor, a Processing program or something written in another language) then you can replace the cable with a “wireless link” of some kind.

      X-bee seems to have become a ‘standard’ in its own right, and it appears sometimes as if it is the only way to achieve the goal – but there are what appear to be easier and simpler solutions to ‘wireless communication’ that are not as well known, like the modules from RF-Digital and their “Wireless Inventor’s Shield” (see or, if you need long range, their “RFDANT” (the modules and the RFDANT are 3.3V – so beware, you’ll need to use ‘level-shifting’ for the signals and the 3.3V line from the Arduino for power).

      And don’t overlook Blootooth and WiFi – they are both “Wireless Communication” methods – as is Infra-Red…

      Due to problems with Customs where I am, I haven’t been able to try the “Wireless Inventor’s Shield” yet but Jeremy, being on the same continent, may be able to do so much more easily – any thoughts Jeremy?

      Duncan (in Spain)

  2. Jeremy,
    are just gr8,
    could you please tell me how can i plug in my 9v battery to make it COMPLETELY wireless(i dont want the usb cable)
    please tell me as soon as possible
    would be better if you can post a short video
    thanks in advance!!!

  3. Hello Jeremy
    I want to ask about making a bidirectional communication between 2 arduinos.using 2 Xbee’s. Here my biggest issue is how to make them talk one at the time , and how to make them know when to listen and when to transmit.
    I tried so far with a software serial port named Xbee , by using
    if ( Xbee.available == 0 ) {
    \\ trasmitting code } and

    if ( Xbee.available>0) {
    switch ( Xbee.read() \\receiving code }

    one both arduinos ( one used for a remote , and one for a robot ) , but trouble is : they don’t seem to synchronize , and one way trasmissions are lost ( those comming from the robot althought his xbee’s is working properly)

    Then i thought that an emulated serial port is not as good as the original hardware port and i connected both xbee’s to the arduino’s RX -TX , Is this guess true ?
    Now i’m able to send data to the robot and to receive a feedback but that’s all , i can’t make the remote enter transmission mode again unless i reset the arduino

    I don’t know what functions or structures a should use to achieve this

    Thank you for your time

  4. Hello

    I have 2 xbees, one sitting on explorer board and the other connected to a dsPIC chip. I initialized the clock and set peripherals and assigned the RX and TX pins correctly but I am not able to send or receive!!! I am going nuts… This same code I used with a different xbee (regular) but the xbee I have now is xbee pro S2. I configured it with XCTU and all but in XCTU terminal I only see the characters sent from the PC xbee… But the xbee on the PIC won’t receive from PC and I am sending from it to PC but XCTU terminal on PC doesn’t show anything received… The RSSI light should blink I believe when they send and receive but I don’t know why this is happening! Is there a special setting for xbee pro that I am missing?

    I was thinking maybe the baud rate isn’t the same on both but I checked my calculations many times and they both are set at 9600… Any ideas?

    Thank you.

  5. Hi Jeremy,
    Thanks again for this presentation… I could finally make everything work:)
    Do you know how I could make the same with a higher resolution (like 180)… 9 is not sufficient for what I’m hoping to do… It it is much more complicated to read strings of 3-4 characters:(… Any suggestion?

    Thanks & Happy new year!

  6. Hi Jeremy,

    Great video! I am wondering if these instructions will work for Mega ADK’s instead of the Unos? Do you know if the xbee radios would need to be the same type? Thanks!

    -Micah

  7. hi jeremy..very nice tutorial.am working on my project ” rc plane “..hence i need to have a wireless communication to control servo motor and am using xbee pro 900..i have two mega 1280 and 2560 ..i just did lotz of test to see if the communication works well on the xbee and yes it was…on the transmitter @ is fine but on the receiver something happening wrong..something wrong with the code!!
    the transmitter is sending the information perfectly…but when i connect the receiver module to one of the arduino and serial print on my pc…this are the values i am getting :
    60
    0
    0
    60
    0
    0
    60
    0
    0
    etc..i don’t know were the zero are coming from.the 60 is the value that changes according to the pot trim..while if i connect to the xbee to xbee adapter and serial print am getting the values 0-9 perfect..and the servo freaks.just moving small from 0-50 while freaking.. i did your changes on as said above….thanks let me know!:)

    1. did you try changing ” Serial.println(val);” to “Serial.print(val);” on the sketch that is transmitting? .

      1. Hi Michael,

        Ive been searching for days for a solution to that problem with the servo, tried everything and everywhere, then came across ur message to another user. I changed it to print and it works perfect.
        Nice 1.

        thanks a million

  8. Hello Jeremy,

    I’m new to arduino and want to send two variables data from one arduino to another via wireless serial port. what should I write in the code to get this done?

    Thanks,

  9. Hi Jeremy,
    The XBees in the tutorial are Series1 or Series2?If they are Series2, doesn’t one need to be a coordinator?

      1. hey Jeremy

        what will be the difference if i use series 2 Xbee rather than series 1, will i be able to set it up and run a DC motor using this same tutorial.

        i am asking this because most series 1 Xbees are out of stock

        please reply ASAP

        thanks a lot!!!

  10. Hey Jeremy,

    Great blog and great instructions! I was wondering if you could post similar tutorial videos for MSP430 Launchpad or EZ430-RF2500. I saw your weather station video and I know that it’s been a while since you finished that project up but if you could post some beginner tutorials on how to program EZ430-RF2500 and/or MSP430 Launchpad, it will be greatly appreciated! Or, even if you could post on how your programmed your EZ430-RF2500, that would be great as well! Thanks for your aid and keep up the great work!

  11. Hi Jeremy, I had puzzled about how to accomplish a task I was designing for and I stumbled onto your arduino series on YouTube and I think you just may have solved my problem. THANKS!

    1) I am examining the episode 9 parts list and programs. I am finding the links pointing to the Xbee shield and the Xbee transcievers are ending up at a “product not found” search page. Could you possibly check into that for us newbs?

    2) Could I be so intrusive as to send you a brief description of what I am trying to do and get your input as to whether or not I am on the right track and your observations on it? Not sure if that would be acceptable in this venue or not.
    Thanks, Michael

  12. hi jeremy,you are awesome.Do you have any idea how to transmit more than one analog input (e.g analog 0-4)with the same 0-9 clicks to control each independent servo on the receiver??it looks a bit tricky ..please try to help me out. thanks :)

  13. Hi Jeremy, my wife keeps leaving her cellfone behind, I want to setup an pan network between her phone and maybe a neckless or watch something like this with a distance setting option that will activate an alarm, the question is do you know where I can get information on how to create this leash between two devices? I know you can buy this on the market for example Zomm but I would like to make my own one.

    Hope you can help me.

    Italo New Zealand

  14. Hello Jeremy!
    Awesome tutorials!! Your tutorials have helped me and my team in our senior project!
    I have a question. How do you connect the XBee (we are using a XBee WiFi Module) to an Arduino Mega 1280? I mean, which pin of the XBee goes where in the Arduino? We will get the XBee shield pretty soon, but we have to start working on it.
    Thank you very much!

  15. Hey! First off, great tutorial! I have two questions:

    1) With the xbee shield on, is it possible to attach a motor shield over it? For example, if I had one arduino controlling a robot car and I wanted it to convey the signals of where to turn to a second car following it, is that possible?

  16. Hello Jeremy!
    Please help me choose! I want to create wireless connection, but i’m can’t choose device to solve that problem? I want a stable signal near metal objects such as steel structures on cement plants?

  17. Hey Jeremy

    You’re tutorials are amazing, they have helped me a lot in my project!!!!

    I am intending to do the same thing as you did in the video, but with the addition of a motor shield. I have two questions;

    1) will i have to use two motor shields to communicate between the two xbees ? (i guess no!!!!)

    2) Is it possible to use the motor shield when the Xbee shield is still stacked on the arduino uno
    ( This question was asked before, but i did not understand the answer——->

    ” Connect the RX pin on one to the TX on the other and vice versa. Conenct the Xbee Vcc to 3.3V and the ground to the arduino ground. ” )

    thanks
    Allen

  18. Hi Jeremy, nice tutorial. I have one problem though; Everything works for a bit and my servo moves about 90 degrees (when I turn my POT 180 degrees) and it randomly stops, buzzes, and shakes and won’t respond to my POT anymore. Is it something with the serial.flush mentioned before? I changed it to the updated version mentioned in the edit( while(Serial.available()>0) Serial.read(); ) and other than that, my code is basically identical to yours. Any tips?
    Thanks!

  19. hi
    how will the codes change if i want to control two servos using two different pots, i tried doing it but was not able to get it. I am posting both codes below please could anybody please help .

    sender

    int potPin_0 = 0;
    int potPin_1 = 1;
    int potPin_2 = 2;

    void setup()
    {
    //Create Serial Object (9600 Baud)
    Serial.begin(9600);
    }

    void loop()
    {
    int val_0 = map(analogRead(potPin_0), 0, 1023, 0, 9);
    Serial.print(val_0);
    delay(50);

    int val_1 = map(analogRead(potPin_1), 0, 1023, 0, 9);
    Serial.print(val_1);
    delay(50);

    int val_2 = map(analogRead(potPin_2), 0, 1023, 0, 9);
    Serial.print(val_2);
    delay(50);

    }

    receiver end

    #include

    //Define Pins
    int servoPin_0 = 8;
    int servoPin_1 = 9;
    int servoPin_2 = 10;

    //Create Servo Object
    Servo orangeServo;
    Servo wristServo;
    Servo gripperServo;

    void setup()
    {
    //Start Serial
    Serial.begin(9600);

    //Attaches the Servo to our object
    orangeServo.attach(servoPin_0);
    wristServo.attach(servoPin_1);
    gripperServo.attach(servoPin_2);

    delay(500);
    }

    void loop()
    {

    while( Serial.available() == 0);
    int data_0 = Serial.read() -‘0’;

    int pos_0 = map(data_0, 0, 9, 0, 180);
    pos_0 = constrain(pos_0, 0, 180);

    //Turn the servo
    Serial.print(pos_0);
    orangeServo.write(pos_0);
    while(Serial.available()>0);
    Serial.read();

    while( Serial.available() == 0);
    int data_1 = Serial.read() -‘0’;

    int pos_1 = map(data_1, 0, 9, 0, 180);
    pos_1 = constrain(pos_1, 0, 180);

    //Turn the servo
    Serial.print(pos_1);
    wristServo.write(pos_1);
    while(Serial.available()>0);
    Serial.read();

    while( Serial.available() == 0);
    int data_2 = Serial.read() -‘0’;

    int pos_2 = map(data_2, 0, 9, 0, 180);
    pos_2 = constrain(pos_2, 0, 180);

    //Turn the servo
    Serial.print(pos_2);
    gripperServo.write(pos_2);
    while(Serial.available()>0);
    Serial.read();

    }

    the problem i am facing currently is that when i move one pot all the servos turn .

    could somebody please explain why this happens

    thanks

  20. I want to create code that will send characters from the keypad through the xbee to the other xbee. Then the ardiuno will take in the signal and control a DC motor. Now i am not sure if the way i programmed this will work. I don’t know if the character i send will be received as a character. I have not tested the code yet because I am waiting for my USB explorer to give the xbees the ID’s in order for them to communicate. I can copy my code down if you want to see. Any answers you may have would be greatly appreciated.

  21. Hi Jeremy. GREAT tutorials by the way, thank you for your effort.

    if the arduino uno is communicating with a sensor board by UART, can it also communicate this data to another unit using xbee? Or does the UNO need to only talk to one or the other using UART. I think the mega allows multiple uart ports but not sure if it’s doable with UNO.

  22. Hi Jeremy,

    Your tutorials have been extremely handy. I only started to use the Arduino two months ago, pretty interesting stuff. Currently, I have been able to establish wireless communications to display some of my outputs on the serial monitor. About a week ago, I decided to step it up by using a serial graphic LCD to display my outputs for a Voltage reading circuit using a Potentiometer, two arduinos, two Xbee shields, and a serial LCD, but it doesn’t seem to work.

    My code to get the analogue reading on PinAO on the first arduino (transmitter) seems to be OK, because I have used it for other circuits. But the code for the GLCD circuit on the digital pin 4 on the second arduino (receiver) seems to be giving me a glitch.

    Can you offer a guide on what I can possibly do?

    I am posting the codes for the first arduino and second arduino in the footnote below:

    I will also forward a table of the values I’m looking forward to reading on the LCD to you. Many thanks and accept the assurances of my best regards.

    First Arduino (Potentiometer Circuit) CODE:

    const int analogInPin = A0; // Analog input pin that the potentiometer is attached to

    int sensorValue = 0; // value read from the pot
    int outputValue = 0; // value output to the PWM (analog out)
    int incomingByte;

    void setup()
    {
    Serial.begin(9600);
    }

    void loop()
    {
    if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    if (incomingByte == ‘1’){
    sensorValue = analogRead(analogInPin);
    // map it to the range of the analog out:
    outputValue = map(sensorValue, 0, 1023, 0, 255);
    Serial.print(outputValue, DEC);
    }
    }
    }

    Second Arduino (GLCD Circuit):
    #include
    #include

    // this array defines values for after the decimal place
    // note that lut[1] (625) is in fact .0625
    const unsigned int lut[16] = {
    0, 625, 125, 1875, 25, 3125, 375, 4375, 5, 5625, 625, 6875, 75, 8125, 875, 9375};

    int outputValue = 0; // value output to the PWM (analog out)

    int beforeDP = 0; // value befroe the decimal point
    unsigned int afterDP = 0;
    unsigned int valueaDP = 0;
    int temp = 0;

    serGLCD myGLCD(4); // GLCD connected to pin 4

    void setup() {
    myGLCD.setbrightness(50); /// set backlight duty cycle to 50%
    // initialize serial communication:
    Serial.begin(9600);
    delay(5000); /// delay to allow Zbee to setup
    Serial.print(‘1’);
    }

    void loop() {
    if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    outputValue = Serial.read();

    // get before decimal place value
    if (outputValue < 50) {
    beforeDP = 0;
    calculate_afterDP();
    }
    // I'm stuck on getabout the rest of the numbers before the decimal place.
    //………..

    // print this to LCD
    myGLCD.setCursor(0,63); // set cursor to right position
    myGLCD.print("ADC value: ");
    myGLCD.print(outputValue, DEC);
    // remove any digits on screen that are no longer necessary by adding 2 spaces
    // for numbers less than 10, and 1 space for numbers less than 100.
    if (outputValue < 10) myGLCD.print(" ");
    else if (outputValue < 100) myGLCD.print(" ");

    myGLCD.setCursor(0,53); // set cursor to right position
    myGLCD.print("Voltage: ");
    myGLCD.print(beforeDP, DEC);
    myGLCD.print(".");

    // get afterDP value
    valueaDP = lut[afterDP];
    // now print it to the screen
    //………..

    // send message to get another reading
    delay(500);
    Serial.print('1');
    }
    }

    void calculate_afterDP() {
    // I couldn't figure this out work this out – can be calculated from beforeDP value
    // and received outputValue.
    // ………
    }

  23. Hi Jeremy, i’m using usb-serial converter for configuring xbee radio. I have two xbee series 2 radios. I opened putty and entered +++, it returned OK. But When i entered ATMY 1000 returned ERROR000 something like that. But all the other future commands works fine such as ATDL 1001, WR etc.. What’s the problem?

  24. Hi Jeremy,

    Great tutorials you have on both the Arduino and Eagle, both are a huge help!

    I’ve got one large question when it comes to sending data that is over an integer of 9. Since the Serial.read() function reads one Char at a time, how would you suggest sending say, 8 bytes of data (ie 8 int’s with a range of 255). I assume I’d want to make the packet size smaller and simply send one byte per xbee packet, splitting the data from the stop bit on the receiving end.

    I’ve been researching this for days and am running against a wall, any suggestions/tips would be very welcome.

    Thanks.

    Matt

  25. Hi Jeremy,

    I really like your tutorials, they are very useful and you’re AWESOME!
    So far I’m doing some experiment, I would like to use piano keyboard to control the LED and maybe using bluetooth to do the remote control.
    I would like to ask how can make it possible, I need to MIDI right? and what materials would you reccomend? Could you give me some suggestions?

    Thank you so much!

    Chin

  26. hye..I have two Xbees and two Arduinos coded to control angle of servo motor. How could I code both of them . I think we need a sender and receiver code. On the receiver ,I’m already have the receiver code, but I have no idea for sender code. I’m a total beginner. Thanks!

    Here is my receiver code.

    #include

    Servo myservo;

    int pos = 0;

    void setup()
    {
    Serial.begin(9600);
    myservo.attach(9);
    }

    void loop()
    {

    while (Serial.available() > 0) {

    pos = Serial.parseInt();

    }
    myservo.write(pos);
    delay (100);

    }

  27. Hi Jeremy. I’m trying to pass a serial input from the serial monitor from one arduino to another arduino but it doesn’t seem to work. I have pasted my Tx Rx codes below. Also, is there a way to log the incoming data into any database?

    Tx:

    void setup()
    {
    Serial.begin(9600); //Setting baud rate
    }

    void loop()
    {
    while (Serial.available() == 0); //Checks to see if arduino is receiving something from computer

    int val = Serial.read() – ‘0’; //read i/p from computer in integer terms taking care of ASCII
    Serial.print(val);
    delay(50);
    }

    Rx:

    int ledPin = 13;

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

    void loop()
    {
    while (Serial.available() == 0);
    int val = Serial.read() – ‘0’;
    if (val == 1)
    {
    digitalWrite(ledPin,HIGH);
    }
    else if (val == 0)
    {
    digitalWrite(ledPin,LOW);
    }
    else
    {
    digitalWrite(ledPin,LOW);
    }
    Serial.flush();
    }

  28. How would I modify this code to enable wireless communication between arduinos like you did in tutorial 09. This code is used to have a wii nunchuk accelerometer control two servos.

    #include
    // comment out the below for Arduino 0011 and above, uncomment for older
    #include
    #include
    uint8_t outbuf[6]; // array to store arduino output
    int cnt = 0;
    int ledPin = 13;

    int servoPin = 11; // Control pin for servo motor
    int pulseWidth = 0; // Amount to pulse the servo
    long lastPulse = 0; // the time in millisecs of the last pulse
    int refreshTime = 20; // the time in millisecs needed in between pulses
    int minPulse = 700; // minimum pulse width

    #define pwbuffsize 4

    int pwbuff[pwbuffsize]; // buffer for smoothing pulseWidths
    int pwbuffpos = 0; // position in pwbuff

    void setup(){
    Serial.begin(19200);
    Wire.begin (); // join i2c bus with address 0x52
    nunchuck_init (); // send the initilization handshake
    pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
    pulseWidth = minPulse; // Set the motor position to the minimum
    Serial.print (“Finished setup\n”);
    }

    void nunchuck_init(){
    Wire.beginTransmission (0x52); // transmit to device 0x52
    Wire.write (0x40); // sends memory address
    Wire.write(byte (0x00)); // sends sent a zero.
    Wire.endTransmission (); // stop transmitting
    }

    void send_zero(){
    Wire.beginTransmission (0x52); // transmit to device 0x52
    Wire.write(byte (0x00)); // sends one byte
    Wire.endTransmission (); // stop transmitting
    }

    int t = 0; // when it gets to 25, read nunchuck
    void loop(){
    t++;
    if( t == 25 ){
    t = 0;
    Wire.requestFrom (0x52, 6); // request data from nunchuck
    while (Wire.available ()){
    // receive byte as an integer
    outbuf[cnt] = nunchuk_decode_byte (Wire.read ());
    digitalWrite (ledPin, HIGH); // sets the LED on
    cnt++;
    }
    // If we recieved the 6 bytes, then go print them
    if (cnt >= 5) {
    printNunchuckData(); // uncomment this for debug
    //update servo pulseWidth
    float tilt = outbuf[4]; // z-axis, in this case ranges from ~75 – ~185
    tilt = (tilt – 70) * 1.5; // convert to degrees angle, approximately
    pulseWidth = (tilt * 9) + minPulse; // convert angle to microseconds
    pwbuff[pwbuffpos] = pulseWidth; // save for averaging
    if( ++pwbuffpos == pwbuffsize ) pwbuffpos = 0;
    pulseWidth=0; // reset so we can
    for( int p=0; p= refreshTime) {
    digitalWrite(servoPin, HIGH); // Turn the motor on
    delayMicroseconds(pulseWidth); // Length of the pulse sets the motor position
    digitalWrite(servoPin, LOW); // Turn the motor off
    lastPulse = millis(); // save the time of the last pulse
    }
    }

    /*Print the input data we have recieved
    accel data is 10 bits long
    so we read 8 bits, then we have to add
    on the last 2 bits. That is why I
    multiply them by 2 * 2
    */

    int i=0;
    void printNunchuckData(){
    int joy_x_axis = outbuf[0];
    int joy_y_axis = outbuf[1];
    int accel_x_axis = outbuf[2]; // * 2 * 2;
    int accel_y_axis = outbuf[3]; // * 2 * 2;
    int accel_z_axis = outbuf[4]; // * 2 * 2;
    int z_button = 0;
    int c_button = 0;

    /*byte outbuf[5] contains bits for z and c buttons
    it also contains the least significant bits for the accelerometer data
    so we have to check each bit of byte outbuf[5]
    */
    if ((outbuf[5] >> 0) & 1)
    z_button = 1;
    if ((outbuf[5] >> 1) & 1)
    c_button = 1;

    if ((outbuf[5] >> 2) & 1)
    accel_x_axis += 2;
    if ((outbuf[5] >> 3) & 1)
    accel_x_axis += 1;

    if ((outbuf[5] >> 4) & 1)
    accel_y_axis += 2;
    if ((outbuf[5] >> 5) & 1)
    accel_y_axis += 1;

    if ((outbuf[5] >> 6) & 1)
    accel_z_axis += 2;
    if ((outbuf[5] >> 7) & 1)
    accel_z_axis += 1;

    Serial.print (i,DEC);
    Serial.print (“\t”);

    Serial.print (joy_x_axis, DEC);
    Serial.print (“\t”);
    Serial.print (joy_y_axis, DEC);
    Serial.print (“\t”);

    Serial.print (accel_x_axis, DEC);
    Serial.print (“\t”);
    Serial.print (accel_y_axis, DEC);
    Serial.print (“\t”);
    Serial.print (accel_z_axis, DEC);
    Serial.print (“\t”);

    Serial.print (z_button, DEC);
    Serial.print (” “);
    Serial.print (c_button, DEC);

    Serial.print (“\r\n”);
    i++;
    }

    /*Encode data to format that most wiimote drivers except
    only needed if you use one of the regular wiimote drivers
    */
    char nunchuk_decode_byte (char x){
    x = (x ^ 0x17) + 0x17;
    return x;
    }

  29. Hi Jeremy:
    Thanks.
    Followed all the steps. Get an OK when I type in +++, then when I type ATMY1000 I get an error.
    What am I doing wrong?
    Thanks,
    Bela

  30. Hi Jeremy, i have few question to ask…
    After configure the 2 Xbee modules to communicate each other, we need to program the arduino board to transmit and receive data?
    Or using Xbee shield will automatic transmit and receive data between Xbee without any programming?
    Actually i am a mechanical student and my fyp was using few sensors to capture the RC car behavior….
    I using sensor GY-521 MPU6050 and i only know how to capture the raw data but not really know about calibration and conversion to get 0 reading when stationary and get the unit in g (for acceleration) and deg/s (for gyro), pls help me….thanks….

  31. Jeremy can you teach me how to send and receive a message using 2 computers and 2 transceivers i just need basic codes . Its just like a chat box .

  32. Luv all your tutorials. My project is to stick an xbee inside an AC power receptacle, and use that to switch lights on and off. One option is to use an X10 module, but there’s got to be an easier way!

    What would you suggest?

    Regards.

  33. Hi Jeremy,

    thanks for your great xbee tutorial, I tried it with 2 xbee serie 1 but without success. Is it important to have the same shields ?

  34. Hey Jeremy, I have a project where I need ten smartLED costumes to run light patterns in sync. Can one xbee communicate to the 9 other xbees so the lighting programs run in sync with each other?

      1. Thanks, it was actually easy. I just set up the trasmitting arduino as 1000 and the nine others as 1001 and only receiving data.
        Bam.

  35. Hi Jeremy,

    awesome tutorials…keep up the good stuff.
    I am facing some problems with servo motor control using XBee and arduino.
    I have written a Java program that reads the Logitech gamepad input and transmits it via a Xbee USB explorer connected to my laptop. I’m using the gamepad to send simple character commands to control the servo. For example, if I press the right joystick up, i send ‘A’, for right joystick down i send a ‘C’ and vice versa. I hooked up another Xbee connected to an arduino and i’m using the serial monitor to print the commands as they come in to verify that the commands are being transmitted correctly. Please see this code below:

    #include

    SoftwareSerial xbee(2, 3); //Rx, Tx

    void setup() {
    Serial.begin(9600);
    xbee.begin(115200);
    }

    void loop() {

    if(xbee.available()) {
    Serial.print((char) xbee.read());
    }

    if(Serial.available()) {
    xbee.print((char) Serial.read());
    }
    xbee.flush();
    delay(100);
    }

    After having verified that the commands are being read correctly by the receiver Xbee, I wrote this code to control a servo:

    #include
    #include
    #include

    SoftwareSerial xbee(2, 3); //Rx/Tx

    Servo servo; //define servo
    int servoPos = 90;
    char ch;

    void setup() {
    servo.attach(9); //drive servo using digital pin 11 of arduino

    Serial.begin(9600);

    xbee.begin(115200);
    }

    void loop() {
    if(xbee.available() > 0) {
    ch = xbee.read();
    }

    switch(ch) {
    case ‘A’:
    servo.write(0);
    break;
    case ‘B’:
    servo.write(90);
    break;
    case ‘C’:
    servo.write(180);
    break;
    default:
    servo.write(90);
    break;
    }
    delay(100);
    }

    The problem I’m facing is that the servo seems to turn fine in one direction and starts twitching, and when i don’t send in any command, I default the servo to turn 90 degrees. Here also, the servo is not exactly positioned at 90 degrees.
    The servo movement is not smooth and it’s quite erratic, in the sense, the servo seems to turn to some angle randomly.
    Do you see any problem with the code?

    As a test when i replaced the xbee serial with the commands transmitted via a serial monitor, the servo works just fine as seen below:

    #include
    #include

    Servo servo; //define servo
    int servoPos = 90;
    char ch;

    void setup() {
    servo.attach(9); //drive servo using digital pin 11 of arduino

    Serial.begin(9600);
    }

    void loop() {
    if(Serial.available() > 0) {
    ch = Serial.read();
    }

    switch(ch) {
    case ‘A’:
    servo.write(0);
    break;
    case ‘B’:
    servo.write(90);
    break;
    case ‘C’:
    servo.write(180);
    break;
    default:
    servo.write(90);
    break;
    }
    delay(100);
    }

    I’m not sure why it’s not working with the xbee. It would be great if you can help me with this.

    Thanks,
    Sumair

  36. Hi Jeremy,

    Thanks for the great videos! I am an undergrad ME at Purdue University with research in the field of swimming training devices. I wish to send a signal from an accelerometer through an XBEE to an IPAD. Do you know if this is possible and what the best way to accomplish this would be?
    Thanks,
    Chuck Destro

    1. Apple devices are notoriously difficult to interface with. I think you;ll have much better luck with an android device and the Arduino Android Dev kit.

  37. Hi,

    I am running windows 8 and I cant find the COM port .. it shows up under other devices.. So I’m stuck. Arduino uno shows up on COM4 and i tryed just guessing which one it could be but with out any result.

    Do you know how i could figure this out? :)

    Gr.
    Kevin

  38. Is there a method by which two arduino shields, one attached on arduino uno and another attached to arduino mega, can communicate each other?

  39. I got the Xbee’s to working.

    I have an application where a single Xbee is being used as a transmistter and all the remaining Xbee’s will just receive from the same Sender Xbee.

    Kindly let me know what changes do i need to make .

    Jeremy, hoping to hearing it from you

    Cheers

  40. hi, i want to send data form sensor with Xbee as Tx , data sensor receive with Xbee as Rx then show them on LCD.
    But but the data received on the lcd is still a decimal, how to convert it to ASCII?

    I’ve replaced the code

    lcd.setCursor(8,1);
    lcd.write(z); // I change it from lcd.print to lcd.write

    , the data is transformed into ASCII but the numbers appear one by one. for example the data appeared in serial monitor is 230.15 but the data that appears in lcd 2 then 3 then 0 then, then 1 and 5.

    after appearing a few times and then perform data error.
    Please help me Jeremy

    #include “LiquidCrystal.h”; // Gunakan library LCD

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // Inisialisasi LCD dan menentukan pin yang dipakai

    int z;

    void setup()
    {
    Serial.begin(9600);
    lcd.begin(16, 4);
    }

    void loop()
    {

    if (Serial.available() > 0)
    {
    z = Serial.read();

    lcd.setCursor(0, 1);
    lcd.print(“Sudut :”);
    lcd.setCursor(8,1);
    lcd.write(z); // I change it from lcd.print to lcd.write
    delay(200);
    }

    if (z>=25 && z<=335)
    {

    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Kemiringan Kapal");

    lcd.setCursor(16, 0);
    lcd.print("Kapal Berbahaya");

    lcd.setCursor(16, 1);
    lcd.print("Selamatkan Diri!!");
    delay(500);
    }
    else
    {

    lcd.clear();

    lcd.setCursor(0,0);
    lcd.print("Kemiringan Kapal");

    lcd.setCursor(16, 0);
    lcd.print(" Kondisi Kapal");

    lcd.setCursor(16, 1);
    lcd.print(" Aman Kapten");

    delay(1000);
    }
    }

  41. If i am using arduino serial port, to receive data from my xbee, it is eating away the only serial port on the arduino. . . i still want my application to output some result real time to a computer connected to Arduino. .

    What are my options to go about doing this

  42. Hi Jeremy THANK U SO SO MUCH!!! I am so glad i saw ur video. Now what if i dont want to do testing with ur program, instead i wanna try out something even simpler like one side on 1 side is a button is pressed and led connected on the other arduino will blink. Can u please show me a program for that??

    I Thank u in advance :D

  43. hi, first thanks for your work..
    I need to know if arduino Fio + xbee (operating voltage 3v3) can be use with your servo motor control tutorial?
    And in the same way, what about driving Dc motor wirelessly without motor shield by using transistor.. is it possible with Fio + xbee + transistor.. ?
    Thanks for your reply

  44. Hi jeremy, great video tutorials.

    I have one doubt in your program about that infinite loop at starting. why don’t you use serial interrupts rather than waiting the controller for serial data to come. In this program it’s okay.but while using long applications controller gets burdening to wait for data to come by using this kind of polling method.
    Hope we can use interrupts there.

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