Simple Bluetooth RC Car (Arduino Nano + HC-05)

15,764

21

9

Introduction: Simple Bluetooth RC Car (Arduino Nano + HC-05)

About: Lazy Software Developer

I will share my simple project on how to use your android phone to control robot car.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: The Hardware

  • 1 x Arduino Nano
  • 1 x HC-05 Bluetooth module
  • 1 x Motor Driver Module (TB6612FNG)
  • 2 x Motors ( with Wheel)
  • 1 x Battery for Arduino
  • 2 x Battery for Motors

Step 2: Connections

Arduino - HC-05

  • D11 - Rx
  • D10 - Tx
  • +5v - VCC
  • GND - GND

Arduino - TB6612FNG

  • D3 - PWMA
  • D4 - AIN2
  • D5 - AIN1
  • D6 - STBY
  • D7 - BIN1
  • D8 - BIN2
  • D9 - PWMB
  • GND - GND

TB6612FNG - Battery

  • GND to V-
  • VM to V+

Arduino - LED (Optional)

  • D13 - LED+
  • GND - LED-

Step 3: Codding

/* RC_Bluetooth_2018_v6<br> * By:    Khamlek HOMSOMBATH
 * Date:  Jan 17, 2018
 * Download Controller for Android : <a href="https://play.google.com/store/apps/details?id=com.lekpkd.duinojoy">  https://play.google.com/store/apps/details?id=com...>
 */

#include <softwareserial.h></softwareserial.h><SoftwareSerial.h>

// arduino>>bluetooth
// D10 (as RX)   >>>  Tx
// D11 (as TX)  >>>  Rx
SoftwareSerial bluetooth(10, 11); // RX, TX

#define ledpin 13 // Connected to LED

#define PWMA 3
#define AIN2 4
#define AIN1 5
#define STBY 6
#define BIN1 7
#define BIN2 8
#define PWMB 9
void setup() {
  Serial.begin(19200); 
  bluetooth.begin(9600);
  
  pinMode(ledpin,OUTPUT);
  pinMode(PWMA,OUTPUT); // PWM A
  pinMode(PWMB,OUTPUT); // PWM B
  pinMode(BIN1,OUTPUT); // B
  pinMode(BIN2,OUTPUT); // B
  pinMode(AIN1,OUTPUT); // A
  pinMode(AIN2,OUTPUT); // A
  pinMode(STBY,OUTPUT); // STBY

  digitalWrite(STBY,1);
analogWrite(PWMA, 0);
  analogWrite(PWMB, 0);
} 
String data = "";
void loop() {
  while(bluetooth.available()){
    char a = bluetooth.read();
    if(a==')') {
      setData(data);
      data = "";
      return;
    }
    data += a;
  }
}
int ledVal = 0;
void setData(String data){
  data.trim();
  int index = data.indexOf(",");
  if(index != -1){
    int angle = data.substring(0,index).toInt();
    int strength = data.substring(index + 1).toInt();

    digitalWrite(BIN1,0);
    digitalWrite(BIN2,0);
    digitalWrite(AIN1,0);
    digitalWrite(AIN2,0);
    if (angle < 180){
      digitalWrite(BIN1,1);
      digitalWrite(AIN1,1);

      if(angle < 90){
        analogWrite(PWMA, strength * 255 / 100);
        analogWrite(PWMB, strength * (angle * 255 / 90) / 100);
      }else if(angle > 90){
        analogWrite(PWMA, strength * ((180 - angle) * 255 / 90) / 100);
        analogWrite(PWMB, strength * 255 / 100);
      }else{
        analogWrite(PWMA, strength * 255 / 100);
        analogWrite(PWMB, strength * 255 / 100);
      }
    }else if(angle > 180){
      digitalWrite(BIN2,1);
      digitalWrite(AIN2,1);
      
      if(angle > 270){
        analogWrite(PWMA, strength * 255 / 100);
        analogWrite(PWMB, strength * ((360 - angle) * 255 / 90) / 100);
      }else if(angle < 270){
        analogWrite(PWMA, strength * ((90 - (270 - angle)) * 255 / 90) / 100);
        analogWrite(PWMB, strength * 255 / 100);
      }else{
        analogWrite(PWMA, strength * 255 / 100);
        analogWrite(PWMB, strength * 255 / 100);
      }
    }
    return;
  }

  if(data.equals("a")){
    if(ledVal==1) ledVal=0; else ledVal=1;
    digitalWrite(ledpin, ledVal);
    return;
  }
  
  Serial.print("Recieved: ");
  Serial.println(data);
}

Step 4: Testing

Please download Duino Joy Android App at

https://play.google.com/store/apps/details?id=com....

  1. Pair your Arduino Car to your Mobile phone in bluetooth setting on your phone
  2. Open Duino Joy app
  3. Click 'Connect' button
  4. Select 'HC-05' or any name you set for your HC-05
  5. Let's play!!

Be the First to Share

    Recommendations

    • Toys and Games Challenge

      Toys and Games Challenge
    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge

    9 Discussions

    0
    Syed SulemanS
    Syed SulemanS

    Question 2 years ago on Introduction

    Sir could you explain the black wire coming from 9v to TB6612FNG and from there to the bluetooth module. What is that connection? Please help as its not provided in the above procedure.

    0
    adelbiari
    adelbiari

    Answer 6 weeks ago

    Hi, I want to add something else for future readers, since it has several power sources, it is necessary that the GND be common throughout the electronic circuit :)

    0
    KhamlekH
    KhamlekH

    Answer 2 years ago

    Hi,

    Thank you for comment, These are GND connection, you can link from Arduino to Bluetooth module directly.

    Screen Shot 2018-03-13 at 9.39.59 AM.png
    0
    Botboy777
    Botboy777

    Question 3 months ago

    old post, but does this code only work for the Duino Joy app?

    0
    KhamlekH
    KhamlekH

    Answer 3 months ago

    This code is write to work with Duino Joy app, but you can make some change to work with other app too.

    Screen Shot 2018-06-07 at 4.02.53 PM.png
    0
    FranciscoH43
    FranciscoH43

    Question 1 year ago on Step 4

    1.Hola genio! Estoy armando uno, con un motor de destornillador electrico, una placa nano, el modulo y el controlador de motor, me podrías pasar una configuracion de arduino para que funcione con tu app? tambien pienso implementar leds! desde ya gracias


    0
    KhamlekH
    KhamlekH

    Answer 1 year ago

    Hi, I don't understand Spanish, but hoe this help.

    You can test Arduino with my app by Simple code below:

    #include <SoftwareSerial.h>

    // Arduino >>> bluetooth

    // D10 (as RX) >>> Tx

    // D11 (as TX) >>> Rx

    SoftwareSerial bluetooth(10, 11); // RX, TX

    void setup() {

    Serial.begin(19200); // Display to Arduino IDE Serial Monitor

    bluetooth.begin(9600); // Communicate with Bluetooth module

    }

    void loop() {

    while(bluetooth.available()) // Wait for data from bluetooth

    {

    char a = bluetooth.read(); // Read Data as Char from Software Serial

    Serial.print("Recieved: ");

    Serial.println(a); // Print data to Serial Monitor

    }

    }

    Screen Shot 2018-06-07 at 4.02.53 PM.png
    0
    Syed SulemanS
    Syed SulemanS

    Question 2 years ago on Step 3

    Could you please make one with l9110s module. I have tried making with different drivers such as l293d but i failed. At the moment i have arduino nano and l9110s but i keep failing again and again. Am totally new to connections and coding but tutorials didnt help either. Need help!