HC-05 connected to Mega

Hello, I’m building a bigger project (robot). Week ago I bought an HC-05 module. I followed a few tutorials, wrote some successful codes which worked on Arduino UNO. When I connected HC-05 on Arduino Mega it only showed “?”. I created my own app using MIT App Inventor. I tried to use it together with Arduino Uno where it worked. When I tried to use it for Arduino Mega it didn’t. Data were sent and received by Arduino Mega but not recognized. Can you help me someone with it, please? Do you know where the problem can be?

bluetooth_test.ino (489 Bytes)

robot_podvozok_mobil.ino (3.84 KB)

Please post short programs in your Post so we don't have to download them - like this

char Incoming_value = 0;
                
void setup() 
{
  Serial.begin(9600);         
  pinMode(13, OUTPUT);       
}

void loop()
{
  if(Serial.available() > 0)  
  {
    Incoming_value = Serial.read();      
    Serial.print(Incoming_value);        
    Serial.print("\n");        
    if(Incoming_value == '1')             
      digitalWrite(13, HIGH);  
    else if(Incoming_value == '0')       
      digitalWrite(13, LOW);
  }                            
}

Also please make your images visible in your Post - like this. See this Simple Image Posting Guide

...R

If you are using a Mega you should connect the HC05 to pins 19 and 18 (Rx1 and Tx1) and use Serial1 to communicate with it. Remember that Tx on the HC05 should connect to Rx1 on the Mega and Rx to Tx1. You also need a GND connection

Something like this ...

void loop()
{
  if(Serial1.available() > 0)  // reading from Serial1
  {
    Incoming_value = Serial.read();      
    Serial.print(Incoming_value);        // sending output to Serial
    Serial.print("\n");        
    if(Incoming_value == '1')             
      digitalWrite(13, HIGH);  
    else if(Incoming_value == '0')       
      digitalWrite(13, LOW);
  }                            
}

And please don't post pictures of text. Just copy and paste the text.

...R