My arduino RC car with HC05 doesn't work

Hey guys. I am trying to build an easy program where I can control my Arduino RC car with a Bluetooth connection. I’m using the HC-05 Bluetooth module to communicate with my Arduino UNO. I’m also using an Adafruit motor shield on top of the Arduino to control the four DC motors that I have. When I verify my code everything seems fine, and the upload itself happens without any errors. But when i want to steer it with my phone nothing happens. Heres my code:¨

#include <AFMotor.h>
#include <SoftwareSerial.h>
char val;
SoftwareSerial HC05(A1, A3); //Rx, Tx
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup(){
HC05.begin(9600);
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop(){
if(HC05.available()){
val = HC05.read();
HC05.println(val);
}
if(val == ‘F’){
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if(val == ‘B’){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING BACKWARD”);
}
else if (val == ‘L’){
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING LEFT”);
}
else if (val == ‘R’){
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
HC05.println(“DRIVING RIGHT”);
}
else if (val == ‘S’){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
HC05.println(“STOPPING THE CAR”);
}
delay(100);
}

I’m not that good at Arduino coding so are there any obvious mistakes in my code? And also the RX and TX pins on the HC-05 are connected to the analog pins on the motor shield. Hope you guys have any suggestions

Hi,
Welcome to the forum! Please post your code in code tags (</> icon). What phone do you have? iPhones don’t work with HC-05.

IS the HC05 paired with your phone? What app on the phone controls the car? Is the HC05 connected to the app?

Im using and android phone to control the car. And before i connect the red led light on the bluetooth module flashes evvery second, and when paired it flashes in waves. The app is called “arduino bluetooth controller” by Condivisione

<#include <AFMotor.h>
#include <SoftwareSerial.h>
char val;
SoftwareSerial HC05(A1, A3); //Rx, Tx
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup(){
HC05.begin(9600);
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop(){
if(HC05.available()){
val = HC05.read();
HC05.println(val);
}
if(val == ‘F’){
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if(val == ‘B’){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING BACKWARD”);
}
else if (val == ‘L’){
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING LEFT”);
}
else if (val == ‘R’){
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
HC05.println(“DRIVING RIGHT”);
}
else if (val == ‘S’){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
HC05.println(“STOPPING THE CAR”);
}
delay(100);
}

im using and android device

Hi,
Post you code like this:

#include <AFMotor.h>
#include <SoftwareSerial.h>
char val;
SoftwareSerial HC05(A1, A3); //Rx, Tx
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup(){
HC05.begin(9600);
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop(){
if(HC05.available()){
val = HC05.read();
HC05.println(val);
}
if(val == ‘F’){
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if(val == ‘B’){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING BACKWARD”);
}
else if (val == ‘L’){
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
HC05.println(“DRIVING LEFT”);
}
else if (val == ‘R’){
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
HC05.println(“DRIVING RIGHT”);
}
else if (val == ‘S’){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
HC05.println(“STOPPING THE CAR”);
}
delay(100);
}

Do you have the link to the tutorial you followed?

Hi,
I’m not sure how that app works, as I have an iPhone. I normally use Blynk for this type of thing. Maybe it has something to do with the val? Maybe incorrect? Try attaching the Arduino to your computer with a usb cable and add some Serial.print to see if it’s working.

No. Me and my project partner wrote it ourselves. SO i do not have any link. But i can see on the internet that a lot of people have done something similiar. And i have tried everything, but nothing seems to work.

Hi,
I just noticed that you have RX and TX of HC-05 connected to A1 and A3 respectively. I wouldn’t use a analog pin for the RX and TX pins, because I’m not sure it would work. I also notice that you have this:

That means you are sending the received val back to the HC-05 to transmit again. I’m not sure if that’s correct.

Hi,
Try this code and see if it works. Attach RX to D5 and TX to D6 and open the serial monitor at 115200baud.

#include <AFMotor.h>
#include <SoftwareSerial.h>
char val;
SoftwareSerial HC05(5, 6); //Rx, Tx
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup(){
HC05.begin(9600);
Serial.begin(115200);
motor1.setSpeed(255);
motor2.setSpeed(255);
motor3.setSpeed(255);
motor4.setSpeed(255);
}

void loop(){
if(HC05.available()){
val = HC05.read();
Serial.println(val);
}
if(val == ‘F’){
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if(val == ‘B’){
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
Serial.println(“DRIVING BACKWARD”);
}
else if (val == ‘L’){
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
Serial.println(“DRIVING LEFT”);
}
else if (val == ‘R’){
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
Serial.println(“DRIVING RIGHT”);
}
else if (val == ‘S’){
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
Serial.println(“STOPPING THE CAR”);
}
delay(100);
}

There is no problem using the analog input pins (A0-A5) with SoftwareSerial. Those pins are digital pins like any others, but they have the special function of analog input. I actually tested the code with an Uno and the HC05 works fine on A1 and A3.

I suggest that you start the hardware serial port so that you can insert serial prints in the code to follow program execution and monitor the values of variables.

Sadly nothing happens. I’m starting to think that maybe some of my components are broken or something. But i tried the code earlier, and it worked perfectly fine, but out of nowhere it doesnt work

What did you change?

In the Arduino Bluetooth Controller app, which controller are you using? Controller, Switch, Dimmer or Terminal? If Controller, did you edit the output from the buttons? Is the HC05 connected to the app?

I have been investigating the AF motor shield schematic and it appears that the motor shield does not use the analog input pins (A0-A5) so the shield should have no effect.

I tried your code and wiring on my Uno (without a motor shield), HC05 and Android tablet running the Arduino Bluetooth Controller app. The HC05 communicates with the Uno just fine and if I send commands from the terminal I get the responses from the HC05.

Yes i did edit the output of the controller. I didn’t change anything at all.

But how was i able before to communicate with hc05 through my motorshield without any problems?

Hi,
Did you try my code? I only changed the “HC05.println” to “Serial.println”. It might work.

Ues i tried your code but nothing happened…

Hi,
I think the problem is with the data being transmitted and received on Bluetooth. I don’t have that app though or an android phone, so I’m not sure.

So you had exactly the same code and exactly the same components working perfectly? And then they stopped working? So you changed something. What? It can be as simple as moving the project and breaking a wire/connection.

If you’re certain that absolutely nothing changed then a component has suddenly died. Very rare but not completely impossible.

Steve