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 in a couple steps.


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

First up is the Adafruit BLE library. Learn more about this library and download it here.

Next, we will need the Adafruit MotorShield library. Learn more about this library and download it here.

The Code

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

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:

// speed up the motors
      for (int speed=0; speed < maxspeed; speed+=5) {
        delay(5); // 250ms total to speed up

We just use a simple 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 Dec 13, 2016. It was last updated on Mar 08, 2024.

This page (Code for Your Robot) was last updated on Oct 26, 2016.

Text editor powered by tinymce.