Bluetooth controlled walking robot

I have done a project to control a robot from mobile phone using HC-05 bluetooth module.

I have done everything but my motors won't spin.

Here's my code:

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int motorSpeedA = 0;
int motorSpeedB = 0;

int val = 0;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(38400);
}

void loop() {
  //Read input from bluetooth module:
  if ( Serial.available())
  {
    val = Serial.read();
    delay(10);
  }
  delay(10);
  //Input key switch
  switch (val) {
    case '0':
      motorSpeedA = 0;
      motorSpeedB = 0;//Code when no key is pressed
      break;
    case '1':
      // Set Motor A forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);//Code when UP key is pressed
      break;
    case '2':
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);//Code when DOWN key is pressed
      motorSpeedA = 255;
      motorSpeedB = 255;
      break;
    case '3':
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      //Code when LEFT key is pressed
      break;
    case '4':
      //Code when RIGHT key is pressed
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      break;
    case '5':
      //Code when X key is pressed
      motorSpeedA = 0;
      break;
    case '6':
      //Code when O key is pressed
      motorSpeedB = 0;
      break;
    default:
      motorSpeedA = 255;
      motorSpeedB = 255;
      // default code (should never run)
  }
  analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
  analogWrite(enB, motorSpeedB);
}

I have attached my circuit below.

Pls tell me what I have did wrongly

Where is the simpler test program you wrote that doesn't rely on serial comms?

Did that spin the motors?

I made only this program

I don't understand what you are telling?

Pls explain me'

Yovan10:
I made only this program

But there's a much simpler test program that you wrote earlier, that sets up the output pins and switches on the motors, and doesn't rely on unproven serial communications, right?

AWOL:
But there's a much simpler test program that you wrote earlier, that sets up the output pins and switches on the motors, and doesn't rely on unproven serial communications, right?

He means that you should create that simple program if you have not already done so.

Build a computer program as a series of parts and then each part can be tested separately. Only bring the parts together when you can get each part to work on its own.

These links may help
Serial Input Basics - simple reliable ways to receive data.
Planning and Implementing a Program

...R

Pls tell how to create a simpler test program

I used the app called Arduino BT Joystick developed by heightDev

Can you prescribe me any other good app

Write a simple sketch (yes, you can use delay) that sets up the output pins, and then ramps up the speed on one motor, printing the values as they are applied.
Make sure there are long delays (human-sized long delays) between updates, so you can read the results off the serial monitor.

Can this Be because of LOW battery

AWOL:
Write a simple sketch (yes, you can use delay) that sets up the output pins, and then ramps up the speed on one motor, printing the values as they are applied.
Make sure there are long delays (human-sized long delays) between updates, so you can read the results off the serial monitor.

Can you give me the sketch for this pls bro

I can't write a sketch for hardware I don't have (well, I could, but I couldn't then test it, so there'd be little point in me giving it to you - it would only further confuse things)

I'm doing a project on a walking robot controlled by a mobile phone using a HC-05 bluetooth module.

I,ve done my code and everything is fine.But I can't send the values from my phone to my module.

Here's my code:

#define enA 9
#define in1 4
#define in2 5
#define enB 10
#define in3 6
#define in4 7

int motorSpeedA = 0;
int motorSpeedB = 0;

int val = 0;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(enB, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  Serial.begin(38400);
}

void loop() {
  //Read input from bluetooth module:
  if ( Serial.available())
  {
    val = Serial.read();
  }
  
  
  //Input key switch
  switch (val) {
    case '0':
      motorSpeedA = 0;
      motorSpeedB = 0;//Code when no key is pressed
      break;
    case '1':
      // Set Motor A forward
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      // Set Motor B forward
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);//Code when UP key is pressed

     Serial.println("<Setting Motor Forward>");
      break;
    case '2':
    if(val = 2){
      // Set Motor A backward
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      // Set Motor B backward
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      //Code when DOWN key is pressed
      motorSpeedA = 255;
      motorSpeedB = 255;
      Serial.println("<Backward>");
      }
      break;
    case '3':
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, LOW);
      digitalWrite(in2, HIGH);
      digitalWrite(in3, HIGH);
      digitalWrite(in4, LOW);
      Serial.println("<Left>");
      //Code when LEFT key is pressed
      break;
    case '4':
      //Code when RIGHT key is pressed
      analogWrite(enA, 180); //speed 0 - 255
      analogWrite(enB, 180); //speed 0 - 255
      digitalWrite(in1, HIGH);
      digitalWrite(in2, LOW);
      digitalWrite(in3, LOW);
      digitalWrite(in4, HIGH);
      Serial.println("<right>");
      break;
    case '5':
      //Code when X key is pressed
      motorSpeedA = 0;
      break;
    case '6':
      //Code when O key is pressed
      motorSpeedB = 0;
      break;
    default:
      motorSpeedA = 255;
      motorSpeedB = 255;
      // default code (should never run)
  }
  analogWrite(enA, motorSpeedA); // Send PWM signal to motor A
  analogWrite(enB, motorSpeedB);
}

I'm using the app called Arduino RC as a controller, It's available in the Play store.

I have attached my circuit below.

Can anyone tell me why can't I send Values to my module.

I have used the serial monitor optiion to check If im receiving values but I can't.

Also I'm using values 1-6 only.

Pls correct me If my code is wrong.. :confused: :confused: :confused:

But I can't send the values from my phone

Crucial item of information there, I feel.

I have used the serial monitor option to check If Im receiving values but I can't.

With the bluetooth module connected to the hardware serial pins, you can not use the serial monitor.

If you disconnect the HC05 your code should be able to run it with input from the serial monitor through usb. Set the serial monitor for no line ending.

First order of business is to confirm that your code works with the serial monitor for input. Then you can replace the monitor with the phone and HC05. Is it an Android phone?
If so, instead of the RC app, you should start with a basic BT terminal app, like Kai Morich's Serial Bluetooth Terminal to send the values from 1-6.