Problems with AT commands to Bluetooth HC-06

Anyone have HC-06s not responding to AT commands issued from a sketch (see the code below)?

I have a bunch of devices, all with three things in common:

  • ATtiny processor (different ones, but all with serial port, like 2313, 4313, 87...),
  • HC-06 bluetooth module connected to Tiny's RX and TX pins, and
  • ISP connector for programming.

The idea was to customize the Bluetooth device name, pairing PIN and UART communication speed by uploading a sketch (using my Mega2560 and "Arduino as ISP" example code) :

void setup() {
   Serial.begin(9600);
   delay(1000);
   Serial.print("AT+NAMEBT 001");
   delay(1000);
   Serial.print("AT+PIN4321");
   delay(1000);
   Serial.print("AT+BAUD7");
}

void loop() {
}

Then' I'd "File => Upload Using Programmer" the code that should actually run on the device.

Two identical (at least the intention was) devices with Attiny 4313 and HC-06. Upload the intended code that the device is intended for; both work. Now upload above BT config code, then regular running code again. The first device successfully changes name, pin and baud rate. The second does nothing, and HC-06 still has original "HC-06" name and still operates at 9600 bps.

Now things get weird one step further: uploading BT config code to change back the first HC-06's name, pin and baud rate - does nothing (I did remember to change the speed in Serial.begin). Now I have two Bluetooth modules that do not respond to AT commands... Could it be a timing issue with "Serial.print" commands?

(the baud rate in Serial.begin was correct, and the Bluetooth modules were not paired to anything - the LEDs on PIO1 are blinking; names and PINs checked by searching for Bluetooth devices using Amarino on Android phone)

The AT commands period with HC-06 shall not exceed 1000ms, I think. Try to remove the delays, or use delay(200) instead, for example..

Pito,

My understanding was that 1000 ms was the maximum delay between characters in a command, not between commands, but you got me thinking about it, so I tried delay(200), which did not work; then I tried delay(2000) between the commands, and that WORKED! Apparently 1000 ms was just cutting it too close…

Trying different things, I noticed another quirk: trying to change the name from “Test1234” to something else with the following code (Mega2560, HC-06 TX attached to D10, RX to D11):

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
   mySerial.begin(57600);
   mySerial.print("AT+NAME123456789012345");
}

void loop() {
}

… failed. However, one character less - mySerial.print(“AT+NAME12345678901234”) - worked fine! But when I changed the Bluetooth UART baud rate to 9600, I was able to set names up to 20 characters without problems. I would now dare to guess that the cause is the deviation of both the Bluetooth and Arduino UART baud rates from nominal values (and from each other), and that higher speeds may require hardware flow control. The problems are then going to be more pronounced with Tiny MCUs running at lower speeds and with on-chip oscillators.

Hi Guys!

I tried your sketch, but it doesnt work for me. The wiring is correct, so is the Baudrate (tried it with different ones). Tried it with an Arduino UNO and an Arduino Mega 2560.

The SoftwareSerial example works. The data I am sending through my phone (Android Bluetooth Terminal) shows up in the Serial Monitor of the Arduino IDE. Then I disconnect my phone (BT Module blinking), and upload the sketch to change the baudrate. Nothing happens.Baudrate isnt changing.

I also tried many other sketches like SoftwareSerial Example and manually send the AT commands, but I do not get any response from the HC-06. Not even an “OK” when i ping it with “AT”. Everthing else is working exept the AT settings. Any Ideas?

Thanks

:slight_smile: :slight_smile:
Hello, sombody already resolve this issue?

I have the same problem, I send AT commands using Monitor Serial and Im not getting any response from bluetooth

My experience is that whenever there is no OK when you send AT, if the wiring is correct (for example, that Bluetooth's TX should be connected to Arduino's RX, and vice versa), the problem is the Bluetooth module's serial port speed (mySerial.begin command). Do not forget to upload the code when you change the speed :slight_smile:

I have the a similar problem with a bluetooth module, the problem was the voltage level, the module that i have is 3.3v so I can send commands but I can't receive a response because the answer voltage level was too low and the arduino doesn't see it, I try using the arduino board as a pure USB-TTL interface (GND to RST) and in that way I can communicate with the module to test it, so my assumption was the voltage level was wrong,

I bought a new Bluetooth module that is 5v and it works pretty good, i don't have any problem with it and arduino.

The bluetooth's led is blinking but it is posible the bluetooth is damaged? :frowning:

I already doble check the wiring, I have seen in other sites it needs 2 resistors but I checked it with the seller and he said he just connect directly to the arduino

raffe:
The bluetooth’s led is blinking but it is posible the bluetooth is damaged?

It probably isn’t. The blinking light simply means the power is there but Arduino has not been paired. You should able to test this by attempting a connection without all that AT stuff.

I already doble check the wiring, I have seen in other sites it needs 2 resistors but I checked it with the seller and he said he just connect directly to the arduino

It is now clear that the Bluetooth Rx/Tx run on 3.3v. Arduino doesn’t care about this but bluetooth might complain about getting 5v on the Rx from Arduino, and a divider is a sensible precaution. Having said that, I have never done it myself, and my bluetooth runs more or less continuously for months.

Yep the LED is just power.

Try using the board as a USB-TTL converter, just jumper the reset pin and the GND pin, connect TX to RX and RX to TX and send AT commands directly from the terminal monitor, if it works it means you have the same problem that I had and you will need to get a 5V module

It is now clear that the Bluetooth Rx/Tx run on 3.3v. Arduino doesn’t care about this but bluetooth might complain about getting 5v on the Rx from Arduino

well, thats not completly true, because if the TX from the bluetooth voltage is 3.3V arduino will not detect it because the “HIGH” voltage level is above 4.5V

Hi hsaul17, what do you mean with jumper the reset pin? which is the reset pin, is it an arduino's pin?

Yep the LED is just power.

Nope. The LED indicates whether or not the device is paired.

well, thats not completly true, because if the TX from the bluetooth voltage is 3.3V arduino will not detect it because the "HIGH" voltage level is above 4.5V

That's not what Table 28-1 of the ATmega328 data sheet says.

Don

When using 3.3 V Bluetooth with 5 V Arduino (say, 5 V Pro Mini), generally, you should not connect Arduino's TX directly to Bluetooth's RX. This is what I do, and I have a number of prototypes working this way:

  • Arduino GND to Bluetooth GND
  • Arduino VCC, through two diodes 1N4148 in series - anode of the first diode to Arduino, cathode of the second diode to Bluetooth VCC
  • Arduino's RX to Bluetooth's TX
  • Arduino's TX, through 1k8 resistor, to Bluetooth's RX (this may become a problem at higher speeds, but runs fine for me at 38400 baud)

Leave Bluetooth's reset not connected (The pin configuration figure does show the 10 k pulldown resistor, and partially a 220 n capacitor,but those components are built-in on the HC Bluetooth module.

Hi guys, I bought another bluetooth module and I wired it the same way and the same code and It works! :-/

:slight_smile: hello guys

I was working OK with AT Commands until I changed the baud rate , I sent AT+BAUD9(baud rate 230400) and It stop to respose OK to AT Commands

Then I uploaded my sketch again and initialized the serial with mySerial.begin(230400) but I realized that serial monitor doesn't work with that baud rate :frowning: , so how can I change the baud rate again?

so how can I change the baud rate again?

Use another terminal program such as 'Br@y's Terminal' which apparently is now just called 'Terminal'.

Don

floresta:

so how can I change the baud rate again?

Use another terminal program such as 'Br@y's Terminal' which apparently is now just called 'Terminal'.
Terminal

Don

I tried with Terminal v1.91b but when I send AT+VERSION I got ERROR message if I just send AT I receive OK
I connected the bluetooth module through my arduino uno , so I dont know if a I have connect bluetooth module to my pc for use Terminal program

I have programmed a HC06 through an Arduino and now it can connect to my laptop. I am wondering if it is possible to send commands from my laptop via bluetooth to HC06 and program the Tx and Rx pins on HC06. Basically, I want to connect a LED to the Tx pin of HC06 and turn it On/Off from my laptop via bluetooth (without an Arduino).

Thanks.

pjadhav:
I want to connect a LED to the Tx pin of HC06 and turn it On/Off from my laptop via bluetooth (without an Arduino).

I believe it is possible to do essentially what you want but you connect the LED to one of the other contacts on the HC-06.

  1. send code to arduino
  2. off voltage arduino and module bt
  3. on voltage arduino and module bt
  4. wait 10s

Serial.begin ----> usb -----> PC monitor port
Serial1.begin ----> PWM 0RX , 1TX ---> bt module

void setup() {
delay(5000); //5s.
Serial1.begin(9600); //last setting BAUD4 ? OK
delay(1000);

//seting bt module AT comend
Serial1.print("AT+NAMEBT PRIVATE");
delay(1000);
Serial1.print("AT+PIN4321");
delay(1000);
Serial1.print("AT+BAUD7");
}

void loop() {
delay(10000);
}

/*
The posible baudrates are:
AT+BAUD1-------1200
AT+BAUD2-------2400
AT+BAUD3-------4800
AT+BAUD4-------9600 - Default for hc-06
AT+BAUD5------19200
AT+BAUD6------38400
AT+BAUD7------57600 - Johnny-five speed
AT+BAUD8-----115200
AT+BAUD9-----230400
AT+BAUDA-----460800
AT+BAUDB-----921600
AT+BAUDC----1382400
*/