Pairing/Linking HC-05 Blueooth modules

I’ve run into a point of confusion in a project that I’m hoping someone here can help me figure out. Everything is technically working, but I’m confused by the results.

Here’s the setup: I have an Arduino Nano connected to an HC-05 Bluetooth transciever (set as master), and an Arduino Micro connected to another HC-05 transciever (set as slave). Using this basic code that is widely available on the Google, I can easily get the two into AT mode and do all kinds of neat things:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup()
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);  // HC-05 default speed in AT command more

void loop()

  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())

The problem is that I’m confused about the proper sequence of events to pair the two modules. The first time I did this, I used AT+INQ to find the slave’s address and then AT+LINK to pair the two. From that point on, whatever I typed into the COM monitor of one Ardunio popped up on the COM monitor of the other side. Swell! But later, when I reset either Arduino, I couldn’t get consistently get back to that place.

Sometimes the Arduinos/HC-05s would come up in ‘Intialized’ state. Sometimes one would come up as ‘Connected’ and the other as ‘Inquiring’. Sometimes they would come up both showing connected, but I couldn’t send data back and forth. Sometimes one would show up as ‘Pairing’. It seems like o matter what sequence of commands I would try (AT+CMODE=1 then AT+INIT then AT+LINK being most common), I couldn’t get consistently back to the point where I could send data back and forth.

So, here are my questions:

  1. Is there a standard issue series of commands for getting my master to search for and connect to the nearby slave, so that the two can send data back and forth?

  2. Once I’m in that mode, how can I exit back out without having to reset the Arduino?

  3. is there a reliable way to get my slave module to forget the master module? I tried using AT+RMAAD and it would temporarily forget the master module, but if I reset the Arduino it would go right back to trying to connect to the master module and reported it’s address in its pairing table. I’d prefer for it to be ‘clean’ each time I powered on the Arduino, and only pair with the master when the master finds it/links with it.

Thanks! Hope at least some of that made sense.