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