HC-06 not working ? ( rc car project )

Hi There

Trying my first ever arduino project , (long term reader , newbie maker )

so I have tried to hookup an rc car to an arduino uno with an r3 motor sheild.

when I have the usb connected into the uno and I send commands over the serial the motors work and the RC car works as expected.

when I then take the usb connection out and start the hc-06 , I try to send commands over tera term but the tera term page is unresponsive as bellow

I have tried the hc-06 and it worked fine on this project that I copied

this is the code I am using

// Bluetooth-bot v1
// Arduino Robotics unofficial chapter 14
// use Bluetooth Mate serial adapter to receive commands from PC
// Arduino decodes commands into motor movements
// Creates high-speed wireless serial link for robot control using keyboard
// Uses keys "i" = forward, "j" = left, "k" = reverse, and "l" = right
// speed control is also implemented using "," = speed down, "." = speed up, and "/" = max speed.

// L298 motor control variables
int M1_A = 12; // if using Ardumoto, change to pin 13
int M1_PWM = 3;
int M1_B = 9; // if using Ardumoto, remove this variable

int M2_A = 13; // if using Ardumoto, change to pin 12
int M2_PWM = 11;
int M2_B = 8; // if using Ardumoto, remove this variable

// LED pin attached to Arduino D13
int LED = 5;

// variable to store serial data
int incomingByte = 0;

// variable to store speed value
int speed_val = 255;

//////////////////////////////

void setup(){

TCCR2B = TCCR2B & 0b11111000 | 0x01; // change PWM frequency for pins 3 and 11 to 32kHz so there will be no motor whining

// Start serial monitor at 115,200 bps
Serial.begin(115200);

// declare outputs
pinMode(LED, OUTPUT);

pinMode(M1_A, OUTPUT);
pinMode(M1_PWM, OUTPUT);
pinMode(M1_B, OUTPUT);

pinMode(M2_A, OUTPUT);
pinMode(M2_PWM, OUTPUT);
pinMode(M2_B, OUTPUT);

// turn motors Off by default
M1_stop();
M2_stop();

delay(500);

}

////////////////////////////////////

void loop(){

// check for serial data
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// if available, blink LED and print serial data received.
digitalWrite(LED, HIGH);
// say what you got:
Serial.print("I received: ");
Serial.println(incomingByte);
// delay 10 milliseconds to allow serial update time
delay(10);

// check incoming byte for direction
// if byte is equal to "46" or "," - raise speed
if (incomingByte == 46){
speed_val = speed_val + 5;
test_speed();
Serial.println(speed_val);
}
// if byte is equal to "44" or "." - lower speed
else if (incomingByte == 44){
speed_val = speed_val - 5;
test_speed();
Serial.println(speed_val);
}
// if byte is equal to "47" or "/" - max speed
else if (incomingByte == 47){
speed_val = 255;
test_speed();
}

// if byte is equal to "105" or "i", go forward
else if (incomingByte == 105){
M1_forward(speed_val);
M2_forward(speed_val);
delay(25);
}
// if byte is equal to "106" or "j", go left
else if (incomingByte == 106){
M1_reverse(speed_val);
M2_forward(speed_val);
delay(25);
}
// if byte is equal to "108" or "l", go right
else if (incomingByte == 108){
M1_forward(speed_val);
M2_reverse(speed_val);
delay(25);
}
// if byte is equal to "107" or "k", go reverse
else if (incomingByte == 107){
M1_reverse(speed_val);
M2_reverse(speed_val);
delay(25);
}
// otherwise, stop both motors
else {
M1_stop();
M2_stop();
}

}

else {
M1_stop();
M2_stop();
digitalWrite(LED, LOW);
}
}

void test_speed(){
// constrain speed value to between 0-255
if (speed_val > 250){
speed_val = 255;
Serial.println(" MAX ");
}
if (speed_val < 0){
speed_val = 0;
Serial.println(" MIN ");
}

}

/////////// motor functions ////////////////

void M1_reverse(int x){
digitalWrite(M1_B, LOW);
digitalWrite(M1_A, HIGH);
analogWrite(M1_PWM, x);
}

void M1_forward(int x){
digitalWrite(M1_A, LOW);
digitalWrite(M1_B, HIGH);
analogWrite(M1_PWM, x);
}

void M1_stop(){
digitalWrite(M1_B, LOW);
digitalWrite(M1_A, LOW);
digitalWrite(M1_PWM, LOW);
}

void M2_forward(int y){
digitalWrite(M2_B, LOW);
digitalWrite(M2_A, HIGH);
analogWrite(M2_PWM, y);
}

void M2_reverse(int y){
digitalWrite(M2_A, LOW);
digitalWrite(M2_B, HIGH);
analogWrite(M2_PWM, y);
}

void M2_stop(){
digitalWrite(M2_B, LOW);
digitalWrite(M2_A, LOW);
digitalWrite(M2_PWM, LOW);
}

please help this is the only problem I have had with arduino so far its as if the bluetooth module just isnt responding , the red LED on the hc-06 flashes when there are no connections but when I load up tera term or arduino ide and connect it to the hc-06 the red LED stops flashing indicating that it does have a connection ,

I am a bit stumped here , please help if possible

If it works over the cable, there is nothing wrong with the code. If the LED goes solid, it indicates kosher connection between bluetooth devices. It does not mean kosher connection between Arduino and Bluetooth. Is the wiring correct Tx>Rx Rx>Tx? Has the HC-06 been configured to run at 115200?

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Also mind some BT modules (ie HC-05) go into a sleep when not receiving data from their serial side (tx/rx) for at least ie. 5 seconds. After that they need some time to wake up from the sleep, and your data may get lost.

pito:
Also mind some BT modules (ie HC-05) go into a sleep when not receiving data from their serial side (tx/rx) for at least ie. 5 seconds. After that they need some time to wake up from the sleep, and your data may get lost.

WOW! I didn't know that. How can you tell that it is likely to go to sleep? I guess you can configure it to stay awake (!?)

Being just a datalogger, my blueteeth get a nudge every second but, if you are waiting for incoming traffic, this could be a problem. I recognise this is unlikely with HC-06