2

This is my first post. I seek you guys' help with my problem. Basically, my project is a Mobile-App Bluetooth Controlled WheelChair. 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:

PowerBank

Arduino Uno

HC 05

MDD20A Motor Driver

X2 24V DC Motor

X2 12V Battery

//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);
        }
      }
      }
    }

  }

enter image description here

3
  • "HC-05 drops connection" Does this mean is no longer connected to the phone (I'm guessing)? Or does it mean something else? – timemage Mar 17 at 21:18
  • Yes, true. It has something to do with PWM. When I set the speed at 100, there is no issue with the HC-05 Connection. However, once I set the speed at 175, it doesn't go smoothly for too long until suddenly the HC-05 connection drops the connection and then the dc motor becomes malfunction and drives its own (like stuck at forward). Sorry late. I did not realize this small comment box. – Peace You Mar 18 at 18:55
  • You might try adding some capacitors near the VCC/GND on the HC-05. – timemage Mar 18 at 21:09
0

I assume that you want the chair to stop if the connection is lost. Is the 'state' pin on your HC-05 implemented, and does it distinguish between connected and not-connected (or something else)? If it's the former you should be monitoring that state pin. Otherwise, your Arduino and the mobile app need to agree on an "Are you there?" protocol; a handshake that takes place every 0.5 sec or so (off the wall guess!), and if the chair controller hasn't got a response darn near immediately, it stops. If the mobile misses a response, it should send a 'stop' (a backup which might not be heard by the chair controller), and alert the operator. It wouldn't be a half-bad idea to have a watchdog timer (in hardware) on the chair that stops the motors if the chair controller doesn't reset it on short intervals. The chair controller is software; software sometimes fails. You'd like to detect that in hardware in time to cut the drive to the chair before it hits an obstruction or drives into the street.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.