Watch Video on Youtube: https://www.youtube.com/watch?v=ZdvKh3c_yoQ
| AT Command | REply from HC-06 | COMMENTs | 
|---|---|---|
| AT | OK | Used to verify communication | 
| AT+VERSION | OKlinvorV1.8 | The firmware version | 
| AT+NAMEmyBT | OKsetname | Sets the module name to “myBT” | 
| AT+PIN1234 | OKsetPIN | Sets the module PIN to 1234 | 
| AT+BAUD1 | OK1200 | Sets the baud rate to 1200 | 
| AT+BAUD2 | OK2400 | Sets the baud rate to 2400 | 
| AT+BAUD3 | OK4800 | Sets the baud rate to 4800 | 
| AT+BAUD4 | OK9600 | Sets the baud rate to 9600 | 
| AT+BAUD5 | OK19200 | Sets the baud rate to 19200 | 
| AT+BAUD6 | OK38400 | Sets the baud rate to 38400 | 
| AT+BAUD7 | OK57600 | Sets the baud rate to 57600 | 
| AT+BAUD8 | OK115200 | Sets the baud rate to 115200 | 
| AT+BAUD9 | OK230400 | Sets the baud rate to 230400 | 
| AT+BAUDA | OK460800 | Sets the baud rate to 460800 | 
| AT+BAUDB | OK921600 | Sets the baud rate to 921600 | 
| AT+BAUDC | OK1382400 | Sets the baud rate to 1382400 | 
|  | 
| Method 1 Setup | 
/*This sketch Configures the name and baud rate of an HC 06 Bluetooth module */
char message1[10];//need length of chars being read +1 for null character
char message2[9];
void setup() {
  // set baud rate then delay to give user time to open serial monitor
  Serial.begin(9600);
  delay(5000);
  //Send command to set name of HC06 module, with the below command name will change to "forcetronics"
  Serial.print("AT+NAMEForceT");
  delay(600); //HC06 requires 500 msec for reply
  int8_t count = 0; //declare and intialize count 
  while(1) { //loop until OKsetname is read and cleared from buffer
    if(Serial.available()) {
        message1[count] = Serial.read(); //read in char
        count++; 
        if(count == 9) break; //after we get all 9 char break out of loop
    }
    delay(10);
  }
  //Send AT command to change baud rate to 115200
  Serial.print("AT+BAUD8");
  delay(600); //HC06 requires 500 msec for reply
  count = 0; //intialize count
  while(1) { //loop until OK115200 is read and cleared from buffer
    if(Serial.available()) {
        message2[count] = Serial.read(); 
        count++; 
        if(count == 8) break; 
    }
    delay(10);
  }
  //print out each message to make sure it worked
  Serial.println("");
  Serial.println(message1);
  Serial.println(message2);
}
void loop() {
 //do nothing
  delay(50);
}
|  | 
| Method 2 Setup | 
//Example code for testing a serial bluetooth device using Arduino and a serial terminal on a computer
void setup() {
  // set baud rate to match BT module
  Serial.begin(115200);
}
void loop() {
  String t; //string to hold data from BT module 
  while(Serial.available()) { //keep reading bytes while they are still more in the buffer
    t += (char)Serial.read(); //read byte, convert to char, and append it to string
  }
  if(t.length()) { //if string is not empty do the following
    if(t == "Hi Uno\r\n") { Serial.print("Hello Neil\n"); } //say hello
    else if(t == "Meaning of life?\r\n") { //find out the meaning of life
      delay(1000);
      Serial.print("Money. ");
      delay(1000);
      Serial.print("Guns. ");
      delay(1000);
      Serial.print("Hoes.\n");
      delay(1000);
      Serial.print("Arduino.\n");
   }
   else { Serial.print("Syntax Error\n"); } //send this for any other string
  }
   delay(20);
}
 
Hi
ReplyDeleteGreat blog!
You said we could use the HC-06 straight out of the box: Besides the restorers why are we changing things? I am ashing because I am using an Uno as a led controller in an art work and I dont want to pull it apart each time I want to make changes ; this BT shield would be a big help!
Thanks
John