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

Picture of Simple RC Car (Arduino Nano + HC-05)

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

Step 1: The Hardware

Picture of 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

Picture of Connections

Arduino - HC-05

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

Arduino - TB6612FNG

  • D5 - PWMA
  • D9 - AIN1
  • D10 - AIN2
  • D6 - PWMA
  • D7 - BIN1
  • D8 - BIN2
  • GND - GND

TB6612FNG - Battery

  • GND to V-
  • VM to V+

Arduino - LED (Optional)

  • D13 - LED+
  • GND - LED-

Step 3: Codding

Picture of Codding
/* RC_Bluetooth_2017_v4
* By: Khamlek HOMSOMBATH * Date: Oct 7, 2017 * Download Controller for Android : https://play.google.com/store/apps/details?id=com... */ #include SoftwareSerial bluetooth(11, 12); // D11(Rx) to Tx, D12(Tx) to Rx #define ledpin 13 // Connected to LED #define PWMA 5 #define AIN1 9 #define AIN2 10 #define PWMB 6 #define BIN1 7 #define BIN2 8
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
  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

Picture of 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!!

Comments

DIY Hacks and How Tos (author)2017-10-07

Cool. I always wanted to make my own RC car.

About This Instructable

484views

12favorites

Bio: Lazy Software Developer
More by KhamlekH:Simple RC Car (Arduino Nano + HC-05)
Add instructable to: