Code for Your Robot

To take this robot to the next level, we are going to modify James De Vito's awesome code for the similar Red Robot Rover. In his code, he has multiple control methods where you can either use the Bluefruit App controller or use your phone's accelerometer to drive your robot. For this example, I am going to simplify things and we will just use the control pad. This will free up the four auxiliary buttons for some customization which we will cover later.

MotorShield Library

For this code to work, we will need to install a library. See the previous step on a really easy way to install this library using the Arduino Library manager.

We will need the Adafruit MotorShield library. Learn more about this library and download it here.

You probably already have this installed if you followed the previous page but triple check now!

The Code

Once you have the libraries installed, you will want to download the latest rover code. Click the button below to download. 

Once the file has downloaded, unzip it and rename the folder from Adafruit_CurieBot-master to Adafruit_CurieBot

Then, place this folder in your Arduino sketches directory and open the sketch Ada_CurieBot_RC.

There are a few other sketches included in the download which you'll use later on in this guide.

If you take a good look through this code, you will see it isn't so much more complicated than what we learned in the previous step. There is some complicated code that deals with the bluetooth connection to your phone (which we will use in the next step). One neat feature we added is a way to slowly speed up the motors to full speed so it doesn't pop-a-wheelie when you take off going forward with this bit of code:

Download: file
// speed up the motors
      for (int speed=0; speed < maxspeed; speed+=5) {
        L_MOTOR->setSpeed(speed);
        R_MOTOR->setSpeed(speed);
        delay(5); // 250ms total to speed up
      }

We use a  for loop to slowly ramp up the speed until it hits max speed. Learn more about for loops here.

This guide was first published on Apr 01, 2017. It was last updated on Apr 01, 2017. This page (Code for Your Robot) was last updated on May 31, 2020.