HC-05 Bluetooth Module Renaming

Connection Diagram

Connection Diagram

WIRING

HC-05 GND --- Arduino GND Pin
HC-05 VCC (5V) --- Arduino 5V
HC-05 TX --- Arduino Pin 10 (soft RX)
HC-05 RX --- Arduino Pin11 (soft TX)
HC-05 Key (PIN 34) --- Arduino Pin 9

Arduino Code

#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.begin(9600);
  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())
    Serial.write(BTSerial.read());

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

STEPS

  1. Do connection as per diagram.
  2. Burn the above code to arduino.
  3. Open Arduino serial monitor.
  4. Select Both NL & CR option right-bottom part of serial monitor.
  5. Type AT+ROLE=1 and press send, It will return OK on success.
  6. Type AT+NAME=newname to change device name.
  7. Type AT+NAME? to test device name.
  8. Type AT+ROLE=0 to change to slave mode again.
  9. Done.

NOTE: If you use AT+ORGL command, your bluetooth module will restore to default settings, so the baud rate, device name, password all will reset. The baud rate of most of modules are 34800. So after resetting to default config, you should use 34800 as baud rate in your Arduino code instead of 9600.

Reference: