Skip to content

Instantly share code, notes, and snippets.

@garrows
Last active September 23, 2025 14:05
Show Gist options
  • Save garrows/f8f787dac6e85591737c to your computer and use it in GitHub Desktop.
Save garrows/f8f787dac6e85591737c to your computer and use it in GitHub Desktop.

Revisions

  1. garrows revised this gist May 2, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions SetupBluetooth.ino
    Original file line number Diff line number Diff line change
    @@ -42,6 +42,9 @@ SoftwareSerial mySerial(10, 11); // RX, TX
    void setup()
    {
    Serial.begin(9600);
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
    }
    Serial.println("Starting config");
    mySerial.begin(BLUETOOTH_SPEED);
    delay(1000);
  2. garrows renamed this gist May 2, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. garrows created this gist May 2, 2014.
    81 changes: 81 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,81 @@
    /*

    This is for configuring the hc-06 bluetooth chip to work with Johnny-Five javascript robotics library.
    Might also work with the hc-05.

    Author: Glen Arrowsmith (@garrows)

    */

    #define ROBOT_NAME "RandomBot"

    // If you haven't configured your device before use this
    #define BLUETOOTH_SPEED 9600
    // If you are modifying your existing configuration, use this:
    // #define BLUETOOTH_SPEED 57600

    #include <SoftwareSerial.h>

    // Swap RX/TX connections on bluetooth chip
    // Pin 10 --> Bluetooth TX
    // Pin 11 --> Bluetooth RX
    SoftwareSerial mySerial(10, 11); // RX, TX


    /*
    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
    */


    void setup()
    {
    Serial.begin(9600);
    Serial.println("Starting config");
    mySerial.begin(BLUETOOTH_SPEED);
    delay(1000);

    // Should respond with OK
    mySerial.print("AT");
    waitForResponse();

    // Should respond with its version
    mySerial.print("AT+VERSION");
    waitForResponse();

    // Set pin to 0000
    mySerial.print("AT+PIN0000");
    waitForResponse();

    // Set the name to ROBOT_NAME
    mySerial.print("AT+NAME");
    mySerial.print(ROBOT_NAME);
    waitForResponse();

    // Set baudrate to 57600
    mySerial.print("AT+BAUD7");
    waitForResponse();

    Serial.println("Done!");
    }

    void waitForResponse() {
    delay(1000);
    while (mySerial.available()) {
    Serial.write(mySerial.read());
    }
    Serial.write("\n");
    }

    void loop() {}