Reliable Data Transfer with Arduino and HC-06 module

Configuring the module HC-06 can be interesting to verify that it is working, hooked up correctly and to modify its parameters such as its name (useful when your are using several modules), PIN code and communication speed (baudrate). To allow configuration, the module HC-06 should be powered but not paired (la LED is blinking).

The following code allows you to modify the parameters using the serial monitor.
#include <SoftwareSerial.h>
SoftwareSerial hc06(2,3);
void setup(){
//Initialize Serial Monitor
Serial.begin(9600);
Serial.println("ENTER AT Commands:");
//Initialize Bluetooth Serial Port
hc06.begin(9600);
}
void loop(){
//Write data from HC06 to Serial Monitor
if (hc06.available()){
Serial.write(hc06.read());
}
//Write from Serial Monitor to HC06
if (Serial.available()){
hc06.write(Serial.read());
}
}
To test serial communication, enter AT in the serial monitor and click on the send or press enter. Be sure to select “No end line” and the correct baudrate in the communication options. Module should answer OK. If it is not working check the wiring and the module version.

To modify the module name, enter AT+NAMEmodule_name.Module should answer OKsetname. (Ex: If you want to change module name into BTM1 enter AT+NAMEBTM1)
To modify the module PIN code, enter AT+PINxxxx. Module should answer OKsetPIN. (Ex: If you want to change PIN into 0000 enter AT+PIN0000)

To modify the module communication speed (only if required), enter AT+BAUDx. Ex: If you want to change baudrate into 9600 enter AT+BAUD4. Module should answer OK9600. (Note: 1 for 1200, 2 for 2400, 3 for 4800, 4 for 9600, 5 for 19200, 6 for 38400, 7 for 57600, 8 for 115200)

WARNING:Different versions of the Bluetooth module HC-06 exit and the list of AT commands may vary. Check the serial number written on the module and the firmware version by entering AT+VERSION.

For instance, the module HC-06 labelled ZS-040with firmware version 3.0-20170609 returns ERROR(0) when sending command AT+NAMExxxx (with xxxx the new name of the module). The AT commands to configure such module are:

  • AT+NAME=xxxx to set the name of the module
  • AT+PSWD:”xxxx” to set the pin code of the module

Do not hesitate to leave a comment if you encounter an issue while configuring your Bluetooth module HC-06.
The Programmer level java certifications offered by E-learning is the most recognized and popular certification in the IT market. The following are Java Programmer certifications offered by Oracle:
Oracle Certified Associate, Java SE 8 Programmer.