Simple Bluetooth RC Car (Arduino Nano + HC-05)
by lekpkd in Living > Toys & Games
27447 Views, 33 Favorites, 0 Comments
Simple Bluetooth RC Car (Arduino Nano + HC-05)


I will share my simple project on how to use your android phone to control robot car.
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
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-
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); }
Downloads
Testing




Please download Duino Joy Android App at
https://play.google.com/store/apps/details?id=com....
- Pair your Arduino Car to your Mobile phone in bluetooth setting on your phone
- Open Duino Joy app
- Click 'Connect' button
- Select 'HC-05' or any name you set for your HC-05
- Let's play!!