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
Hi Jeremy,
Your videos has been of great help these past weeks.
I have my accelerometer connected to the Arduino UNO with an XBEE shield. So do I need to buy another Arduino UNO with XBEE shield connected to my computer to receive input from my accelerometer to my computer?
Thanks!
You don’t need another Arduino. Just a USB xbee explorer from sparkfun.
Good day,
Could you re-visit but this time with xbee series 1?
Thank You
The tutorial is done with XBee series 1.
link pls
can u pls tell the smae thing using xbee series 2
sir can i get code for xbee communication using arduino mega 2560.
Hi Jeremy,
Thank you so much for your videos. I have 5 Arduino boards that are logging data. I would like to send the data from these 5 devices to my computer.
Would the best way to accomplish this be to :
-Get 5 Arduino boards
-5 Xbee shield with 5 Xbee
-USB Xbee explorer + Xbee for computer
Thanks for the help!
Thank you Jeremy,
This video clear and perfect
really thnx
Could you re-visit but apply 2 pots? Goal would be to pass 2 analog signals
Thank You
Hi Jeremy,
I was working on a project where I needed to communicate data between two arduino: one that has a force sensor, the other has a motor attached to it. Is it possible to just use a bluetooth device for this instead of an xbee? Are there any disadvantages to this approach?
I haven’t personally used bluetooth for this purpose, but I see no reason why you wouldn’t be able to do it.
Hi Jeremy,
Thanks so much for the tutorials, they’re a real help to a big project I’m working on. I have been having problems though with step. Ive followed this tutorial the way you’ve done, except I used the jumper-switch to program the Xbee instead of an explorer, and am using an Arduino Mega 2560 instead of Uno. When I upload the code the potentiometer-arduino works well. However, the arduino with a servo receives random numbers from 0 to 160 and will often pulse between two numbers in a way not connected to the actions of the potentiometer whatsoever. Do you know of anything that could cause this?
Thanks so much
A quick update, I had to edit the motor program as the original kept giving this error, which I unfortunately could not understand how to remedy:
In function `__vector_default’:
(.vectors+0xdc): relocation truncated to fit: R_AVR_13_PCREL against symbol `__vector_55′ defined in .text.__vector_55 section in core.a(HardwareSerial.cpp.o)
With the edited program, which has brackets for the while loop and a “int data” added at the beginning, the xbee receives data, but only so long as the reset button is held. Also, the servo does not match the given position.
Sorry to be asking so many questions, the help means a lot to me
To provide more information, the servo-arduino only shows the received data on the com port with reset held while the jumpers are on the outermost pins while the transmitting pot-arduino’s pins are on the inside
Nevermind to all prior, it’s working now. Thanks again though for such a great tutorial!
Hi Jeremy!
Great videos! I´m currently working on my interaction design thesis proyect and they help a ton.
I just have this issue, I have two ultrasound distance sensors (HC-SR04) and I want them to send the data wirelessly to an Arduino. For that I´m thinking of a 433Mhz RF receiver – transmitter setup. Now problem is that I only have one Arduino UNO (receiver) and a bit of a tight budget, so my question is it´s possible to connect a distance sensor and a receiver and get them to work without using another two Arduino boards (as transmitters)?
If not, is there some reduced/cheaper version of an arduino board that I could use? Or maybe a different distance sensor that don´t require an Arduino?
Thanks a lot!
sir my project also same like yours…. my project is to detect an object using ultrasonic sensor and sound an alarm though RF 433 MHZ transceiver……am using 2 arduino Mega as controller and HC-SR-04 …please help me to program the arduino…..pls send mail to [email protected]……thanks in advance..
Hey Jeremy,
As I don’t have another arduino, i’m wondering if I could set up this module to transmit data to my smartphone. Is this possible? If so some direction would be appreciated.
Thank for the help
hello friend
i have esc to control motor. how i connect in to the radiuno…
what is the program….. if you can help me….please tell me.
thank you
Hi,
I have been working on a wireless tire pressure monitoring system. I am using an arduino nano that is getting air pressure through a sensor and transmitting the results over an RF link. I am planning to link the nano to an RFM02 transmitter over SPI. Would someone assist me in the syntax to link the two? Thanx in advance.
hi victor could you try this code
// include the SPI library:
#include
//int pbIn=0; // Interrupt 0 is on digital pin 2
// set pin 10 as the slave select for the RFM02:
const int slaveSelectPin = 10;
int RFM_IRQ =2;
void setup() {
Serial.begin(9600);
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.begin();
pinMode(RFM_IRQ, INPUT);
digitalWrite(RFM_IRQ, HIGH); // pull-up
init_radio();
send_command(0xC039); // open tx
packet();
// send_command(0xC001); // Close tx
}
void loop() {
//uint16_t sttus=send_command(0xCC00); // Status command
//Serial.println(sttus);
}
uint16_t send_command(byte cmd)
{
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin,LOW);
// send in the command via SPI:
SPI.transfer(cmd);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
void init_radio()
{
uint16_t stat=send_command(0xCC00); // Status command
Serial.println(stat,HEX);
send_command(0xA620);//433BAND,+/-150kHz
send_command(0xA620);//433.92 MHz
send_command(0xB000);// 0dB output power
send_command(0xD040);//PLL settings, datarate/2
send_command(0xC823);//4800bps==data rate
send_command(0xC220);//ENABLE BIT SYNC
send_command(0xC001);//enable clk out but CLOSE ALL processes
delay(10);
Serial.println(“Radio initialized”);
pinMode(RFM_IRQ, INPUT);
digitalWrite(RFM_IRQ, 1); // pull-up
}
void packet()
{
digitalWrite(slaveSelectPin,LOW);
byte Checksum=0;
RF02B_SEND(0xAA); // send Preamble
RF02B_SEND(0xAA);
RF02B_SEND(0xAA);
RF02B_SEND(0x2D); // Synchronisation head high byte
RF02B_SEND(0xD4); // Synchronisation head low byte
Checksum += 0x10;
RF02B_SEND(0x10); // Data 0
Checksum += 0x11;
RF02B_SEND(0x11); // Data 1
Checksum += 0x12;
RF02B_SEND(0x12); // Data 2
Checksum += 0x13;
RF02B_SEND(0x13); // Data 3
Checksum += 0x14;
RF02B_SEND(0x14); // Data 4
RF02B_SEND(Checksum); // Checksum
Serial.println(Checksum,HEX);
RF02B_SEND(0xFF); // Dummy byte
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin,HIGH);
}
void RF02B_SEND(unsigned char aByte){
unsigned char i;
for(i=0;i<8;i++){
//while(PIND&(1<<RFXX_SDO));//Polling nIRQ
//while(!(PIND&(1<<RFXX_SDO)));
attachInterrupt(0,help,FALLING);
if(aByte&0x80){
digitalWrite(9,HIGH);//PORTB|=(1<<1);
}else{
digitalWrite(9,LOW);//PORTB&=~(1<<1);
}
aByte<<=1;
Serial.println(aByte,HEX);
}
}
void help()
{
Serial.println("it works");
}
/*
void RF02B_SEND(unsigned char aByte){
unsigned char i;
for(i=0;i<8;i++){
while(PIND&(1<<RFXX_SDO));//Polling nIRQ
while(!(PIND&(1<<RFXX_SDO)));
if(aByte&0x80){
PORTB|=(1<<RFXX_DATA);
}else{
PORTB&=~(1<<RFXX_DATA);
}
aByte<<=1;
}
}
*/
Hi jeremy.
Have you used the ethernet shield .Am finding trouble in posting data to a database using the ethernet shield
Yes, the last chapter of my book focuses on using it.
Hi Jeremy,
I am busy working on this project, what i do is take reading from temperature sensors and send them using xbees but the problem is I am not reading the same values that I am sending.
Can u please give suggestions.
Hey Jeremy, first I’d like to say you rock man, I’ve searched everywhere online and your tutorials are second to none.
So here is what I am trying to do, I’m a newb at arduinos, so this is what I need, I have a Mega 2560, a pair of XBEE’s and an SD shield by Seeedstudio, which doesn’t quite fit the Mega.
I want to capture data and log it to the SD card then I want to use bluetooth to pull the data to a laptop.
Is this doable with the components I have and if so can you point me in the right direction to help me get this done?
Here are the components I have.
https://www.sparkfun.com/products/11061
http://www.seeedstudio.com/wiki/SD_Card_Shield_V3.0
http://en.wikipedia.org/wiki/XBee
why doesn’t that work with the Mega 2560 ? and how do i make it work ?
i use the Mega 2560 and xbee zb s2
plz provide m the circuit diagram i.e how u connected th xigbee module with arduino uno….
i didn’t connect the Xbee to the Arduino uno i use Arduino Mage 2560.
i use xbee s2 1mw and xbee shield
Hi Jeremy,
I have found all your videos very useful, is there any chance of making one to explain how to code NRF24L01 please?
Best Regds
Hi Jeremy,
Kindly please advise as when i key in the command ‘ATMY1000’ , it shows ‘error’. Thanks!
Do you get the ‘ok’ when you go into command mode with ‘+++’?
Hello Mr. Blum I am a future EE working on a wireless project and im in need of your help. I am trying to get the ultrasonic sensor to display on the lcd 16×2 wirelessly. My question is, will the code that you use in the wireless tutorial be enough to display data on the lcd or is there more to it??
Hi Jeremy, thanks for the reply! I did get OK with the command mode ‘+++’
hi jermey,
i got “OK” in command mode with ‘+++’ but when i key in the command ‘ATMY1000′ , it shows ‘error’
And another thing why are my sheilds blinking red and not green because i have the exact same everything as you do and I followed all the proper steps for programming them??
Hi Jeremy,
cool tutorial! i got my Xbee S1 just yesterday and tried to configure it with a USB explorer but it just would not reply. it just heats up.
i googled my problem and tried out changing serial settings on my PC, but still it would not work.
need your help!
Regards
Abel
How hot does it get? Did you plug it in backwards?
Hi Jeremy,
at first yes, but now i configured both my xbees successfully with arduino and an xbee shield works fine…the alternate method that you demonstrated.
Thank God the Xbees still work!!
and no it does not even give me OK with +++ on the PuttY also not with the X-CTU software…
I am designing a proof-of-concept/prototype that involves wireless communications.
I need to do this over a large distance. With the xbee’s I see they offer several different modules.
For the proof of concept — can I use a less expensive module; then once proven & receive funding; buy a longer-range (more expensive) xbee and leave the rest the same? (code, xbee sheild, etc)
Thank you
-josh
ps: great tutorials!
Hi Jeremy,
Your tutorial is great.
I would like to control 6 servos from 6 joysticks through xbee. How can I code to transmit these signals? And, I want to increase the range of signal from 0-9 to 0-255.
need your helps,
Regards,
Hoan
JEREMY-
I AM TRYING TO CONFIGURE A FEW XBEE S1’S WITH AN ARDUINO FIO V3. I EXPECTED I WOULD NOT NEED AN XBEE EXPLORER, AND I COULD CONFIGURE THE XBEE WHILE IT IS MOUNTED TO THE FIO V3, HOWEVER, X-CTU DOES NOT SEEM TO RECOGNIZE MY XBEE. I HAVE PLAYED WITH BAUD RATES AND A FEW OTHER SETTING. I ALSO TRIED THE “XBEECONFIGTOOL”, BUT NO LUCK. IT SAYS IT CANNOT ENTER COMMAND MODE. I TRIED HOOKING ONE OF THE XBEES UP TO AN FTDI BOARD THAT I HAD LYING AROUND, BUT THE BOARD IS 5V, NOT 3.3V. I MADE SURE TO REGULATE THE SOURCE VOLTAGE DOWN TO 3.3, BUT THE TX/RX LINES WERE LIKELY STILL AT 5V. NOT SURE HOW DANGEROUS THAT WAS, BUT I HAVE A SPARE XBEE THAT I DID NOT HOOK UP TO THE FDTI AND IT ALSO WON’T CONNECT. USING THE FTDI AT LEAST GOT ME TO THE POINT WHERE X-CTU WOULD PROVIDE SOME SMALL AMOUNT OF INFORMATION ON MY XBEE.
AFTER HITTING “TEST” AND RESETTING THE XBEE, X-CTU WOULD RETURN A SMALL WINDOW THAT HAD THE HARDWARE ID, BUT NO OTHER INFORMATION. IT SAID MODEL TYPE = NAME UNKNOWN, SERIAL NUMBER = , MODEM FIRMWARE VERSION = , AND COMMUNICATION WITH MODEM .. OK.
DO YOU HAVE ANY THOUGHTS ON HOW I CAN CONFIGURE MY XBEES. ALSO, I TRIED USING A TERMINAL WINDOW TO CONFIGURE, AND WHEN I TYPE +++ I GET NO RESPONSE.
THANKS FOR ANY HELP YOU CAN OFFER.
-MICHAEL
hi im trying to run a program on my uno arduino with processing and arduino, theres somthing i have to edit in the processing code so that my processing is connected to my arduino program or whatever. im totally confused with ensuring the programs are connected. btw the program is simply click the screen on processing and it turns the led on etc..
Hello! This is a really helpful video!
But i don’t have a xbee explorer now, and i am out of time to buy one. Can you teach me how i can configure the xbee only with the arduino i detail?
Many many thanks!
Hmm,
When I try to enter programming mode on series ones…I get no response. On series 2 devices, I can enter programming mode, but typing ATMY1000 just yields an error.
Just trying to program using putty with my sparkfun breakout.
No idea why this is non-functional.
Hello Sir Jeremy,
I was working my thesis.My thesis was all about wireless door lock using xbee.could it be possible to drive a solenoid to unlock or lock the door using wireless communication and how can I resolve this.
I am very greatfull that you read and hopefully respond my problem.
Thanks a lot and more power
Yes, that’s possible. You can drive a solenoid in much the same way that you drive a motor.
Can you please help me or shall I say give me a hint for this on how to control solenoid?
.thanks
Hi,
This is a great tutorial. So what I am tryong to do is send and receive data from the xbee. I have a LED on pin 9 of the arduino and a switch on pin 8. I have a xbee with xplorer connected to the computer. So the xbee should send the status of the switch. (which it is doing right now as expected.) I also want to be able to send it a serial msg from the computer and turn the led off/on. How do I achieve this 2 way communication?
thanks
Rituparna
Hi Jeremy,
I am trying to program the xbee using the sprakfun usb serial adater in putty. When I type in +++ I do not get any response back can you please let me know the solution to this problem.
You probably don’t have the baud rate set correctly.
Thanks a lot for such an useful tutorial. I am using labview to read analog values from sensor using arduino for acquisition of signal via usb cable. Now i want to replace the cable by wireless xbee and view the analog values in labview as that can be viewed in serial monitor of arduino. previously i have been successful in reading analog values of sensor in labview via arduino. now when i connect coordinator xbee to arduino and the arduino to labview, it shows error in labview. please help me with the code in arduino that will both recieve data from xbee and sent it serially to labview.
I have attached here the code used for labview interface in arduino
#include
#include
#include
#include “LabVIEWInterface.h”
/*********************************************************************************
** setup()
**
** Initialize the Arduino and setup serial communication.
**
** Input: None
** Output: None
*********************************************************************************/
void setup()
{
// Initialize Serial Port With The Default Baud Rate
syncLV();
// Place your custom setup code here
}
/*********************************************************************************
** loop()
**
** The main loop. This loop runs continuously on the Arduino. It
** receives and processes serial commands from LabVIEW.
**
** Input: None
** Output: None
*********************************************************************************/
void loop()
{
// Check for commands from LabVIEW and process them.
checkForCommand();
// Place your custom loop code here (this may slow down communication with LabVIEW)
if(acqMode==1)
{
sampleContinously();
}
}
waiting for your reply.
pls mr jeremy to a tutorial using the simplest library on 433mhz tx and rx . a program that can be used to turn on or off an led on the rx side using just a push switch on the tx side please. God bless
Hi Jeremy!
Thanks alot for the tutorial videos. Although I’m a mechanical Engg but your videos made it very easy for me to understand the basics of the ardiuno.
I’m planning on making a small home automation system using a RF module.
Can you please me guide me through it?
Hey Jeremy,
Is there a way to connect an xbox controller to an Arduino and get it to control a motor on an other Arduino?
Hi Sir
Im Newbie to Arduino and i Have Graduate Project in my college so can you give me some help
and guide me to buy Buy The Tool And Arduino Boards And Shields to start working in my project (i Will Depend on what you say)
My Project Is Mmake connection between two Arduino board via xbee shield to send signal
from First board to second board to control or Run Any Thing Connected in The Second Board
@@@@
see the photo please in link below
@@@@
the distance between the two board is 200 or 150 Meter
i Don’t know what XBee shield should i use
i think the model “XBee Pro 60mW Wire Antenna – Series 1 (802.15.4)” is enough to me
https://www.sparkfun.com/products/8742
but my problem is with the Arduino board
I’m new and I’ve never use Arduino board before so of course you will Say Buy Arduino UNO R3
but i need To connect two LCD Screen and WAVE player shield And Xbee shield And Photoresistor
and i don’t think that the ” UNO R3 ” have enough Pin to connect 2 LCD And Xbee shield
So is ” Arduino Mega 2560 ” enough to me and is it able to connect all this thing
and the most important thing can i connect the
” shield XBee Pro 60mW Wire Antenna – Series 1 (802.15.4) ” directly with ” Arduino Mega ” with out need to buy any Add-Ons or shield
sir i have no time only 3 months to start working for my project
and the most important thing is im from IRAQ there is no Arduino Shop that’s mean i should make order from internet and what between 25 to 35 day to receive the shipment
if you have any suggestion or any note please tell me (i will put it in my mind and depends on it to make
my order and buy all the things i need)
and another question is it very important to ” XBee Explorer USB ”
why should i need to programming the xbee shield
can i connect it to arduino board and use it without programming it
thank you very much sir
MY REGARDS
Hi,
I am trying your code to run 4 brushless motors on my quadcopter using xBees Series 2. I have hooked up every thing like you have done in your video. However, I have made slight changes in the code. Here is my code:
int potPin = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
int val = map(analogRead(potPin), 0, 1023, 0, 179);
Serial.println(val);
delay(50);
}
The Other code for reading and running the motors is:
#include
int servoPin1 = 3;
int servoPin2 = 5;
int servoPin3 = 6;
int servoPin4 = 9;
Servo myServo1;
Servo myServo2;
Servo myServo3;
Servo myServo4;
void setup()
{
Serial.begin(9600);
myServo1.attach(servoPin1);
myServo2.attach(servoPin2);
myServo3.attach(servoPin3);
myServo4.attach(servoPin4);
}
void loop()
{
while(Serial.available() == 0);
int data = Serial.read() – ‘0’;
int pos = map(data, 0, 1023, 0, 179);
pos = constrain(pos, 0, 179);
Serial.println(pos);
myServo1.write(pos);
myServo2.write(pos);
myServo3.write(pos);
myServo4.write(pos);
Serial.flush();
}
However, there is a problem. The xBee attatched to my computer is reading the values of potentiometer fine and its doing as I want it to do. However, the xBee attatched to the motors is going all over the place. Through the serial monitor, I can see the values coming in the arduino from xBee however, these values are random. They change as I move the knob of the potentiometer; however they are not doing what I want it to do. The values that are being transmitted are random values.
I have configured the xBees using X-CTU rather than PUTTY. However, the fact that the xBees are communicating shows that they are configured fine.
I am really confused and dnt know how to go about this :(
I really need help pleaseeee :((
try replacing
Serial.println(val);
with
Serial.print(val);
and
Serial.println(pos);
with
Serial.print(pos);
Hi,
Firstly a great simplified video Jeremy, thanks. I have successfully communicated 3 Xbee’s which have been connected to an arduino individually, by using the method of ‘Broadcast’.
For my current project I need to use 3 Xbee’s to communicate wirelessly which will ‘Transmit’ & ‘Receive’ information from each stage. I am struggling with coding and have come at a standstill, with time running out.
I would appreciate it if someone can help me out with a program that will request where a particular XBee is in API mode after which this particular device will then send back its RSSI information.
Please help.
Perhaps you can tell me the best way to connect my mesh network to the company wifi. I would appreciate this very much. The system looks like:
Mesh Network Architecture:
The nodes are Arduinos (not sure which Arduinos yet), with Xbee transmitters. Each node will have a sensor.
To start with, I am using PH sensors. The coordinator will be an Arduino Mega, with an Xbee receiver. The
coordinator needs to send the sensor data via the company Wifi system to the internet.
UNKNOWN: The Best way to transmit the sensor data from the coordinator to the WiFi system
Two possibilities that I know of:
1. The Arduino Mega could have a Wifi shield. It would also have to have a Xbee shield. I do not know
if I can have both shields on the Mega. And if I can, will there be interference between the Xbee and Wifi ?
2. I can have another Arduino connected to the coordinator. The coordinator would have the Xbee shield, to receive
the node data. The second Arduino would have the Wifi shield. I do not know how I would connect the two Arduinos.
I know there is a USB and serial port. Would either of these work to transfer the data from the coordinator to the
second Arduino?
Hi Jem:
If I have a large amount of endpoints configured as routers (about 30000), can I have several coordinators to divide the network? Some like 10 coordinators. Then, how can I centralize all the coordinators?
Any ideas?
Hi ,Jeremy!
I have seen your tuto and apreciate it but i don’t understand the command you did for configurate the xbee.
I have 2 arduino with xbeeshield including to the 2 arduino without any sparkfun, I must connect the 2 arduino and so send data from a water sensor and temperature sensor to the other arduino wirelessly.
How can i do that ? Thank you to reply.
Will this work with the sparkfun xbee shield? Do I have to do anything different hardware and software-wise?
why don’t u use analog joystick and then transmit it by your xbee in API mode.
Should work fine. You might have to change some pin numbers.
hiii
Jeremy Blum
im doing my project to control rc engg .
so i have to control servo motor by using potentiometer with the help of aurdino.
but it should be wire less ..
will u plz help me .
or recomnd me any site ,from wer i get the knowledge
its an urgent
i am waiting fr reply plz plz plz reply soon
Raj
hi jermey ,
u are a genius!!!
i am not able to sent two analog data at a time using xbee .
please reply soon.
sir my project is to detect an object using ultrasonic sensor and sound an alarm though RF 433 MHZ transceiver……am using 2 arduino Mega as controller and HC-SR-04 …please help me to write the program….
Hello
I configure the 2 xbees using the putty and everything worked well.
but i try the arduino to code to only print hello message
but it not working
i tried to configure the xbee again but i didn’t get “OK” after +++
also i tried the X-CTU but same problem occur
this is the code:
Sender:
void setup()
{
Serial.begin(9600);
}
void loop()
{
Serial.println(“hello”);
delay(5000);
}
————————————
receiver:
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.avilable() > 0)
{
Serial.write(Serial.read());
}
}
HELP plz!
I HAV THE SAME PROBLEM…HOW TO GO ABT IT?
I HAV THE SAME PROB…WAT TO DO?