My bluetooth car bluetooth is getting disconnected after sending a data to it

my code is given below
#include <SoftwareSerial.h>

SoftwareSerial bluetooth(2, 3); // RX, TX pins

#define motor1A 4
#define motor1B 5
#define motor2A 6
#define motor2B 7

int motorSpeed = 255; // Default motor speed, range: 0 to 255

void setup() {
Serial.begin(9600);
bluetooth.begin(9600);

pinMode(motor1A, OUTPUT);
pinMode(motor1B, OUTPUT);
pinMode(motor2A, OUTPUT);
pinMode(motor2B, OUTPUT);
}

void moveForward() {
analogWrite(motor1A, motorSpeed);
digitalWrite(motor1B, LOW);
analogWrite(motor2A, motorSpeed);
digitalWrite(motor2B, LOW);
}

void moveBackward() {
digitalWrite(motor1A, LOW);
analogWrite(motor1B, motorSpeed);
digitalWrite(motor2A, LOW);
analogWrite(motor2B, motorSpeed);
}

void turnLeft() {
digitalWrite(motor1A, LOW);
analogWrite(motor1B, motorSpeed / 2);
analogWrite(motor2A, motorSpeed);
digitalWrite(motor2B, LOW);
}

void turnRight() {
analogWrite(motor1A, motorSpeed);
digitalWrite(motor1B, LOW);
digitalWrite(motor2A, LOW);
analogWrite(motor2B, motorSpeed / 2);
}

void stopMoving() {
analogWrite(motor1A, 0);
digitalWrite(motor1B, 0);
analogWrite(motor2A, 0);
digitalWrite(motor2B, 0);
}

void loop() {
if (bluetooth.available() > 0) {
char command = bluetooth.read();
switch (command) {
case 'F':
moveForward();
break;
case 'B':
moveBackward();
break;
case 'L':
turnLeft();
break;
case 'R':
turnRight();
break;
case 'S':
stopMoving();
break;
case '0':
motorSpeed = 0; // Stop the car
break;
case '1':
motorSpeed = 100; // Set speed to 100
break;
case '2':
motorSpeed = 150; // Set speed to 150
break;
case '3':
motorSpeed = 200; // Set speed to 200
break;
case '4':
motorSpeed = 255; // Set speed to maximum (255)
break;
}
}
}

Please reformat your code and then post it with tags so we can read it. And share a connection diagram (can be a photo of a hand-drawn one) that shows how your Arduino is powered.

How do you know the car Bluetooth it is getting disconnected?

I moved your topic to an appropriate forum category @pratyuh.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

#include

SoftwareSerial bluetooth(2, 3); // RX, TX pins

#define motor1A 4
#define motor1B 5
#define motor2A 6
#define motor2B 7

int motorSpeed = 255; // Default motor speed, range: 0 to 255
commands functioning
void setup() {
Serial.begin(9600);
bluetooth.begin(9600);

pinMode(motor1A, OUTPUT);
pinMode(motor1B, OUTPUT);
pinMode(motor2A, OUTPUT);
pinMode(motor2B, OUTPUT);
}

void moveForward() {
analogWrite(motor1A, motorSpeed);
digitalWrite(motor1B, LOW);
analogWrite(motor2A, motorSpeed);
digitalWrite(motor2B, LOW);
}

void moveBackward() {
digitalWrite(motor1A, LOW);
analogWrite(motor1B, motorSpeed);
digitalWrite(motor2A, LOW);
analogWrite(motor2B, motorSpeed);
}

void turnLeft() {
digitalWrite(motor1A, LOW);
analogWrite(motor1B, motorSpeed / 2);
analogWrite(motor2A, motorSpeed);
digitalWrite(motor2B, LOW);
}

void turnRight() {
analogWrite(motor1A, motorSpeed);
digitalWrite(motor1B, LOW);
digitalWrite(motor2A, LOW);
analogWrite(motor2B, motorSpeed / 2);
}

void stopMoving() {
analogWrite(motor1A, 0);
digitalWrite(motor1B, 0);
analogWrite(motor2A, 0);
digitalWrite(motor2B, 0);
}
command
void loop() {
if (bluetooth.available() > 0) {
char command = bluetooth.read();
switch (command) {
case 'F':
moveForward();
break;
case 'B':
moveBackward();
break;
case 'L':
turnLeft();
break;
case 'R':
turnRight();
break;
case 'S':
stopMoving();
break;
case '0':
motorSpeed = 0; // Stop the car
break;
case '1':
motorSpeed = 100; // Set speed to 100
break;
case '2':
motorSpeed = 150; // Set speed to 150
break;
case '3':
motorSpeed = 200; // Set speed to 200
break;
case '4':
motorSpeed = 255; // Set speed to maximum (255)
break;
}
}
}
it 's my code and iam a begineer so i cannot understand what do you mean by tagging it

it is disconnecting as it show's in my bluetooth teminal

What kind of Bluetooth module are you using?
Are you sure 9600 is the right bit rate your module expects?

Also, please share a diagram showing how the Arduino and the motors are powered.

i am using hc05 bluethooth . what bit rate should i use ?

What is the 12v supply?
What Bluetooth terminal app are you using?

I would not take the 5v from the motor driver board to to the HC06 or the Arduino. Let it just be an internal supply for the board.

Power the HC06 from the 5v pin of the Arduino.

12v means i am using 3 lithium 3.7 volt battery.

i don't know what you are saying in the second thing.
i am not giving the Bluetooth 5v from motor driver.
but i am giving 5v to Bluetooth and motor driver both from the board

I recommend that Kai Morich's Serial Bluetooth Terminal is the App to be used on the phone

i am not giving the Bluetooth 5v from motor driver.
but i am giving 5v to Bluetooth and motor driver both from the board

Can you provide a link the the motor driver board you are using. Some of then have a jumper where the 5v logic supply to the board can come from the motor voltage supplied to the driver board. It would be better to use that than 5v from the Arduino.

Your initial schematic is very hard to read, and some of the connections are not clear. Can you try again with darker lines.

By the way i am using

https://amzn.eu/d/gS2XKns
Motor drive
But now the Bluetooth is not even working :sob:

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