UNO and Bluetooth HC06 AT commands

Hello,

I'm stuck with my UNO and a HC06 bluetooth module.

HC6 Vcc - Uno Vcc (5v)
HC06 Gnd - Uno Gnd
HC06 TxD - Uno D10
HC06 RxD - Uno D11 through a voltage divider (+3.3V)

My HC06 led is blinking, so no paired.

My sketch:

#include <SoftwareSerial.h>

SoftwareSerial Serial2(10, 11);

void setup(){

Serial.begin(9600);
Serial2.begin(9600);
delay(2000);
Serial.print("AT: ");
Serial2.print("AT");
delay(1000);
}

void loop() {
if(Serial.available()) Serial2.write(Serial.read());
if(Serial2.available()) Serial.write(Serial2.read());
}

After compilation and load, the "AT" command is sent but no answer from the HC06.
If I send an AT command trought the Serial Monitor, nothing append.
I tried another HC06 module but the result is the same.

It might be down to how your command is assembled. Here is a one-shot example I use. Just add your Software serial stuff. Serial monitor is just aide memoire

String command = ""; // Stores response from HC-06 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth 

  Serial.print("AT      ");  
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    char c = Serial1.read();
      command += c;    
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats

  Serial.print("AT+NAMEFosters      "); 
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }
  delay(2000);
  Serial.println(command);
  command = ""; // No repeats

  Serial.println("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read();  
    }
  }
  delay(2000);   
  Serial.println(command);
  command = ""; // No repeats

  Serial.print("AT+BAUD8      ");  
  Serial1.print("AT+BAUD8");               //CHANGE SPEED TO 115K
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      command += (char)Serial1.read();    
    } 
  } 
delay(2000);       
Serial.println(command);
}

void loop(){
}   //one-shot - nothing here

Hello,

I followed your advice without success.

My code, using yours, is...

#include <SoftwareSerial.h>

#define Serial_HC06_RxD 11
#define Serial_HC06_TxD 12

SoftwareSerial Serial1(Serial_HC06_RxD, Serial_HC06_TxD); // HC06 (Bluetooth) serial port

String command = ""; // Stores response from HC-06 

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth 

  Serial.print("Send AT..");  
  Serial1.print("AT");                  //PING
  delay(2000);
  Serial.print(".");
  if (Serial1.available()) {
    Serial.print("Data received from BT!");
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    char c = Serial1.read();
      command += c;    
    }
  }
  delay(2000);
  Serial.print("End setup.");
}

void loop(){
}   //one-shot - nothing here

No answer from the BT module.
I don't know if the module receives something...
Is there a change of the led blinking when the BT module is receiving an AT command?

I have 2 BT modules and the result is the same.

Hello,

I've made some new tests to check if the SoftwareSerial was not the cause...

In the code below, I'm using only the hardware serial.
I'm blinking 5 time the internal led before sending the "AT" command and in case of any answer I power on the LED.
Result... nothing :frowning:

#define LED13           13

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor

  pinMode(LED13, OUTPUT); // LED13 Blink 5 time
  for (int Cpt = 0 ; Cpt < 5 ; Cpt++){
    digitalWrite(LED13, HIGH);
    delay(1000);
    digitalWrite(LED13, LOW);
    delay(1000);
  }
  
  Serial.print("AT");                  //PING
  delay(2000);
  if (Serial.available()) {
    digitalWrite(LED13, HIGH);        // Power up LED13 in case of BT answer
  }
}

void loop(){
}   //one-shot - nothing here

blob13:
Is there a change of the led blinking when the BT module is receiving an AT command?

Yes. The LED changes from fast (2Hz) to slow (0.5Hz)

Make sure your wiring is kosher.
This may help a little,

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

but I don't deal with configuration very much. Have a look at the Martyn Currey website.

LED: As I remind, my led blinking doesn't change so it means my AT command never arrives to the BT module. :o

Thanks for all this advice.
I'll check my connections again.

The documents are very complete, I'll read it in detail.

Note that, with the HC-06, you don't have to do anything to enter AT mode. It is in AT by default with power-on, so long as you have not made a connection.

So...

  • document read.
  • wiring redone (resistors and wires changed)
  • sketch of the document used

No change concerning the led blinking
Same result! :frowning:

You can try the following (which should be similar to what you already have) and manually enter the commands in the serial monitor.

// Basic Bluetooth sketch HC-06_01
// Connect the Hc-06 module and communicate using the serial monitor
//
// The HC-06 defaults to AT mode when first powered on.
 
 
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
// Connect the HC-06 TX to the Arduino RX on pin 2. 
// Connect the HC-06 RX to the Arduino TX on pin 3 through a voltage divider.
// 
 
 
void setup() 
{
    Serial.begin(9600);
    Serial.println("Enter AT commands:");
    BTserial.begin(9600);  
}
 
void loop()
{
 
    // Keep reading from HC-06 and send to Arduino Serial Monitor
    if (BTserial.available())
    {  
        Serial.write(BTserial.read());
    }
 
    // Keep reading from Arduino Serial Monitor and send to HC-06
    if (Serial.available())
    {
        BTserial.write(Serial.read());
    }
 
}

There are various different modules, some of which use the same hardware and look the same but have different firmware and finding out which exact module you have is the key. What name does yours broadcast?

I presume your module is on a breakout board, if so what markings does it have; zs-040, FC-114, JY-MCU, KEYES, etc.

Some modules require uppercase, some require lowercase, some don't care.
Some require line end characters (\r\n). Others do not.
Most use 9600 baud rate but this is not guaranteed (I have a couple of weird ones that default to 38400).

Try the AT command in different ways; upper and lower case, with and without line end characters.
Do each one 2 or 3 times, not just once and wait more than a second between tries.

Some modules give welcome messages (such as the Bolutek ones) so cycle the power of the BT module while the Arduino is on and connected and with the serial monitor open.

If you do not get anything at 9600, try again at a different baud rate.

Hello,

thanks for your help.
I've tried your tips with the following sketch:

#include <SoftwareSerial.h>

// PINs definition
#define Serial_HC06_RxD 11
#define Serial_HC06_TxD 12

SoftwareSerial Serial_HC06(Serial_HC06_RxD, Serial_HC06_TxD); // HC06 (Bluetooth) serial port

//---------------------------------------------------------------------------------------------
void setup(){

Serial.begin(9600);     // Serial port init

Test(2400);
Test(4800);
Test(9600);
Test(19200);
Test(38400);
Test(57600);
Test(115200);
Serial.print("---------------------------END");
}

//---------------------------------------------------------------------------------------------
void Test(long Speed){

Serial.println("\n--------------------------- " + String(Speed));
Serial_HC06.begin(Speed);
delay(3000);

Serial.println("AT:");
Serial_HC06.print("AT");
Display_HC06();

Serial.println("at:");
Serial_HC06.print("at");
Display_HC06();

Serial.println("ATln:");
Serial_HC06.println("AT");
Display_HC06();

Serial.println("atln:");
Serial_HC06.println("at");
Display_HC06();
}

//---------------------------------------------------------------------------------------------
void Display_HC06(){
  delay(1000);
  while (Serial_HC06.available()){
    Serial.println(Serial_HC06.read());
    delay(500);
  }
}

//---------------------------------------------------------------------------------------------
void loop(){ 
}

The result in the Serial Monitor is...
--------------------------- 2400
AT:
at:
ATln:
atln:

--------------------------- 4800
AT:
at:
ATln:
atln:

--------------------------- 9600
AT:
at:
ATln:
atln:

--------------------------- 19200
AT:
at:
ATln:
atln:

--------------------------- 38400
AT:
at:
ATln:
atln:

--------------------------- 57600
AT:
at:
ATln:
atln:

--------------------------- 115200
AT:
at:
ATln:
atln:
---------------------------END

I've made another test...

Smartphone connected to the Arduino via HC06.
Using 'Bluetooth Terminal' to send and receive data.

It works!
I'm able to send strings from the BT-Terminal to the Arduino and display them on the Serial Monitor.
In add, when I'm able to send strings from the Serial Monitor and receive them on the BT-Terminal.

Detail, I had to set speed communication to 38400!

Concerning the AT commands, nothing better. Even if I use 38400 :frowning: