My HC-05 Bluetooth module is not responding in AT Command mode. I've tried several different tutorials, and I'm successfully getting it to the point where it blinks slowly (every two seconds) so I think it's in AT Command mode. However, I can't seem to get any response back from the BT module. I'm not getting that "OK" when I send the "AT" command. I've read just about all the forum posts with no luck. Any other ideas are greatly appreciated! Thanks!
I am not home to be sure but i think this is the one, upload it to arduino check/change SoftwareSerial ports and open serial monitor.
#include <SoftwareSerial.h>
SoftwareSerial bluetooth_serial(10, 11);
volatile boolean bluetooth_serial_rate_detected = false;
long serial_rates[] = {
9600, 57600, 115200,
19200, 38400, 4800, 2400, 1200, 230400
};
bool discover_bluetooth_serial_rate() {
for (int i = 0; i < (sizeof(serial_rates)/sizeof(long)); i++) {
Serial.print(".");
long rate = serial_rates[i];
bluetooth_serial.begin(rate);
bluetooth_serial.write("AT");
bluetooth_serial.flush();
if (bluetooth_serial.readString() == "OK") {
Serial.println("\nBluetooth Serial Rate detected: " + String(rate));
return true;
} else {
bluetooth_serial.end();
}
}
Serial.println("\nBluetooth Serial Rate not detected.");
return false;
}
void setup() {
Serial.begin(9600);
bluetooth_serial_rate_detected = discover_bluetooth_serial_rate();
}
void loop() {
if(bluetooth_serial_rate_detected) {
if (bluetooth_serial.available()) {
String s = "";
char c;
while((c = bluetooth_serial.read()) != -1) {
s += c;
delay(5);
}
Serial.println("Received: " + s);
}
if (Serial.available()) {
String s = "";
char c;
while((c = Serial.read()) != -1) {
s += c;
delay(5);
}
Serial.println("Sent: " + s);
bluetooth_serial.print(s);
}
}
}
This is for config (AT+Commands) BT, just be sure that you put TX RX cross between BT and Arduino.
nancyp:
My HC-05 Bluetooth module is not responding in AT Command mode. I've tried several different tutorials, and I'm successfully getting it to the point where it blinks slowly (every two seconds) so I think it's in AT Command mode. However, I can't seem to get any response back from the BT module. I'm not getting that "OK" when I send the "AT" command. I've read just about all the forum posts with no luck. Any other ideas are greatly appreciated! Thanks!
There are several types of HC-05 modules.
See if yours is like this one --> Arduino with HC-05 (ZS-040) Bluetooth module – AT MODE – Martyn Currey
The problems with configuring the HC-05 are twofold
-
Getting it into AT mode. This does not involve Arduino per se. All Arduino does is provide the power.
-
Sending the commands. This does involve Arduino, so it needs the proper connections and the proper code.
it blinks slowly (every two seconds) so I think it's in AT Command mode.
This is correct, so you have succeeded at item 1!
So you now need to ensure the connections are kosher Rx>Tx and TX>Rx.
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
There is some configuration for use with a Mega, but I think Currey has the most sensible universal code at the abovementioned link. But, before you rush there, it would appear that you are not so familiar with bluetooth, so do you really need to do this?
Sorry wasn't the code i use to send commands, this is that i use and works.
/*
#include <SoftwareSerial.h>
SoftwareSerial Serial1(8, 9);
int led = 13;
int ledHIGH = 0;
long bauds[] = {
// major
9600, 57600, 115200,
// others
19200, 38400, 4800, 2400, 1200, 230400
};
bool detectBleBaudRate() {
Serial.println("Detecting BLE baud rate:");
for (int i=0; i<(sizeof(bauds)/sizeof(long)); i++) {
Serial.write("Checking ");
long cur_baud = bauds[i];
Serial.println(cur_baud, DEC);
Serial1.begin(cur_baud);
Serial1.write("AT");
Serial1.flush();
delay(50);
String response = Serial1.readString();
if (response == "OK") {
Serial.println("Detected");
return true;
} else {
Serial1.end();
}
}
return false;
}
void setup() {
// init
Serial.begin(115200); // USB (choose 115200 in terminal)
if (detectBleBaudRate())
Serial.write("Ready, type AT commands\n\n");
else
Serial.write("Not ready. Halt");
pinMode(led, OUTPUT);
}
void loop() {
// read from BLE (HM-10)
if (Serial1.available()) {
Serial.write("ble: ");
String str = Serial1.readString();
Serial.print(str);
Serial.write('\n');
}
// read from USB (Arduino Terminal)
if (Serial.available()) {
Serial.write("usb: ");
String str = Serial.readString();
Serial1.print(str);
Serial.print(str);
Serial.write('\n');
}
}