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
#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'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
#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
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.
// 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.
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