Manual
Sample Code
The DFRobotShop Rover is not intended to be a “complete product” which explains all the steps needed to
achieve a specific objective. Instead, the Rover is a platform which provides you with the basic hardware and
basic software to get started in programming mobile robots and Arduino. The code below is not “optimized”
but is intended to get you started.
Sketch #1 operates both motors at full speed. Sketch #2 allows serial commands to be sent to the DFRobotShop
Rover by either a wired (USB) or wireless (Bluetooth, XBee) connection. The keyboard commands are "w", "a",
"s" and "d" for driving forward, turning left, turning right and reversing. The rover will execute the command
until it is told to stop by pressing any other character. The basic kit requires that the USB cable be connected to
the robot while the Xbee and Bluetooth kits allow for wireless control. Ensure you select the correct COM port
and 9600 baud rate. The Baud rate for the Bluetooth module can be 9600 or 115200 depending on the module
– check the manual to be certain. Note that it is likely the two motors are not identical and you will need to
adjust the speed slightly so the robot goes straight. Font size is reduced to allow easy copy / pasting.
Sketch #1: Basic Rover – Full speed forward
/* Copy and paste the code below into the Arduino software */
int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
void setup()
{
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
analogWrite (E1,255);
digitalWrite(M1,LOW);
analogWrite (E2,255);
digitalWrite(M2,LOW);
delay(100);
}