We begin this tutorial by reviewing the basics of how to set up the Jaycon Systems Arduino compatible wireless xbee shield! After we have covered the basics, we swing into controlling motors wirelessly by incorporating a DC motor and motor shield. If and when you are working on your own project and get stuff and need to ask questions please do so by posting on our forum (http://www.jayconsystems.com/forum/)

Note: We assume you have already paired your Series 2 xbee modules. If not go to this tutorial here. If you are using Series 1 xbees.. then they are already paired out of the box so no need to mess with their settings. They are going to pair automatically and will communicate with your Arduino at a baudrate of 9600.
 
Here is a video demo for this tutorialhttp://youtu.be/xKuImcS2CFY


STEP 1: Gathering all the parts
Things you will need for this tutorial:

Pair of xbee modules (we use seires 2) - (JS-8385)
Arduino Uno R3 - (JS-3967)
xbee Explorer Board - (JS-3446)
Arduino compatible wireless xbee shield - (JS-1835)
Ardumoto V2 motor shield - (JS-2773)
DC Motor of your choisce
Mini/Micro USB cable
Arduino IDE Software and your computer
 

 

STEP 2: Install the xbee module in the explorer board, and also install the xbee shield in the arduino uno. 

Note: Make sure you have correctly installed the module and shield on to the boards facing the correct direction.

 

STEP 3: Wirelessly send your data.

A quick side note before we start, if you would like to connect your Arduino to a computer as well as this shield, you will need to make a few simple changes:

Move the switch on the wireless shield to the D4/D5
Solder the Rx and Tx jumpers on the wireless shield  
 



 

To use the shield in this configuration, you need to use a software serial library to create a secondary serial port on pins 4 and 5 of your Arduino. The SoftwareSerial library now comes with the latest Arduino IDE and has two great examples to get you started. I would recommend getting familiar with the SoftwareSerialExample.ino which created a new port on pins 2 and 3 of the Arduino.
 
Simply change the mySerial(2,3) to mySerial(4,5), and the mySerial.begin(4800) to match your xbees baudrate. Now if you need to send data to your xbee you would use mySerial.print("Hello"), and to send data to your USB port, you would use the standard Serial.print("Hello").
 

STEP 4: Remove the xbee wireless shield from the Arduino Uno and insert the motor shield; then reinsert the wireless shield. 



 

STEP 5: Connect the motor leads to your motor shield



 

STEP 6: Connect power to your Arduino board. You might need to use a ac/dc adapter to get enough power for all 3 circuit boards, your wireless module, and your dc motor. 


 


Step 7: Upload your code...our sample code has been tested and well commented

The code will not upload to your Arduino with the xbee in place since it is sharing the same serial port in this example. This is where that D4/D5 switch comes in handy! Simply move the switch over to the D4/D5 position during programming, and move it back when you see the 'Done Uploading" on the Arduino IDE. You can also remove the xbee during programming, but then you risk bending the pins.

/*
 Motor Shield by Jaycon Systems
 
 This example shows how to control 1 Brushed DC motor Using the Ardumoto V2 Shield (JS-2773 by Jaycon Systems)
 and a JS XBEE SHIELD FOR ARDUINO (JS-1835). You will also need two paired xbees of your choice at 9600 Baud, 
 and a USB Explorer Board (JS-3446) connected to your computer to send messages to the Arduino.
 
 The Program will turn on the motor on Channel B when it gets the correct message over a wireless connection.
 Message Structure example: 0xFE 0x01 0x90
  0xFE: is the command for the motor
  0x01: is the direction of the motor on channel B
  0x90: is the speed to set the motor (valid values range from 0x00 to 0xFF)
  
  
 Wiring:
 The shield must be powered using the VIn Max 18V screw terminals or the Arduino must be powered by the DC Barrel Jack.
 The motors will not turn if the Arduino is powered by the USB Port. Powering the Shield through the DC Barrel Jack is not recommended since 
 you risk burning the thin traces on your Arduino. One DC Brushed motors should be connected to the Channel B screw terminals.

 */


int PWMB = 5;    // PWM Pin for Output B
int DIRB= 8;    // Direction Pin for Channel B

char incomingByte = 0;

// the setup routine runs once when you press reset:
void setup()  { 
  pinMode(DIRB,OUTPUT);   // Direction Pin Output
  analogWrite(PWMB,0);    // Set motor speed to 0
  Serial.begin(9600);     // We need the Serial Port to get messages from the Xbee// the loop routine runs over and over again forever:
void loop()  { 
  if (Serial.available() > 2) { // wait for 3 bytes on the serial port.
     incomingByte = Serial.read();  // read the first byte
     
     if (incomingByte = 0xFE){   // check to see if this is a motor command
       
       incomingByte = Serial.read();  // if yes then read the second byte
       if (incomingByte == 0x01){     // this is our motor direction
         digitalWrite(DIRB,HIGH);      // Set Direction to High
       }else{
         digitalWrite(DIRB,LOW);      // Set Direction to Low if not 0x01
       }
       
        incomingByte = Serial.read();  // read the last value in the command, this is the speed
        analogWrite(PWMB, incomingByte);       // Set Speed for Output A (0-255)
        Serial.println("OK");                 // print an OK to let us know it worked!
     }
  } 
}


Step 8: Send the signal from your computer to the receiving module.

Open the X-CTU software. We like to use the built in terminal in X-CTU because it has a great little assemble packet command.

 
 
Make sure your baud rate is correct (this was set by you earlier when you paired your series 2 xbee modules). We set the baud rate to 9600. Then click Test/Query.. If successful you will see this pop up window.

 
 
Now click the Terminal tab which allows you to send and receive data from your xbee, then click the Assemble Packet button. A new window will pop up.

 
 
In this new window select the HEX radio button. Now you are ready to assemle and send your packet. 

To compose a packet for this example you need to enter 3 things (this was defined directly in our Arduino code). FE, then the direction which is indicated by 00 for direction 1, and 01 for direction 2. The third item you need to enter is the speed from 00 to FF. Where 00 (Decimal 0) is off and FF (Decimal 255) is full speed ahead! The speed is in hexadecimal format so you can use your favorate search engine to find a converter. A chart can be located on this wikipedia page.

The format for these 3 entries are xx xx xx (X-CTU places the spaces automatically).

 
 
Lastly you click the Send data button to wirelessly send the packet to the receiving xbee module. The Arduino code will interpret  the packet and set the direction and speed on your motor! 

Hopefully this example was helpful in getting started with wireless control. Remember that this is a pretty simple example and you can add as many fields as you like in your packet; to control a number of different things! From servos, to LED's to your Car!. The sky is the limit! 

If you have any questions on this example, don't hesistae to post a comment, shoot us an email, or post it in our forum! We would be glad to help you tackle your next wireless project!