Problems with HC-05 module and Arduino Mega

Hi,

I am working on a car project controlled by a app, this app communicates with Arduino through the HC-05 module and I also use the dual H-bridge L298N module to control a DC motor. I did a sketch and everything worked without problems in Arduino Uno, however, in Arduino Mega I can't make the engines work.

Since the same sketch worked with Uno and not with Mega, I think the problem is not in the sketch but just in case the sketch will be at the end of the post. I was careful to make the pin connections at Mega, just like I did at Uno. I tested all the TX and RX pins that Mega has (0-1, 14-15, 16-17, 18-19) and tried different baud-rates in the sketch.

When I connect the app with Mega, the HC-05's blue LED flashes more slowly, indicating that it has connected with the cell phone. The Mega LED connected to the TX pin will flash in a certain order and will also flash when I activate any button I created in the app (maybe I'll try to make a video and post the link if it helps to better understand what I say).

My question is, where is the problem most likely? Would it be in Mega, in the app or in the HC-05 module? In the case of the tests I did changing the baud-rate, should I enter the AT mode of the HC-05 module and change over there, or is the change in the sketch enough?

I can post the library files that the app uses, I don't know what all the commands do but from what I researched everything is correct.

Materials used:

  • Arduino Mega 2560
  • HC-05 module
  • Dual H-bridge L298N
  • App -> Virtuino
  • OS -> Android

Edit: The sketch is too long and exceeds the maximum characters of the post.

When you have a long program just add the .ino file as an attachment.

Better still, make a shortened version of the program that illustrates the problem.

Please also post the working Uno version.

...R

Edit2: I attached a photo of the Arduino Uno, a photo of the Arduino Mega and my .ino file.

Thank you Robin2 for your attention and patience.

Teste_Main_Uno.ino (11.3 KB)

When you have a long program just add the .ino file as an attachment.

Better still, make a shortened version of the program that illustrates the problem.

Please also post the working Uno version.

...R

taito_magatsu:
My question is, where is the problem most likely? Would it be in Mega, in the app or in the HC-05 module? In the case of the tests I did changing the baud-rate, should I enter the AT mode of the HC-05 module and change over there, or is the change in the sketch enough?

The problem is most likely in the user understanding. There is nothing to suggest a hardware problem, particularly not in Bluetooth. While you are not likely to leave it that way, your code should be transferable without variation from Uno to Mega, so long as you connect Bluetooth to the same pins. Changing the baud rate in your sketch won't damage anything but it is a complete waste of time, unless you have configured Bluetooth with the baud rate to match, which is unlikely. I suggest you leave all the car stuff out for the moment, and just concentrate on Bluetooth. You can do this with a standard Android terminal, and thereby prove that you actually have a Bluetooth problem.

Nick_Pyner:
The problem is most likely in the user understanding. There is nothing to suggest a hardware problem, particularly not in Bluetooth. While you are not likely to leave it that way, your code should be transferable without variation from Uno to Mega, so long as you connect Bluetooth to the same pins. Changing the baud rate in your sketch won't damage anything but it is a complete waste of time, unless you have configured Bluetooth with the baud rate to match, which is unlikely. I suggest you leave all the car stuff out for the moment, and just concentrate on Bluetooth. You can do this with a standard Android terminal, and thereby prove that you actually have a Bluetooth problem.

Thanks for answering.

I thought that the baud rate would change in some way when connected to different hardware, but as you said, it was a complete waste of time since it must maintain a standard baud rate and I only change it via AT mode.

My guess is that the problem is either in the Mega card, app or (what I find most difficult) in the app's library. I tested two different Mega I have and none worked. I will follow your idea and do different tests with the bluetooth module but don't you think that, as it communicated with Uno via app, everything is fine with it?

taito_magatsu:
Edit2: I attached a photo of the Arduino Uno, a photo of the Arduino Mega and my .ino file.

I have an Uno and a Mega beside me on my workbench - I'm not sure what value another photo will provide?

I asked you to post the program that works on your Uno so I can compare it with the Mega program that does not work.

...R

OK, against better judgement, I have actually had a look at your code and the view is now clear. It won't work on Mega, and it should never have worked on the Uno in the first place. I stand by what I said before, but I did say "should", and I naively assumed that your code was kosher when run on Uno. It wasn't. You are trying to run software serial on the hardware serial pins 0,1. This is usually fatal and I will put your success with Uno down to luck. No damage done, though.

I suggest you:

  1. delete all references to software serial. Actually deleting the software serial library isn't such a bad idea - it just fosters bad habits.

  2. use serial3 commands as you have already tried, with Bluetooth on pins 14,15.

You may then find that it works, even with that other stuff I know nothing about.

Robin2:
I have an Uno and a Mega beside me on my workbench - I'm not sure what value another photo will provide?

I asked you to post the program that works on your Uno so I can compare it with the Mega program that does not work.

...R

The idea of ​​sending the photos of Uno and Mega was simply to show which card I am, anyway. I used the same program at Mega that worked at Uno, just being careful that in the IDE tools indicate the use of Mega.

Nick_Pyner:
OK, against better judgement, I have actually had a look at your code and the view is now clear. It won't work on Mega, and it should never have worked on the Uno in the first place. I stand by what I said before, but I did say "should", and I naively assumed that your code was kosher when run on Uno. It wasn't. You are trying to run software serial on the hardware serial pins 0,1. This is usually fatal and I will put your success with Uno down to luck. No damage done, though.

I suggest you:

  1. delete all references to software serial. Actually deleting the software serial library isn't such a bad idea - it just fosters bad habits.

  2. use serial3 commands as you have already tried, with Bluetooth on pins 14,15.

You may then find that it works, even with that other stuff I know nothing about.

If I understand correctly, my problem is in my understanding between using serial software or serial hardware. Just excluding the Softwareserial library and removing the lines that use references to it did not work. I'm researching to better understand the use of serial software and serial hardware.

In this case, I don't think that at Uno it worked by luck, it may be related to how the app I'm using communicates with the HC-05 module.

You were in doubt about what Virtuinobluetooth would be, this refers to the library of the app I'm using, it's an application ready to use with Arduino and offers an interface with buttons and other things that I can use.

taito_magatsu:
If I understand correctly, my problem is in my understanding between using serial software or serial hardware. Just excluding the Softwareserial library and removing the lines that use references to it did not work. I'm researching to better understand the use of serial software and serial hardware.

Well, you do need to replace them with relevant hardware serial commands, including

Serial3.begin(9600);.

Since you have a Mega, you can safely forget about software serial altogether. If you insist on using software serial on a Mega, you should not show your efforts to your mother.

In this case, I don't think that at Uno it worked by luck, it may be related to how the app I'm using communicates with the HC-05 module.

It was either (very) good luck, or you are lying. Communications between the app and HC-05 have nothing to do with communication between HC-05 and Arduino.

You were in doubt about what Virtuinobluetooth would be, this refers to the library of the app I'm using, it's an application ready to use with Arduino and offers an interface with buttons and other things that I can use.

I don't know anything about Virtuino. I suggest you leave it out of the game and just try saying hello to a standard Android terminal, thereby proving that Bluetooth is OK.

You might find the following background notes useful.