Xbee + motor control shield - how??

Hi there.
I am building a line-follow robot, and I have a few questions:

  1. I am trying to figure how to combine the arduino + motor control + xbee.

I have this xbee board: XBee adapter - Simple wireless communication.
This motor control board: http://www.amazon.com/Motor-control-shield-KIT-Arduino/dp/B002VH9APQ.

As you can see, nor the xbee or the motor control has an input pins (I can stack shield on top of shield).

How can I connect them? if you have a link with pictures/explanations/videos, that will be fantastic!

  1. i’m attaching the code I wrote to my robot (It got 4 sensors - two on the front and two rear once), my idea is that the robot will be able to take turns (like the maze solve robot 3pi), so far so good,
    my question is - how to control the arduino using the xbee? (how to transfer data from my pc to the arduino using xbee?)…

code:

// analog sensors
int FrontSensorR = 0;    
int FrontSensorL = 0;  
int BackSensorR = 0;   
int BackSensorL = 0;
//motors
int RMotorDir = 12; // Direction pin for motor B is Digital 12
int LMotorDir =12;// Direction pin for motor A is Digital 12
int VelMotorR = 9; // Speed pin for motor B is Digital 9 (PWM)
int VelMotorL = 10; // Speed pin for motor B is Digital 9 (PWM)
int speed = 50;
int OutLine=250,OnLine=300;
int sf=0,delay1=600,timeflag=0,code=0,checking=0,k1=0,sum=0,Asum=0;
int flag1=1,AR=1,ActiveSensor=0;
int q=2,q1=0;// Junction Number

void setup() {
  Serial.begin(9600);
  
  pinMode(RMotorDir, OUTPUT);
  pinMode(LMotorDir, OUTPUT);
  
  pinMode(0, INPUT);   // digital sensor is on digital pin 0
  pinMode(1, INPUT);   // digital sensor is on digital pin 1
  pinMode(2, INPUT);   // digital sensor is on digital pin 2
  pinMode(3, INPUT);   // digital sensor is on digital pin 3
   
}

void loop()
 {
    checking=q1;
    FrontSensorL  = analogRead(0);
    FrontSensorR = analogRead(1);
    BackSensorL = analogRead(2);
    BackSensorR= analogRead(3);
     // send sensor values for printig
     Serial.print(FrontSensorL, DEC);
     Serial.print(",");
   
     Serial.print(FrontSensorR, DEC);
     Serial.print(",");
     Serial.print( BackSensorL, DEC); 
     Serial.print(",");
     Serial.print( BackSensorR, DEC); 
     Serial.print(",AR=");
     Serial.print( AR, DEC); 
     Serial.print(",checking=");
     Serial.println( checking );
     delay(50);
  
      
   
  if (AR==1) //Active Regime 1,Follow Line 
  {
  code=0;
  ActiveSensor=BackSensorR;
    if (FrontSensorR < OutLine && FrontSensorL < OutLine )// Correction to Left
    {
  digitalWrite(RMotorDir, 12); // set direction
  analogWrite(VelMotorR, speed); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, speed); // set speed (PWM)
  sf=0;
     }
       
  if(FrontSensorL < OutLine  && FrontSensorR > OnLine)// Correction to Right
     {
  digitalWrite(RMotorDir, 12); // set direction
  analogWrite(VelMotorR, speed-sf); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, speed+sf); // set speed (PWM)
  sf=+10; 
     }
     
     if(FrontSensorR < OutLine  && FrontSensorL > OnLine)
     {
  digitalWrite(RMotorDir, 12); // set direction
  analogWrite(VelMotorR, speed); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, speed-sf); // set speed (PWM)
  sf=+10; 
     }
  if(BackSensorR > OnLine &&  BackSensorL < OnLine)
 {
  digitalWrite(RMotorDir, 12); // set direction
  analogWrite(VelMotorR, speed); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, speed); // set speed (PWM)
 }
   }
  //////////////////////////////////
    if(AR==2)// Active Regime 2: Turn Left on Junction
  { 
    ActiveSensor=FrontSensorR;
    if(code==1)
    {
      AR=1;
      ActiveSensor=BackSensorR;
    }
  digitalWrite(RMotorDir, 0); // set direction
  analogWrite(VelMotorR, speed); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, speed); // set speed (PWM)
  
    
  }
  ////////////////////////////////////
  
  if(AR==3)// Active Regime 2: Turn Left on Junction
  { 
    ActiveSensor=FrontSensorL;
    if(code==1)
    {
      AR=1;
      ActiveSensor=BackSensorR;
    }
  digitalWrite(RMotorDir, 12); // set direction
  analogWrite(VelMotorR, speed); // set speed (PWM)
  digitalWrite(LMotorDir, 12); // set direction
  analogWrite(VelMotorL, 30); // set speed (PWM)
  
    
  }
  
 /////////////////////////////
 if(FrontSensorL > OnLine && FrontSensorR > OnLine && q1==q ) 
  {
    AR=2;//go to new Active Regime
  } 

  
   
     //GetCode
     if ( ActiveSensor > OnLine  && k1==0  ) // 
  {
    
    extern volatile unsigned long timer0_millis;
    timer0_millis = 0;
    timeflag=millis();
    k1=1;
     Asum=0;
      
  }
  if (millis()<timeflag+delay1)// Scanning Time
  {
  flag1++; // Scanning Number kamut srikot
  sum=sum+ActiveSensor;//
  }
  
    
  if (millis()>timeflag+delay1)// Scanning Result
  {
    Asum=sum/flag1;
    flag1=1;
    sum=0;
    
    if(ActiveSensor < OutLine)
    {
    k1=0;
    }
    
      
  }
  if (Asum > OnLine)
  { 

    if(millis()>timeflag+delay1 && ActiveSensor==BackSensorR && BackSensorL < OutLine)
    {
      q1++;// placing code
    }
    
    code++; // service code
   
    }
 }

You do have two xbees, right? One is connected to the Arduino on the robot, and one is on the xbee Explorer USB device.

http://www.sparkfun.com/commerce/product_info.php?products_id=8687

The serial data send from the PC is transmitted by the xbee attached to the computer to the xbee attached to the Arduino. To the Arduino, it looks just like the data came from the USB cable.

Use Serial.read on the Arduino to read the data received by the xbee.

ok, thanks. Question is - how to physicly connect the arduino + xbee + motor control? (the xbee shield nor the motor control has a stackable input)

The xbee board you have is equivalent to the XBee Regulated USB from Sparkfun that I posted the link to. It is not a shield that can be directly plugged into the Arduino. You'll need to connect it to a breadboard, and run wires to the Arduino, or solder the wires directly to the board, and run them to the Arduino.

You might need to create your own shield that goes between the Arduino and the motor shield that breaks out the pins whatever way you need. It's not that difficult, and is quite rewarding when the PCB arrives, and you solder on the headers and it works.

Thank you for your answer.

Do you have any idea how to connect it (the xbee) to the arduino? meaning - which goes to where..?

Thanks

You only need to connect 4 wires - +5V, RX, TX, and Gnd. +5V and Gnd connect to +5V and Gnd on the Arduino. RX and TX connect to the digital side - pins 0 and 1. RX on the Arduino and TX on the xbee get connected. TX on the Arduino and RX on the xbee get connected.