Arduino MEGA with HC-05 doesn't apply AT commands or print anything

I'm trying to establish a commands connection between Android & Arduino. The idea is a basic project. It receives commands from Android and sends commands to Android via Bluetooth.

Parts:

  • Arduino MEGA
  • Bluetooth HC-05

I have an L293D Motor shield, therefore, I'm connecting the TX & RX into the TX1 and RX1. The 5v & Ground are connected.

I'm doing a long press on the HC-05 while connecting the Arduino to the PC. Then, I'm trying to establish a normal connection and trying to apply AT commands, such as changing the name of the Bluetooth connection.

When I write any AT command, I don't get any output back. When I send anything from Android, it does not get printed. (Previous code had Serial1.print and Serial.print to see the output, in this code I removed this)

What's the issue with my approach?

Code:

void setup() {
   Serial.begin(9600);
   Serial1.begin(38400);
}

void loop() {

 
   if(Serial1.available()){
    int inByte = Serial1.read();
    Serial.write(inByte);
    
   }

   if(Serial.available()){
    int inByte = Serial.read();
    Serial1.write(inByte);
   
   }
}
Serial1.begin(38400);

The default baud rate on my HC05 modules for serial communication is 9600. 38400 is the baud rate to talk to the HC05 when the HC05 is in AT mode. Enter AT mode by holding the tiny push button while powering the HC05 up.

Here is a handy utility to configure an HC05. It requires one to connect the HC05 to a PC with a USB to TTL serial adapter (FTDI), though.

JaegerDE:
therefore, I'm connecting the TX & RX into the TX1 and RX1. The 5v & Ground are connected.

No. Tx>Rx1 and Rx>Tx1. Transmitters transmit to receivers.

Then, I'm trying to establish a normal connection and trying to apply AT commands

Make up your mind about what you want to do - communicate or configure. You can't do both at the same time. Press the button only if you want to configure Bluetooth.

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

There is some reference in the appendix that specifically applies to Mega.