Project tutorial
BLE Robot Using Blynk & Arduino

BLE Robot Using Blynk & Arduino © CC BY

Getting Started Guide for using Blynk with the Arduino IDE for controlling a small robot chassis using a Bluetooth phone or tablet.

  • 2,333 views
  • 0 comments
  • 13 respects

Components and supplies

Apps and online services

About this project

Overview

In the first workshop, we'll be spending most of the time building the robots and testing them using Blynk and Arduino. If you'd like to get the most out of the workshop, please bring a laptop computer and a smartphone or tablet. Don't worry if you don't have them, we'll be working in teams, and we'll pair you up with others who have all the equipment.

The robot chassis we will be using is the Dago Multi-Chassis 4WD ATV Model:

Part 1

  • Download and Install the Arduino sketch for the workshop, named - Arduino101_BLE_Blynk_AdaMotor_V2.ino
  • Using the Blynk application on your smart phone or tablet, clone the project user interface using the QR Code. This is a nice Blynk feature to save you the time of manually entering all the information required.

Part 2

Once the project has been cloned, go to the setup menu (Nut Icon) and email yourself the "Auth Token" for the project. Each user will have their own unique "Auth Token". Enter that string into your Arduino sketch:

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; 

Connect your Arduino101 board to your laptop computer using the USB cable and wait for the USB port to enumerate. This can take several minutes the first time as drivers are downloaded and installed.

From the Arduino "Tools" menu select the Arduino101 board type and the correct COM: port for the Arduino101 board.

Click on the Arduino IDE "Upload" button to compile and upload your sketch to the robot board. From your smarthphone/laptop, click the "Connect" icon to connect the Bluetooth radio to your robot.

Now use the buttons and speed control slider to control your robot.

If one or more of the motors spins incorrectly, reverse the wire leads to that motor to fix the direction.

That's it! In the following workshops, we'll work on more independent robot control and work up to the PARTS robot challenge.

Code

Arduino101_BLE_Blynk_Adamotor_V2C/C++
The Arduino sketch for simple control of the Robot
/**************************************************************
 * This sketch is for an Arduino 101 BLE rover using Blynk and Adafruit Motor Shield V2
 * Code was copied from both Adafruit and Blynk librarie examples
 * Full documentation on building this rover yourself on Hackster.IO and electronhacks.com
 * Sketch is released under MIT license
 **************************************************************/


#define BLYNK_PRINT Serial
#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

BLEPeripheral  blePeripheral;

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

// Select which 'port' M1, M2, M3 or M4.
Adafruit_DCMotor *motor1 = AFMS.getMotor(1);
Adafruit_DCMotor *motor2 = AFMS.getMotor(2);
Adafruit_DCMotor *motor3 = AFMS.getMotor(3);
Adafruit_DCMotor *motor4 = AFMS.getMotor(4);

//######### SETUP ######################################
void setup() {
  Serial.begin(115200);
  delay(1000);

  // The name your bluetooth service will show up as, customize this if you have multiple devices
  blePeripheral.setLocalName("Arduino101Blynk");
  blePeripheral.setDeviceName("Arduino101Blynk");
  blePeripheral.setAppearance(384);

  //Blynk.begin(auth, blePeripheral);
  Blynk.begin(blePeripheral, auth);
  
  blePeripheral.begin();
  
  Serial.println("Waiting for connections...");
    
  Serial.println("Adafruit Motorshield v2 - DC Motor");

  AFMS.begin();  // create with the default frequency 1.6KHz
  //AFMS.begin(1000);  // OR with a different frequency, say 1KHz
  
  // Set the speed to start, from 0 (off) to 255 (max speed)
  motor1->setSpeed(255);
  motor2->setSpeed(255);
  motor3->setSpeed(255);
  motor4->setSpeed(255);  

}


//########## LOOP ######################################
void loop() {
  Blynk.run();
  blePeripheral.poll();
}


//######### Subroutines ################################

// This function will set the speed
BLYNK_WRITE(V0)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("V0 Slider value is: ");
  Serial.println(pinValue);
  motor1->setSpeed(pinValue);
  motor2->setSpeed(pinValue); 
  motor3->setSpeed(pinValue);
  motor4->setSpeed(pinValue);   
}

// Motor 1 Forward
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("Motor 1 Forward: ");
  Serial.println(pinValue);
  if(pinValue == 1) {
    motor1->run(FORWARD);
    motor2->run(BACKWARD);
    motor3->run(FORWARD);
    motor4->run(BACKWARD);
  }
  if(pinValue == 0) {
    motor1->run(RELEASE);
    motor2->run(RELEASE);
    motor3->run(RELEASE);
    motor4->run(RELEASE);    
  }
}


// Motor 2 Forward
BLYNK_WRITE(V2)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("Motor 2 Forward: ");
  Serial.println(pinValue);
  if(pinValue == 1) {
    motor1->run(BACKWARD);
    motor3->run(FORWARD);

  }
  if(pinValue == 0) {
    motor1->run(RELEASE);
    motor2->run(RELEASE);
    motor3->run(RELEASE);
    motor4->run(RELEASE);  
  }
}

// Motor 1 Backward
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("Motor 1 Backward: ");
  Serial.println(pinValue);
  if(pinValue == 1) {
    motor1->run(BACKWARD);
    motor2->run(FORWARD);
    motor3->run(BACKWARD);   
    motor4->run(FORWARD);       
  }
  if(pinValue == 0) {
    motor1->run(RELEASE);
    motor2->run(RELEASE);       
    motor3->run(RELEASE);
    motor4->run(RELEASE);    
  }
}

// Motor 2 Backward
BLYNK_WRITE(V4)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  Serial.print("Motor 2 Backward: ");
  Serial.println(pinValue);
  if(pinValue == 1) {
    motor3->run(BACKWARD);
    motor1->run(FORWARD);
  }
  if(pinValue == 0) {
    motor1->run(RELEASE);
    motor2->run(RELEASE);
    motor3->run(RELEASE);
    motor4->run(RELEASE);  
  }
}

Schematics

Embedis Repository
Onboard database for later labs

Comments

Similar projects you might like

Intel Arduino 101 BLE Blynk Tank

Project tutorial by Johnathan Hottell

  • 10,716 views
  • 6 comments
  • 42 respects

Arduino/Genuino 101 BLE Thermometer With TMP102 and Blynk

Project tutorial by Konstantin Dimitrov

  • 8,178 views
  • 1 comment
  • 26 respects

Robot Rover - iPhone controlled using Blynk Joystick

Project tutorial by jim Myracle

  • 4,948 views
  • 0 comments
  • 17 respects

Arduino 101 Blynk and BLE Example Panel

by Rafa Juárez

  • 1,339 views
  • 0 comments
  • 5 respects
Add projectSign up / Login