Create your own phone application and control the Arduino Robot via bluetooth!



In this tutorial we will learn how to control the Arduino via bluetooth using the android application. First, we will make the robot car for control it. And, we will use Bluetooth module (HC05 or HC06) for the communication. And last, we will create the android application for sending commands to the robot car.

We will use MIT App Inventor for create the android application. Also, I will use 3D printed chassis for the robot car. But, you can use any chassis. If you want, you can download my 3D model and use it.

--------------------

Required Hardware

Arduino Board
Arduino Uno -- https://goo.gl/Rqc5w2
Arduino Nano -- https://goo.gl/9ZDDyw

Bluetooth Module

L298N H-Bridge Driver -- https://goo.gl/Ucvx6J
Robot Car Chassis -- https://goo.gl/WMXVTi
Mini Breadboard -- https://goo.gl/08nnr1
Jump Wires -- https://goo.gl/n5ljN3
Front Wheel -- https://goo.gl/HLLKpc
Li-ion Battery -- https://goo.gl/z8TiqP
9V Battery -- https://goo.gl/DoLBsm
9V Battery Plug -- https://goo.gl/iAEgPl

--------------------

3D Printer and Chassis

Anet A8 3D Printer Promotion Link -- https://goo.gl/MNa3p9
Black Filament -- https://goo.gl/L6TCdu
Red Filament -- https://goo.gl/rucyb5

Car Chassis 3D .stl Files -- https://goo.gl/orVHMp

--------------------

Application

Application .aia and .apk -- https://goo.gl/kJ1oLR

--------------------

Promotion Links

Mega Stock Clearance -- https://goo.gl/eCbuiP
Flash Deals -- https://goo.gl/CVqg7P
Arduino Kits -- https://goo.gl/uwr19e

--------------------

Get the Source Code
//define the control pins of the motors
//motor A
int enableA = 10;
int IN1 = 9;
int IN2 = 8;

//motor B
int enableB = 5;
int IN3 = 7;
int IN4 = 6;

#define maximumSpeed 250

String readString;

void setup() {
  //set all the motor control pins to output

  pinMode (enableA, OUTPUT);
  pinMode (enableB, OUTPUT);
  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (IN3, OUTPUT);
  pinMode (IN4, OUTPUT);

  Serial.begin(9600);
}

void loop() {
  while(Serial.available()){
    delay(50);
    char c = Serial.read();
    readString+=c;
  }

  if(readString.length() > 0) {
    Serial.println(readString);

    if(readString == "FORWARD"){
      moveForward();
    }
    
    if(readString == "BACK"){
      moveBack();
    }

    if(readString == "LEFT"){
      turnLeft();
    }

    if(readString == "RIGHT"){
      turnRight();
    }

    if(readString == "STOP"){
      stopMotors();
    }

    readString = "";
  }
}

void moveForward(){
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  
  // accelerate from zero to maximum speed
  for(int motorSpeed = 0; motorSpeed < maximumSpeed; motorSpeed++){
    analogWrite(enableA, motorSpeed);
    analogWrite(enableB, motorSpeed);
    }
}

void moveBack(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);

  for(int motorSpeed = 0; motorSpeed < maximumSpeed; motorSpeed++){
    analogWrite(enableA, motorSpeed);
    analogWrite(enableB, motorSpeed);
    }
}

void turnLeft(){
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, HIGH);

  for(int motorSpeed = 0; motorSpeed < maximumSpeed; motorSpeed++){
    analogWrite(enableA, motorSpeed);
    analogWrite(enableB, motorSpeed);
  }
}

void turnRight(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);

  for(int motorSpeed = 0; motorSpeed < maximumSpeed; motorSpeed++){
    analogWrite(enableA, motorSpeed);
    analogWrite(enableB, motorSpeed);
  }
}

void stopMotors(){
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, LOW);
  digitalWrite(IN4, LOW);
}