hc-05 bluetooth module is losing connection while commanding

I want to make a bluetooth controlled car.
I have bought myself a hc-05 bluetooth module. It is operating nicely when only it is used in arduino.
When I am connecting arduino with the L298N motor driver shield and connecting bluetooth with arduino's 5V pin and other respective pins, the module is blinking and is easily paired with phone.
(i.e.- hc-05 is not working with 3.3V connection.)

But when I am trying to give command, the connection is lost. It is working nicely if I connect it with my computer.

my code is here::

int AIN1 = 2;
int AIN2 = 3;
int BIN1 = 4;
int BIN2  = 5;
int APWM = 9;
int BPWM = 10; 
int spd =  150;

char data;

void setup()
{
  Serial.begin(9600);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  pinMode(APWM, OUTPUT);
  pinMode(BPWM, OUTPUT);
}

void loop()
{
   if(Serial.available())
   {
    data = Serial.read();
   }
   analogWrite(APWM, 200);
   analogWrite(BPWM, 200);
   
   if(data == 'S')
   {
    Release();
   }
   if(data == 'F')
   {
    forward();
    delay(10);
   }
   if(data == 'B')
   {
    backward();
    delay(10);
   }
   if(data == 'R')
   {
    right();
    delay(10);
   }
   if(data == 'L')
   {
    left();
    delay(10);
   }
}

void forward()
{
  digitalWrite(AIN1, HIGH);
  digitalWrite(AIN2, LOW);
  digitalWrite(BIN1, HIGH);
  digitalWrite(BIN2, LOW);
}

void backward()
{
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, HIGH);
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, HIGH);
}

void Release()
{
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, LOW);
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, LOW);
}

void left()
{
  digitalWrite(AIN1, HIGH);
  digitalWrite(AIN2, LOW);
  digitalWrite(BIN1, LOW);
  digitalWrite(BIN2, HIGH);
}

void right()
{
  digitalWrite(AIN1, LOW);
  digitalWrite(AIN2, HIGH);
  digitalWrite(BIN1, HIGH);
  digitalWrite(BIN2, LOW);
}

I need help in this perspect...

1 Like

This might have something to do with the power supply, but this

" It is working nicely if I connect it with my computer"

is far from clear. What do you mean by connection?

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