HC-05 arduino can't read serial monitor with MIT App Inventor

Hey, I'm doing a project for school that basically consists on a HC-05 as well as a SR-HC04 connected to an Arduino UNO Rev4. The SR-HC04 (proximity sensor) prints the distance in the serial monitor I can connect the HC-05 with MIT App Inventor. The thing is that I don't seem to find the way for printing the serial monitor in the MIT App that I made.
Any help with this would be greatly appreciated! Will provide any other information and details that may be needed.
For now, I'll show what i have:
Arduino's code:
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
#define Pecho 6
#define Ptrig 7
float duracion, distancia;

void setup() {
Serial.begin(9600);
BTSerial.begin(9600);
pinMode(Pecho, INPUT);
pinMode(Ptrig, OUTPUT);
pinMode(13, 1);
}

void loop() {
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}

if (Serial.available()) {
BTSerial.write(Serial.read());
}

digitalWrite(Ptrig, LOW);
delayMicroseconds(2);
digitalWrite(Ptrig, HIGH);
delayMicroseconds(10);
digitalWrite(Ptrig, LOW);

duracion = pulseIn(Pecho, HIGH);
distancia = (duracion/2) / 29;

if (distancia >= 500 || distancia <= 0){
Serial.println("---");
}
else {
Serial.print(distancia);
Serial.println("cm");
digitalWrite(13, 0);
digitalWrite(4, 1);
}
delay(800);

}

MIT App Inventor:
Designer part:


image

Blocks part:

Hi Pere

You need to use the Bluetooth Blocks for your App :slight_smile:

Here is a simple example file. Depending on your version of Android, you may need to add some permissions.

BT_Basic_Setup_Receive_two_vals.aia (7.7 KB)

I really appreciate your answer but I'm not able to open it so if you could send a picture of the blocks, etc. would be awesome!
Thanks though!

Here is a simple BlueTooth text receiver sample, for single value per line:
blocks
initialize global message to


Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

I tried it in MIT App Inventor and it didn't work, but the code that you gave me for the blocks part is not the problem. I've just made a label that prints a message if the MIT App don't receive anything, and fortunately, that is the case.
So now I (think) found the issue, it has to be the arduino's programation as I don't receive anything in MIT.
I didn't really understand what you were talking about in the Arduino's part (as I'm a beginner [I really apologise]), however I'm going to show you my arduino's code and also the MIT part so you can check if there's something wrong in any of the two codes.


image
(I also checked what you told me about the clock)

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(2, 3);
#define Pecho 6
#define Ptrig 7
float duracion, distancia; 

void setup() {
  Serial.begin(9600);
  BTSerial.begin(9600);
  pinMode(Pecho, INPUT);     
  pinMode(Ptrig, OUTPUT);
  pinMode(2, INPUT);               
}

void loop() {
  if (BTSerial.available()) {
    Serial.write(BTSerial.read());
  }

  if (Serial.available()) {
    BTSerial.write(Serial.read());
  }

  digitalWrite(Ptrig, LOW);
  delayMicroseconds(2);
  digitalWrite(Ptrig, HIGH);   
  delayMicroseconds(10);
  digitalWrite(Ptrig, LOW);
  
  duracion = pulseIn(Pecho, HIGH);
  distancia = (duracion/2) / 29;            
  
  if (distancia >= 500 || distancia <= 0){   
    Serial.println("---");                  
  }
  else {
    Serial.println(distancia);                                     
    digitalWrite(4, 1);
    digitalWrite(2, 1); 
  } 
  delay(1000);                                

}

I think it has something to do with the void setuo where I should program that one of the pins has to send data and not only be connected or something like that.
I'm really a beginner so I am probably completely wrong xd
Thanks for your time though, I really appreciate your 24/7 help