David Hoambrecker
Created June 17, 2017 © GPL3+

Arduino 101 BLE Rover Bot

A bluetooth controlled rover you drive with your smartphone

IntermediateWork in progress5 hours46
Arduino 101 BLE Rover Bot

Things used in this project

Hardware components

SparkFun RedBot Kit
SparkFun RedBot Kit
×1
Arduino 101
Arduino 101
×1
Adafruit Motor Shield v2.3
×1
9V battery (generic)
9V battery (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Evothings Studio
Evothings Studio
Visual Studio 2015
Microsoft Visual Studio 2015

Story

Read more

Schematics

Arduino 101 Schematic

Code

Rover.ino

Arduino
Arduino code for the 101 controlling the rover. Motor shield and libraries are required
   #include <CurieBLE.h>
   #include <Wire.h>
   #include <Adafruit_MotorShield.h>
   #include "utility/Adafruit_MS_PWMServoDriver.h"

   BLEService roverService("8a559032-2639-4c03-ace5-b3d486d0c79d"); // BLE Rover Service

   // BLE Motor control Characteristic - custom 128-bit UUIDs, read and writable by central
   BLEUnsignedCharCharacteristic fwdCharacteristic("ecd48ec8-da9d-4dde-8f51-988c3fb23da8", BLERead | BLEWrite);
   BLEUnsignedCharCharacteristic revCharacteristic("e03c5901-9cef-47f3-a92c-09cc6ef8469b", BLERead | BLEWrite);
   BLEUnsignedCharCharacteristic leftCharacteristic("d1d5839e-6aaa-4823-a70d-75c3f1d3aa3e", BLERead | BLEWrite);
   BLEUnsignedCharCharacteristic rightCharacteristic("8fa3a0f3-9e30-4b68-ab85-57a907652ff4", BLERead | BLEWrite);


  // Create the motor shield object with the default I2C address
  Adafruit_MotorShield AFMS = Adafruit_MotorShield();  

  //Create motor objects
  Adafruit_DCMotor *rightMotor = AFMS.getMotor(2);
  Adafruit_DCMotor *leftMotor = AFMS.getMotor(1);


  int runspeed = 50;
  int turnspeed = 25;


void setup() {
   //begin initialization
   AFMS.begin();
   BLE.begin();

   BLE.setLocalName("Rover");
   BLE.setAdvertisedService(roverService);

   // add the characteristics to the service
   roverService.addCharacteristic(fwdCharacteristic);
   roverService.addCharacteristic(revCharacteristic);
   roverService.addCharacteristic(leftCharacteristic);
   roverService.addCharacteristic(rightCharacteristic);

   // add service
   BLE.addService(roverService);

   // set the initial value for the characeristics:
   fwdCharacteristic.setValue(0);
   revCharacteristic.setValue(0);
   leftCharacteristic.setValue(0);
   rightCharacteristic.setValue(0);
   
   // start advertising
   BLE.advertise();

   rightMotor->setSpeed(100);
   rightMotor->run(FORWARD);
   // turn on motor
   rightMotor->run(RELEASE);

   leftMotor->setSpeed(100);
   leftMotor->run(FORWARD);
   // turn on motor
   leftMotor->run(RELEASE);

}

void loop() {
  BLEDevice central = BLE.central();

  if (central) {
    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristics,
      // use the value to control the motors:
      
      
      if (fwdCharacteristic.written()) {
        if (fwdCharacteristic.value()) {   // any value other than 0
          runspeed+= 50;
          turnspeed = 25;
          rightMotor->setSpeed(runspeed);
          leftMotor->setSpeed(runspeed);
          rightMotor->run(BACKWARD);
          leftMotor->run(BACKWARD);
        } else {                              // a 0 value
          runspeed = 50;
          turnspeed = 35;
          rightMotor->run(RELEASE);
          leftMotor->run(RELEASE);          
        }
      }

      if (leftCharacteristic.written()) {
        if (leftCharacteristic.value()) {   // any value other than 0
          runspeed = 50;
          turnspeed += 10;
          rightMotor->setSpeed(turnspeed);
          leftMotor->setSpeed(turnspeed);
          rightMotor->run(FORWARD);
          leftMotor->run(BACKWARD);
        } else {                              // a 0 value
          rightMotor->run(RELEASE);
          leftMotor->run(RELEASE);          
        }
      }

      if (rightCharacteristic.written()) {
        if (rightCharacteristic.value()) {   // any value other than 0
          runspeed = 50;
          turnspeed += 10;
          rightMotor->setSpeed(turnspeed);
          leftMotor->setSpeed(turnspeed);
          rightMotor->run(BACKWARD);
          leftMotor->run(FORWARD);
        } else {                              // a 0 value
          rightMotor->run(RELEASE);
          leftMotor->run(RELEASE);          
        }
      }

      if (revCharacteristic.written()) {
        if (revCharacteristic.value()) {   // any value other than 0
          runspeed+= 50;
          turnspeed = 25;
          rightMotor->setSpeed(runspeed);
          leftMotor->setSpeed(runspeed);
          rightMotor->run(FORWARD);
          leftMotor->run(FORWARD);
        } else {                              // a 0 value
          runspeed = 50;
          turnspeed = 25;
          rightMotor->run(RELEASE);
          leftMotor->run(RELEASE);          
        }
      }
    
  }

}
}

Credits

David Hoambrecker

David Hoambrecker

0 projects • 0 followers
Thanks to Sparkfun.

Comments