Receive Connection From HC-05

Hi. I want to ask for help on how I can receive the integer coming from arduino through HC-05 to the application.

the figure shows the integer I want to send to the application through HC-05

byte receivedData;

the figure shows the blocks for the connection to bluetooth

Dear @ChenBei,
there are sooooo (:grin:) many topics on the matter, that if you just do a quick search on the forum, you'll find for sure the solution to your problem.
Moreover there are the web sites of @Juan_Antonio (kio4.com) and of @ChrisWard (professorcad.co.uk) that contain a huge amout of "ready made" code that explains how to connect Arduino to AI2 by using the HC05 BT comm's.
Best wishes.

I already tried looking at some sources, sir, but I'm having trouble sending the desired data to the app. The condition is that the application should continuously receive data from an Arduino Uno using the HC-05 Bluetooth module, but the application cannot receive the desired data. The following are the picture of blocks I have used and the Arduino code set to send data from Arduino to the application.


Sorry for a lot of questions. I'm relatively new in this.

Dear @ChenBei, let me tell you some hints.

First of all, if you want a higher possibility to get help, do not post only chunks of your code, but the complete .aia and .ino so the P.Users can have a look to the entire code and try to find errors and solutions.
For example in your .ino you want to send initDist by using the Serial line: but is the Serial line connected to the HC05 ? on which pins ? Be careful that the Serial line ( the HW one) is normally used to connect the Arduino to the development system (the PC) and therefore it is better to use other pins to attach the HC05. To this purpose you shall use the SoftwareSerial library, and select a couple of pins accordingly: typically 2,3 or 10,11.
Have you crossed the Tx pin of the Arduino board toward the Rx pin of the HC05 and vice-versa?
Are you sure that the baudrate bwteeen Arduino and HC05 is set correctly ? 9600 ? 19200 ?
38400 ?
When tryinng to transmit on BT never use the delay() function because it completely blocks the Arduino CPU.
You have to write your own one:
void Delay(unsigned long Timeout)
{
unsigned long now = millis();
while ((millis()-now)< Timeout) ; // waits by doing nothing but leaving the CPU alive
}
The use is:
Delay(500); // delay 500 ms. Note the "D" that differs from "d"

Another doubt is: how fast is your clock 1 ? In order to avoid missing BT frames, its period shall be 1/2 of the transmitting period of your Arduino.

To split the problem in two parts, so to make it easier to find the solution, use the Serial Bluetoot Terminal app (free on playstore) to verify if and when your Arduino code is working fine (i.e. transmitting correctly) and after that you can then focus your efforts to your app.

In a nutshell: it's a long way and to get the target without getting crazy it's better to make one step at a time.

2 Likes

Forgive me for the negligence. Here's the entirety of the code sir for .ino and for the blocks.

This image is what I used for the connection of Bluetooth and the Codes I would send to Arduino via HC-05

This is my code for the connection between the ESP32 camera module and my main problem where I can't make the Serial.print(initDist) appear in Label3.Text.

The file attached here is my code for the movement of the rc car I'm making and the function where I want to send the value to app via HC-05. I'm also using the RX and TX of Arduino Uno, the digital pin 0 and 1 respectively.
project.ino (2.8 KB)
Bluetooth.aia (44.4 KB)

Your Clock Timer is enabled only by the Connect to WiFi button?


WiFi is not Bluetooth.

Better:

Your Clock Timer should not have a loop in it.

The whole point of a Clock Timer is to repeat over and over.

Also, the incoming text is in the result of the ReceiveText block, not the BytesAvailabletoReceive, which is just the buffer contents size.

Better:

Also, your Clock is too slow:
image

It should cycle a t twice as often as your sending code

  //This code is where I want to send the initDist value to appear on the application 
  if (countEnabled) {
    if (receivedData == 'F' || receivedData == 'R' || receivedData == 'L') {
      initDist += 1;
    } else if (receivedData == 'B' || receivedData == 'Z' || receivedData == 'X') {
      initDist -= 1;
    }

    Serial.print(initDist);
    Serial.println();
    delay(1000);
  }
}

So try
image

2 Likes

OK, first of all, before having such a complex .ino, try to send one simple character from Arduino to the phone or tablet (whichever is your Android device).
Be sure to have connected pin 0-Rx of Arduino Uno to the Tx pin of HC05 and pin 1-Tx of Arduino Uno to pin Rx of the HC05 (for the time being it will survive, though it's better to save the Rx pin of HC05 by using a voltage divider, but we will take care of that after we've solved the communication problems).
We suppose that the HC05 baudrate is effectively set @9600 => Serial.begin(9600);
I see that you wait until the number of bytes is -1 and accordingly you correctly use the .println() to close the sending from Arduino, but be sure to have set the delimiter byte in your app to 0x0A (i.e. 10 decimal) otherwise by waiting until -1 will cause the app to stuck forever.
How fast is your clock1 ? is it enough to catch all the transmission from the HC05 ?
Don't use the delay() and change it with the one I've suggested.
I agree, it seems I'm bothering you, but it's better to start with a supersimple Arduino code that sends only "Hello" to the app, and to use the Serial Bluetooth Terminal free app to verify if it works.
Until you aren't done with that, it's a waste f time to try to verify further things.

EDIT: I see that also @ABG has had a look into your .aia and he suggests also many other things. Please follow also his hints !

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.