Testing RC Bluetooth Car App and Motor Code -Arduino RoboMaster Part 4

In my ongoing project to build an Arduino RoboMaster, now I have tested the RC Bluetooth Car application from the google play and checked the RC car code. Here is record of what I was doing this two last days.

I downloaded the RC Bluetooth Car application from google play and installed it on my mobile phone. I uploaded a simple RC car control program code for the Arduino Uno. I uploaded the code and tried to connect to the car via Bluetooth on my phone. However it did not connect. After many failed attempt to connect I started to look into the HC-05 Bluetooth module. I even bought a new HC-05 bluetooth module because I thought mine was damaged. As far as I remember when doing works like the Bluetooth and IR sensor Interfacing and coding, I had no such problem and it was quite easy to use. I was starting to guess that I have the wrong baud rate. So I had to use the AT command mode for the Bluetooth in order check and set the baud rate. I showed in the tutorial Quick HC-05 AT startup guide how I entered the command mode of HC-05 Bluetooth module using the onboard push button. 

After checking few Bluetooth settings and check the Bluetooth link live, I finally got one Bluetooth module working with the bluebottle RC car application. Since my lithium ion batteries are still not fully charged I used the 9V supply from the wall socket. So finally after looking into ion lithium battery charger, buying new HC-05 module, checking HC-05 modules, I was able to get the application, code and the wheel spinning correctly.

Testing RC Bluetooth Car App and Motor Code -Arduino RoboMaster

The following video shows checking and testing the RC Bluetooth car application and the working of the RC car.

Arduino Code for Bluetooth RC car

Below is the code that I used in testing the remote Bluetooth controlled car.

#include <AFMotor.h>

//initial motors pin
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command;

void setup()
{
  Serial.begin(9600);  //Set the baud rate to your Bluetooth module.
}

void loop() {
  if (Serial.available() > 0) {
    command = Serial.read();

    stop(); //initialize with motors stopped
    
    switch (command) {
      case 'F':
        forward();
        break;
      case 'B':
        back();
        break;
      case 'L':
        left();
        break;
      case 'R':
        right();
        break;
      case 'S':
        stop();
        break;
    }
  }
}

void forward()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD);  //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD);  //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void back()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void left()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(BACKWARD); //rotate the motor anti-clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(BACKWARD); //rotate the motor anti-clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(FORWARD);  //rotate the motor clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(FORWARD);  //rotate the motor clockwise
}

void right()
{
  motor1.setSpeed(255); //Define maximum velocity
  motor1.run(FORWARD);  //rotate the motor clockwise
  motor2.setSpeed(255); //Define maximum velocity
  motor2.run(FORWARD);  //rotate the motor clockwise
  motor3.setSpeed(255); //Define maximum velocity
  motor3.run(BACKWARD); //rotate the motor anti-clockwise
  motor4.setSpeed(255); //Define maximum velocity
  motor4.run(BACKWARD); //rotate the motor anti-clockwise
}

void stop()
{
  motor1.setSpeed(0);  //Define minimum velocity
  motor1.run(RELEASE); //stop the motor when release the button
  motor2.setSpeed(0);  //Define minimum velocity
  motor2.run(RELEASE); //rotate the motor clockwise
  motor3.setSpeed(0);  //Define minimum velocity
  motor3.run(RELEASE); //stop the motor when release the button
  motor4.setSpeed(0);  //Define minimum velocity
  motor4.run(RELEASE); //stop the motor when release the button
}

In the next part of my journey I will write something about Lithium Ion batteries and charger which is the main power supply for the DIY Arduino RoboMaster.

References

# Building RoboMaster with Arduino - Part 2

# Quick HC-05 AT startup guide - Arduino RoboMaster Part 3

# Lithium Ion Battery and Charger - Arduino RoboMaster Part 5

# My First Arduino RC Car - Arduino RoboMaster part 6

# RC car Battery Charger- Arduino RoboMaster part 7

Post a Comment

Previous Post Next Post