Bluetooth HC-06 AT responds only to ONE command

Hello, recently I bought HC-06 adapter. I want to change it's baud rate. I searched almost entire web and nothing works. The only command I can work with is AT+NAMExxx. Then I get answer OKsetname, as expected. AT, AT+VERSION, AT+BAUDx, AT+PINxxxx, nothing returns any message. I'm using this sketch. I'm using SoftwareSerial, voltage divider. Also bought today second module, nothing changed.

// 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.
// The default baud rate is 9600
// The Hc‐06 requires all AT commands to be in uppercase. NL+CR should not be added to the command string
//
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 4); // 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:");
// HC‐06 default serial speed is 9600
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());
}
}

This makes no sense. If one command works, they all should. I'm guessing that it is a timing problem. The code below might fix that. It uses your wiring and is one shot - no hands.

/*
 One Shot
 Kudos to marguskohv - he sowed the seed....
Serial monitor is just aide memoire
 */
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2, 4); // RX | TX
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
1 Like

My instinct is that it's a software serial problem, ie, you're trying to send and receive from a software serial at the same time. SoftwareSerial is only half-duplex - it can only send OR receive at a given moment.

Thanks guys, code privided by Nick works great. Don't know what was going on with this one command, but for now it is perfect, thanks

Glad to hear that my code helped, I have never used it myself as I never use software serial. I suspect DrAzzy's post explained your problem better than my guess.

1 Like