HC-05 drops connection, then DC Motors won't stop moving 'forward'

Hi everyone,

This is my first post. I hope I am posting in the right thread. I seek you guys' help with my problem. Basically, this is my first project ever is called Mobile-App Bluetooth Controlled WheelChair. I am not really good at Arduino or any engineering stuff since this is outside of my scope. I am only told to make a project related to robotics. Everything's done except a minor problem comes out during testing. After connecting everything, the wheelchair moves accordingly to the code that I wrote. However, after a few sec/min, the HC-05 drops connection, and the wheelchair drives its own by moving forward. I hope you can understand what I am saying.

When I set the speed = 100. I think I did not face the issue as above (confirmed).

Hardware:

Arduino Uno
PowerBank
HC 05
MDD20A Motor Driver
X2 24V DC Motor
X2 12V Battery (Series Circuit)

//including the libraries
#include <SoftwareSerial.h> // TX RX software library for bluetooth

//Initializing pins for bluetooth Module
int bluetoothTx = 0; // bluetooth tx to 0 pin
int bluetoothRx = 1; // bluetooth rx to 1 pin
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

//Motor 1 
int Motor1_Pin = 2;
int Enable1 = 3;

//Motor 2      
int Motor2_Pin = 4;
int Enable2 = 5; 

char command ; //variable to store the data
int velocity = 0; //Variable to control the speed of motor

void setup() 
{       
  //Set the baud rate of serial communication and bluetooth module at same rate.
  // Serial Setup
  Serial.begin(9600); // default communication rate of the HC-06 Bluetooth module;  
  bluetooth.begin(9600);
  
  // Motor Setup
  pinMode(Motor1_Pin,OUTPUT);
  pinMode(Enable1,OUTPUT);
  pinMode(Motor2_Pin,OUTPUT);
  pinMode(Enable2,OUTPUT);
  
  //Setting the enable as HIGH.
  digitalWrite(Enable1, LOW);
  digitalWrite(Enable2, LOW);
}

void loop(){
  if(bluetooth.available() > 0){  //Checking if there is some data available or not
    command = bluetooth.read();   //Storing the data in the 'command' variable
    Serial.println(command);      //Printing it on the serial monitor
    
    //Change pin mode only if new command is different from previous.   
    switch(command){
    case 'F':  //Moving the Car Forward
      analogWrite(Enable1, 175);
      analogWrite(Enable2, 175);
      digitalWrite(Motor1_Pin, HIGH);
      digitalWrite(Motor2_Pin, HIGH);
      break;
    case 'B':  //Moving the Car Backward
      analogWrite(Enable1, 175);
      analogWrite(Enable2, 175);
      digitalWrite(Motor1_Pin, LOW);
      digitalWrite(Motor2_Pin, LOW);
      break;
    case 'L':  //Moving the Car Left
      analogWrite(Enable1, 175);
      analogWrite(Enable2, 100);
      digitalWrite(Motor1_Pin, HIGH);
      digitalWrite(Motor2_Pin, LOW);
      break;
    case 'R':   //Moving the Car Right
      analogWrite(Enable2, 175);
      analogWrite(Enable1, 100);
      digitalWrite(Motor2_Pin, HIGH);
      digitalWrite(Motor1_Pin, LOW);
      break;
    case 'S':   //Stop
      analogWrite(Enable1, 0);
      analogWrite(Enable2, 0);
      digitalWrite(Motor1_Pin, 0);
      digitalWrite(Motor2_Pin, 0);
      break; 
//    case 'I':  //Moving the Car Forward right
//      digitalWrite(Motor2_Pin2, LOW);
//      digitalWrite(Motor2_Pin1, LOW);
//      analogWrite(enable1, 0);
//      analogWrite(enable2, 0);
//      break; 
//    case 'J':  //Moving the Car backward right
//      digitalWrite(Motor2_Pin2, LOW);
//      digitalWrite(Motor2_Pin1, LOW);
//      analogWrite(enable1, 0);
//      analogWrite(enable2, 0);
//      break;        
//    case 'G':  //Moving the Car Forward left
//      digitalWrite(Motor2_Pin2, LOW);
//      digitalWrite(Motor2_Pin1, LOW);
//      analogWrite(enable1, 0);
//      analogWrite(enable2, 0);
//      break; 
//    case 'H':  //Moving the Car backward left
//      digitalWrite(Motor2_Pin2, LOW);
//      digitalWrite(Motor2_Pin1, LOW);
//      analogWrite(enable1, 0);
//      analogWrite(enable2, 0);
//      break;
    break;

    //Controlling the Speed of Car  
    default:  //Get velocity
      if(command=='q'){
        velocity = 255;  //Full velocity
        analogWrite(Enable2, velocity);
        analogWrite(Enable1, velocity);
      }
      else{ 
        //Chars '0' - '9' have an integer equivalence of 48 - 57, accordingly.
        if((command >= 48) && (command <= 57)){ 
          //Subtracting 48 changes the range from 48-57 to 0-9.
          //Multiplying by 25 changes the range from 0-9 to 0-225.
          velocity = (command - 48)*25;       
          analogWrite(Enable2, velocity);
          analogWrite(Enable1, velocity);
        }
      }
      }
    }

  }

Using software serial on the hardware serial pins seems odd. I would put the software serial on different pins and save the hardware serial (pins 0 & 1) for program upload, monitoring program flow, variable values and program output.

There should be a voltage divider between the HC05 RX and the Uno TX to drop the Uno TX to 3.3V to protect the HC05 RX pin.

What is on the other end of the Bluetooth communication? What is the receiving app?

  1. Okay, I see.

  2. By having a voltage divider, it is just to protect the board, right.

  3. Not sure about this part. I have been using a 3rd party-app from Play Store to test it out. Here is the link. https://play.google.com/store/apps/details?id=braulio.calle.bluetoothRCcontroller&hl=ms&gl=US

I have been surveying in the forum if I could find the same issue as mine. Is it because of the external power source (powerbank) is not strong enough which might have caused a short voltage dip to irritate the HC-05 Module?

What is powering the Uno? That is not shown on the diagram.

What are the specifications of the power bank?

Yes, the voltage divider is to protect the HC05 RX pin from the 5V Uno TX voltage.

  1. Sorry, I knew I have to add it but have not updated it yet. The Arduino UNO is powered by a power bank with a 5V 3.6A output.

I just edited my first posting above if you notice. When the speed is set at 100, the issue stated above does not occur but once I set it at 175 as you can see in my latest code above, the issue occured.

So the possible solution that I thought about is to give a higher voltage of external power supply to the Arduino UNO since I am using 2 'big' DC Motor and the PWM could not handle them because of lack of voltage I think as the voltage is split as well (because of 2 DC Motor). For example like if I use 7-12V as per the recommended specification of Arduino UNO, there will less likely be an outcome of having a short voltage dip that would cause irritation to the HC-05 that ends up dropping the Bluetooth connection and it could handle higher speed (>100).

I don't know how to explain it in technical terms. I am still like a baby that is learning to crawl at this kind of stuff but that's what I understand from my point of view. What do you think? Do you think the issue related to what I have told you and the solution good?

Later, what I am afraid of is even I use like 9V battery as the external power supply, I doubt if 9V is already enough to pull the highest speed (255) without facing the same issue. I will still be unsure of the highest possible speed I could set by theory since I actually don't know how this thing works or the calculation to find out except by trial and error.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.