How to Send AT Commands to Bluetooth while it's Linked to another Device

I have my bluetooth HC-05 linked to my android smartphone and I want to change the bluetooth PIN number via an app. The problem is I need to use AT commands to reset the PIN, but the AT commands I send to the bluetooth just goes through to the smartphone and displays there.

Is there any way to send AT commands while the bluetooth is linked? Or is there any way to disconnect the bluetooth digitally without AT commands? Or just any other suggestions are welcome.

To program the HC-05, you need to put it in command mode. This is usually done by connecting the key pin to 3.3V during power up of the HC-05. Some HC-05 modules have a button you press during power up to do this. Once it is in command mode, it is waiting for AT commands to be entered at 38400 baud, with line feed and carriage return for each command line.

dmjlambert:
To program the HC-05, you need to put it in command mode. This is usually done by connecting the key pin to 3.3V during power up of the HC-05. Some HC-05 modules have a button you press during power up to do this. Once it is in command mode, it is waiting for AT commands to be entered at 38400 baud, with line feed and carriage return for each command line.

Further to this. Excerpt from a manual...

Entering Command Mode

EGBT-045MS is put in Command Mode by setting
the CMD pin to logic High. There is one important
point the user should be aware of when setting the
device in Command Mode – the baud rate may as-
sume a different value depending on the instance
the CMD pin is switched to high:
• If EGBT-045MS is powered ON with CMD pin to
+Vcc, the UART is set to 38400bps, 8 data bits, 1
stop bit, no parity, no handshake.
• If the EGBT-045MS is powered ON with the CMD
pin at logic low (or open circuit), and then pulled
High a moment later, the UART parameters as-
sumes a set of values that was previously fixed
using the AT+UART command, with 9600bps, 8
data bits, 1 stop bit, no parity, and no handshake as
default parameter values.

Peppermint:
I have my bluetooth HC-05 linked to my android smartphone and I want to change the bluetooth PIN number via an app. The problem is I need to use AT commands to reset the PIN, but the AT commands I send to the bluetooth just goes through to the smartphone and displays there.

Is there any way to send AT commands while the bluetooth is linked? Or just any other suggestions are welcome.

I think you can take all of the above as a simple "no". I believe you could break the connection and then reprogramme the HC-05 by the simple expedient of having the Key pin under software control. This latter should not be difficult with a plain vanilla JY-MCU board, but it might be fiddly with the newer boards that have a button switch on them. Because of this, I am beginning to think the ZS-040 etc. are not such a good idea.

Or is there any way to disconnect the bluetooth digitally without AT commands?

I think you could. You could power the module off a high pin and switch it off by sending a signal that makes that pin low.