arduino cannot receive the data from hc-06

Hello, I am a new learner of arduino and I am trying to connect hc-06 with arduino nano to control my car by an app ('arduino bluetooth control', which would send 1,2,3,4 to the connected bluetooth module when I press up, down, left and right buttons) on my phone.

For my first try, everything went well for the first few minutes and my car went forward and turned normally, but later 'Error 516: unable to write: broken pipe' was shown on my phone. After that, though my phone can connect with hc06 (the light is on not flashing), RX of arduino doesn't flash and the car doesn't move anymore.
There is no 'error 516' on my screen after my first try, so I am not sure wehther it's the main cause for my failure.

Some details may required:
I use a powerbank to power my arduino nano, and 3 18650 batteries for L298N.

My code is

[code]
#include <SoftwareSerial.h>

SoftwareSerial BT(10, 11);

int motor_L1 = 3;
int motor_L2 = 5;
int motor_R1 = 6;
int motor_R2 = 9;

void setup()
{
  pinMode(motor_L1, OUTPUT);
  pinMode(motor_L2, OUTPUT);
  pinMode(motor_R1, OUTPUT);
  pinMode(motor_R2, OUTPUT);

  Serial.begin(9600);
}

char a;

void loop()
{
  if (Serial.available())

  {
    a = (Serial.read());


    if (a == '1') //if a=1 (the signal from the 'up' button from the bluetooth app) it will move forward
    {
      analogWrite(motor_L1, 0);
      analogWrite(motor_L2, 192);
      analogWrite(motor_R1, 0);
      analogWrite(motor_R2, 192);
    }


    if (a == '2') //it will move backwards
    {
      analogWrite(motor_L1, 192);
      analogWrite(motor_L2, 0);
      analogWrite(motor_R1, 192);
      analogWrite(motor_R2, 0);
    }


    if (a == '3') // it will move left
    {
      analogWrite(motor_L1, 192);
      analogWrite(motor_L2, 0);
      analogWrite(motor_R1, 0);
      analogWrite(motor_R2, 192);
    }


    if (a == '4') //it will move right
    {
      analogWrite(motor_L1, 0);
      analogWrite(motor_L2, 192);
      analogWrite(motor_R1, 192);
      analogWrite(motor_R2, 0);
    }


    if (a == '0') //it will not move
    {
      analogWrite(motor_L1, 255);
      analogWrite(motor_L2, 255);
      analogWrite(motor_R1, 255);
      analogWrite(motor_R2, 255);
    }

  }
}

Thank you![/code]

It was working and then that changed.
Check your wires.

Thank you for your advice, I will check it again.
I am considering replacing a new HC06.

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