The EN (or any of the HC05 input pins) is not 5V compatible. Hopefully you did not damage the HC05 by connecting it to 5V.
Your improperly posted code is incomplete. Please read the forum guidelines* to see how to properly post code and some information on making a good post.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please go back and fix your original post.
Here is the method that I use to put my HC05 modules (labeled ZS-040) into AT mode and make changes to their setup. On some HC05 modules, pressing the button at start up will put the HC05 into a very limited ATmode. Connecting the EN pin to 3.3V and then powering the module puts it into full AT mode. These instructions have worked on all 6 HC05 modules that I have and at least 3 members modules that tried it.
This instruction is for the HC05 module marked ZS-040 connected to an Arduino Uno, Nano or any mega328 based board. Connect the HC05 as shown in the Martyn Currey page on AT mode for the HC05 (ZS-040). HC05 TX to Arduino pin 2 and HC05 RX to Arduino pin 3 (through voltage divider).
To change the baud rate you must first put the HC05 into AT mode. Do that by connecting the EN pin to 3.3V, NOT 5V. Then power up the Arduino board and HC05 module. The LED on the module should alternate lit for about 3 seconds and off about 3 second if it enters AT mode.
Upload the following code to the Arduino board.
// To enable AT mode connect the EN pin of the HC05
// to 3.3V. Caution, do not connect EN to 5V.
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
const long baudRate = 38400;
char c = ' ';
boolean NL = true;
void setup()
{
Serial.begin(38400);
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
BTserial.begin(baudRate);
Serial.print("BTserial started at ");
Serial.println(baudRate);
//BTserial.print("BTserial started at ");
//BTserial.println(baudRate);
Serial.println(" ");
}
void loop()
{
// Read from the Bluetooth module and send to the Arduino Serial Monitor
if (BTserial.available())
{
c = BTserial.read();
Serial.write(c);
}
// Read from the Serial Monitor and send to the Bluetooth module
if (Serial.available())
{
c = Serial.read();
BTserial.write(c);
// Echo the user input to the main window. The ">" character indicates the user entered text.
if (NL)
{
Serial.print(">");
NL = false;
}
Serial.write(c);
if (c == 10)
{
NL = true;
}
}
}
In serial monitor (baud rate set to 38400) you should see something like (the file directory and date will, of course, be a different):
Sketch: D:\bt_test_AT\bt_test_AT.ino
Uploaded: May 19 2022
BTserial started at 38400
Type "AT" (no quotes) and enter. You may see:
AT
ERROR:(0)
That is normal.
Type "AT" (no quotes) and enter again. Now you should see:
AT
OK
If that is what you see, the HC05 is in AT mode and ready to accept AT commands.
To set to baud 115200, enter "AT+UART=115200,0,0" (no quotes).
HC05 AT command list with examples.
More HC05 information by Martyn Currie.