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:
Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.
387 comments
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!
Looks terrifuc. I hope my XBees arrive soon.
i m new to arduino and want to kno all arduino function used for arduino programing so that i can make my own program
http://www.arduino.cc/en/Reference/HomePage
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
Yes, it is possible, and quite easy. If you get that sparkfun board I showed, you can plug it in and it will treat it as a serial connection.
The X-CTU program from Xbee is REALLY nice for configuring the Xbee modules.
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?
Thanks! Just released a new one today.
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
That shouldn’t be an issue so long as the two IDs are different. Just change the ATDL on the other transceiver to match.
Hi,
Thanks for the great tutorials.
Is it possible to use xbees for simple communication without any configuration?
dan
No, you generally need to assign IDs
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.
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
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.
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
Did you set the jumpers correctly, etc?
Thanks for this great tutorial!
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 ?
yes.
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?
Are you flushing the serial buffer on the receiving end after you read the byte? You might be sending data faster than you can receive it.
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
Do you see any lights on the adapter? Can you confirm that it is the one with the FTDI chip on it?
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
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?
instead of saying ‘OK’ says ‘ERROR’…no more comments
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.
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?
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.
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
Oh P.s im trying to switch domestic lighting throughout the house is my main goal and on from there…
cheers
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?
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.
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.
I haven’t used it. But if you use it, and like it, let me know!
And yes I am going to be using an accelerometer to get the data.
I have a question.
I somehow can’t get OK when I type three +s at the beginning
do u know what’s wrong?
You must not have a connection to the Xbee. Ensure it’s plugged in, lights are blinking, and that baud rates are set correctly.
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?
The baud rate is probably wrong. Try connecting at all the common baud rates to see if one works. You can also try using x-ctu
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?
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.
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?
Yes they do. You could modify the code to track the variable and to only enter the transmit routine when a change is detected.
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
You’ll need to look at the documentation. S2 Xbees are designed for mesh networking, and I’ve never used them before.
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 ?
Should be fine. You might experience some packet loss.
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?
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.
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?
That depends on where you bought them – Sometimes they come preconfigured.
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!!!
Yes, they are compatible.
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!
Hook one Xbee up to your computer using the sparkfun USB adapter that I showed in this video,
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?
The arduino Mega has multiple UARTs. You might be able to use one for each.
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
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
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
I’m hoping to do a bluetooth tutorial very soon that will explain this.
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…
Start without the wireless and get the sensors working. Then worry about adding wireless functionality.
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();
}
Are you using arduino 1.0? If so, you may need to change how you are doing the flush. See my edit to the post above.
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?
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
You can get it here: http://www.cooking-hacks.com/index.php/communication-shield-xb-bt-rfid.html
Hi Jeremy! Can I use other Zigbee modules aside from Xbee pro for my Arduino?
Yes, I was using an xbee model 1.
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);
}
You should probably flush the serial buffer by running Serial.read() in a while loop until the buffer is empty on each run through loop()
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…
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…
thanks alot…could i make one repeater without using uno…i want the repeater cost to be as low as possible…
I’ve never tried this, but you might be able to hookup the RX/TX lines of two Xbees to make a repeater. Not sure if it would work, though.
Thanks alot…:)
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
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.
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
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.
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
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!!!
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.
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?
Yes, you need to wait for serial.available() to contain 8 bytes of data, then run Serial.read() 3 times to get all the values.
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 !!!!!
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
Just have the transmitting arduino send data once per second (for example), and the receiving arduino always checking and clearing its buffer for data.
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.