JMYCU Bluetooth units, HC05 and HC06 Part 3 – linking two Arduino’s 

Part 1 setting up the HC06 Slave Bluetooth unit is here.

Part 2. Setting up the HC05 Master/Slave unit is here.

The Universal Bluetooth Receiver with LCD display is here.

Important note: if the Key pin on the HC05 is HIGH when the power is connected it will enter th AT Mode using a baud rate of 38400. As the Slave is set at 9600 baud this presents problems. However, if the Key pin is taken HIGH after power is applied the baud rate is unchanged. In the sketch used here the Key pin is connected to Arduino pin 4. This pin is taken HIGH shortly after power is applied. The HC05 will enter AT mode at 9600 baud rate and is set as a Master Unit, then paired with the HC06. The Key pin can be left HIGH and still the HC05 will be able to communicate with the HC06 as long as the Key pin was taken high after the power was applied.

Once the two Bluetooth units are working the next thing is to link the Master with the Slave. It is useful to use the Universal Bluetooth Receiver with LCD display and the link for this is shown above. 

We now need to apply power to the Arduino/Slave then load the next sketch into the Arduino/Master unit, this will allow AT commands to be sent to the HC05.

With both Arduinos powered On type the following commands into the Serial Monitor connected to th Master make sure NL/CR has been selected.

AT+INIT (only do this once , after applying the power)
AT+INQM=0,9,30 (this will search for up to nine Bluetooth units)
AT+ROLE=1 (sets the HC05 as a master, it will not search unless this is done)
AT+INQ (prints out the address of nearby Bluetooth units)

The bluetooth addresses of nearby units will now be displayed. The address is the first three groups separated by a comma, there are two other groups of numbers.

My HC06 gave 13,1B,412154 as the address.

Once you have identified the HC06 on the Slave Arduino type

AT+LINK=13,1B,412154 (inset your address here)

to link to the HC06. Remember to make sure LF and CR are selected in the serial monitor, or send \r\n with each command. Once linked the LED on the HC06 will stop flashing and remain lit.

// HC05 Master connects to HC06 Slave
// On first running the Bluetooth module is reaset to factory settings then the speed is set to 9600
// Connect RX from the HC05 to pin 2 on the Arduino.
// Connect TX from the HC05 to pin 3 on the Arduino

// to send AT commands KEY is connected to Vcc
// after power is connected, to keep the baud rate at 9600
// by controling the Key pin with Arduino pin 4
// Switch the power on
// Open up the Serial Port Monitor
// Type in AT and click on the SEND button, OK will be printed in the monitor
// showing that the module is receiving commands.

#include <softwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define keyPin 4 // connects to HC05 KEY
String buildString = ""; // Stores response of bluetooth device
// which simply allows \n between each response.

void setup()
// Open serial communications and wait for port to open:
// Hardware Serial port set to 9600
// SoftwareSerial "com port" data rate. 38400.
mySerial.begin(9600); // default speed in AT mode
pinMode(keyPin, OUTPUT);
digitalWrite(keyPin, LOW); // puts HC05 into communication mode
digitalWrite(keyPin, HIGH); // put HC05 into AT mode
// reset bluetooth module to factory settings
// Note: the delay blocks are necessary to allow the commands to take place

// this will take about 25 seconds to link up with HC06
Serial.println("Initialising this will take about 25 seconds...");
Serial.println("HC-05 set as a Master, trying to connect to slave");

void loop() {

As far as I can determine the HC05 in Master mode will only connect with an HC06. The TinyOS Bluetooth Shield uses an HC05 ( see this post here) and so will also connect with an HC 06 and can use all of the code shown above.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: