DFRobotShop Rover W/Xbee and Joystick





Introduction: DFRobotShop Rover W/Xbee and Joystick

About: I make projects, they have names. Some are obscure and some straightforward. Form or Function; I go either way. Battery powered or edible, I love making things.


Rover Obstacle Course from Aleksei Sebastiani on Vimeo.  Thanks to Red Vines and Phillip K Dick.


Goal: To get my DFRobotShop Rover to talk over xbee and be controlled via an Analog Joystick.


The Rover  from DFRobotShop $90 (My prize from this Instructable!)
Joystick Shield from Sparkfun $13
ProtoShield from AdaFruit $13
Xbee and Adapter MakerShed $35 (you'll need 2 of these)
Halfsize Breadboard Adafruit $5
Arduino Uno from Adafruit $30
FTDI interface  IteadStudio $9 (FTDI cable, or de-chipped arduino also work)


Solder iron
Jumper wires
USB cables of all sorts
Aleve, Lots of Aleve


http://www.ladyada.net/make/xbee/index.html (AdaFruit Tutorial)
http://www.digi.com/support/kbase/kbaseresultdetl.jsp?kb=125 (XTCU Software)
http://www.sparkfun.com/tutorials/171#setup (Joystick Turorial)
http://www.robotshop.com/content/PDF/dfrobotshop-rover-user-guide.pdf (Rover Manual)

Step 1: Wiring

The Rover:

Assemble Rover as per Robotshop instructions. Same with the Joystick and Xbee shields. Place protoshield on the rover and Xbee adapter on top. Start connecting wires.
Xbee RX⇒TX on the Rover
Xbee TX⇒RX on the Rover
5volts to 5Volts and Gnd to Gnd

Joystick Shield:

Arduino TX⇒RX Xbee
Arduino RX⇒TX Xbee
5volt to 5volt and Ground to Ground

And that's it.

Step 2: The Code for Arduino Uno(Joystick)

//Code from Sparkfun with a few tweeks to get it working with Rover.  Rather than serial printing 
//words, I switched it to print the letters that the rover sketch understands. 

const byte PIN_ANALOG_X = 0;
const byte PIN_ANALOG_Y = 1;

const int X_THRESHOLD_LOW = 450;   //I have the contrains real big so there's less chance for 
const int X_THRESHOLD_HIGH = 550;  //analog misinterpretation. 

const int Y_THRESHOLD_LOW = 450;
const int Y_THRESHOLD_HIGH = 550;

int x_position;
int y_position;

int x_direction;
int y_direction;

void setup() {

void loop () {
x_direction = 0;
y_direction = 0;

x_position = analogRead(PIN_ANALOG_X);
y_position = analogRead(PIN_ANALOG_Y);

if (x_position > X_THRESHOLD_HIGH) {
x_direction = 1;
} else if (x_position < X_THRESHOLD_LOW) {
x_direction = -1;

if (y_position > Y_THRESHOLD_HIGH) {
y_direction = 1;
} else if (y_position < Y_THRESHOLD_LOW) {
y_direction = -1;

if (x_direction == -1) {
if (y_direction == -1) {
} else if (y_direction == 0) {
Serial.println("a");                               //the A is whats making it go left
} else {
// y_direction == 1
} else if (x_direction == 0) {
if (y_direction == -1) {
Serial.println("s");                          // S is for reverse
} else if (y_direction == 0) {
Serial.println("f");                          // F is for Stop--it sends this until something else is sent
} else {
// y_direction == 1
Serial.println("w");                       // W is forward
} else {
// x_direction == 1
if (y_direction == -1) {
} else if (y_direction == 0) {
Serial.println("d");                         // D is right
} else {
// y_direction == 1

Step 3: Code for the Rover

//Code courtesy DFRobotShop  Rover_Serial 

int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control

int LED = 13;

void setup(void)
 int i;
 pinMode(i, OUTPUT);
 pinMode(13, OUTPUT);
void loop(void)
 while (Serial.available() < 0) {} // Wait until a character is received
 char val = Serial.read();
 int leftspeed = 255; //255 is maximum speed
 int rightspeed = 255;
 switch(val) // Perform an action depending on the command
  case 'w'://Move Forward
  forward (leftspeed,rightspeed);
  case 's'://Move Backwards
  reverse (leftspeed,rightspeed);
  case 'a'://Turn Left
  left (leftspeed,rightspeed);
  case 'd'://Turn Right
  right (leftspeed,rightspeed);

  case 'l'://LED

  case 'f'://Stop


void stop (void) //Stop
void forward (char a,char b)
 analogWrite (E1,a);
 analogWrite (E2,b);
void reverse (char a,char b)
 analogWrite (E1,a);
 analogWrite (E2,b);
void left (char a,char b)
 analogWrite (E1,a);
 analogWrite (E2,b);
void right (char a,char b)
 analogWrite (E1,a);
 analogWrite (E2,b);

void blink_LED ()
 digitalWrite(LED, HIGH);
 digitalWrite(LED, LOW);
 digitalWrite(LED, HIGH);
 digitalWrite(LED, LOW);

Step 4: Review, Failings & Fun

              Firstly, I like to thank the Instructables community and DFRobotShop for providing the rover.   It's a nice platform that I look forward to doing much more with.   I feel like this has gotten me past my noob level and onto a novice grade.  For a while I uploaded and tried all sorts of different codes, AFSoftSerial library, a dozen other things.  The rover wasn't working as I thought it should.  It was behaving as if it wasn't getting nearly enough power to drive the motors.  I tried adding more power.  With batteries in it, I plugged it into a wallwart.  After about 20 minutes of crazy behavior the batteries began to POP, all 4 exploded inside the rover.  Not good.   The next day I was sure everything was setup properly but still no movement, or the rover would move an inch and quit.   After wiring up a separate 5volt supply I realized the built-in LED's were pulling enough power to keep the motors from running at full force.  I pulled out the jumpers and everything works ok now.  Even with the best batteries I could find, it still drains enough power that after about 2 minutes of use, it needs to be cycled Off and On. I don't know why this is or how to combat it(Any Suggestions?).   The Xbee intergration was really the easiest part of this whole project.  A few wires and using XCTU made it very smooth.  In the end, it paid to stick with it and not be deterred by exploding batteries, losing trax of the wheels and tons of shoddy code uploads.    Now some Failure & Fun video.



    • Clocks Contest

      Clocks Contest
    • Oil Contest

      Oil Contest
    • Creative Misuse Contest

      Creative Misuse Contest

    7 Discussions

    Hi there, i am using this platform:


    I have an Arduino Uno with the joystick shield and an Arduino duemilanove and Adafruit Motor Shield to run the Motors, the motor shield is powered separately from the Arduino so there is no Brownout occurring, I have tried your code as it incorporates two motors and i thought it would work but have had no success, your code compiles ok on both the joystick and rover end but i get no movement from the bot at all....

    Any help would be amazing,



    4 replies

    this code won't work for you. it might if you play around with the pin asignments.
    http://www.ladyada.net/make/mshield/faq.html The pins that the H-bridge is attached to on the Motorshield are different that this rover. Adafruits board uses Digital pin 4, 7, 8 and 12. You could still use the joystick code if you match it up to
    serial out the information that will make the motorshield turn the motors on, ie Digital write pin 9 high(forward).
    I would use some of LadyAda's code. and the library AF_motor. It will make what you are doing alot easier. The forums on Adafruit can be very useful. I have a motor shield
    You basically want the joystick arduino to serial write a command that mean go (forward) and if you connect if RX and TX together, the two arduinos will talk to each other.

    Good luck and please message me if you post an instructable of your build. I'd love to see what you're making.

    Thank you for the reply, i will keep trying, and hopefully get it working, I cannot see anywhere in your code to add the addition digital write pin 9 or in my case 4,7,8,12

    I am fairly new to Xbee, not sure how to modify the code correctly as i have tried numerous different attempts and have had all fail. I can talk to the xbee's, i have proven that to myself, and i have got the motor shield running, only thing is getting it all to work with the joystick shield and Xbee, Your code allows me to view the serial data in the serial monitor so a good sign, Please if you could help me compile the code i would be most appreciative, i am a cognitive learner so i struggle with written explanations, hence why instructable's is for me,

    I would most definitely post it as a full Instructable, link your page in, it would help so many people as i know a lot of people are struggling with my same kit, and it would really open doors for people learning xbee and Robot Platform 4WD control,

    Again thank you for the reply i am continuing on for now,


    below is the code on the rover that needs to be changed. The joystick code above shouldn't need to be messed with.

    int E1 = 4; //M1 Speed Control
    int E2 = 7; //M2 Speed Control
    int M1 = 8; //M1 Direction Control //this is where you change the pins
    int M2 = 12; //M2 Direction Control

    int LED = 13; void setup

    (void) { int i; for(i=5;i<=8;i++) //this "for" loop here initializes the pins. change pinMode(i, OUTPUT); //to pinMode(4, OUTPUT); pinMode(7,OUTPUT)
    pinMode(13, OUTPUT); //et cetera


    the trouble with doing it this way is that I just don't know if the motor shield will work this way. I've only tried the motor shield with the AF_motor library.

    luck is not on my side with this project, one of me Xbee's has stopped working! super frustrating, but luckily i have two others on their way to me soon, if i was to purchase this kit :


    And using a joystick shield with Xbee and your code it should work, and once i know i have it all working exactly like your instructable i will attempt the cross over between projects, but in the meantime i have had an idea and found a way to control my 4WD using the DAGU Wild Thumper, it allows me to plug an 2.4GHz RC receiver directly into it and use a 2.4 GHz transmitter to control it, it has a sketch already uploaded which allows it to do so, hopefully it all works. One thing i have learned is that there are many many ways to make and control a RC 4WD bot, the only thing is the expense of the DAGU controller, almost 3 times that of an arduino and Motor controller bought separately, so i guess you pay for convenience.

    Cheers for your response, as soon as i get my Xbee's working again i will try this quick code fix out and get back to you.

    I understand most of your code, but why are you setting X_THRESHOLD_HIGH to 550 and X_THRESHOLD_LOW to 450? I don't really understand what those numbers represent.

    Any help is greatly appreciated,

    1 reply

    If I remember correctly, they represent the threshold for the analog value of the joystick. Between those values, nothing happens. Nothing happens because the joystick is centered. If the joystick is moved forward on the X axis it goes higher than 550. 450-550 is the analog value I recorded for a centered position. Make sense?