My app freeze when I connect to the HC-06 Bluetooth Module

So, I’m trying to control a Arduino Mega2560 robot with the accelerometer, connecting with the HC bluetooth module(HC-06). But the thing is, when I connect my app just stop and freeze, and I have to restart the fone… don’t know what’s going on.Acelerometro.aia (17.0 KB)

It would help to also post your Arduino code, just in case.
In the meantime, let’s assume the Accelerometer events are coming too fast for the BlueTooth component to send your X,Y data.
Here are some suggested revisions, you can drag directly into your blocks …
TimerBT when AccelerometerSensor1 AccelerationChanged


I included your Clock settings for show, and I added some field and message delimiters to help your Arduino separate the X and Y values.

Thank you for the tip, I'll try this changes. Here's the arduino code, the motors are connected by L298N. Thanks again for the help.

#include <SoftwareSerial.h>
SoftwareSerial bluetooth(10, 11);// 10-RX 11-TX

#define motor1 22;//esquerdo
#define motor2 23;//direito
#define Motor_1 24;//motor esquerdo(ré)
#define Motor_2 25;//motor direito(ré)
int eixoX, eixoY;//dados do acelerômetro

void setup()
{
pinMode(22, OUTPUT);
pinMode(23, OUTPUT);
pinMode(24, OUTPUT);
pinMode(25, OUTPUT);

bluetooth.begin(38400);
Serial.begin(38400);
}

void loop()
{
char r = bluetooth.read();
//delay(100);
//Serial.println(r);
//delay(100);
while (bluetooth.available() > 0)
{
eixoX = bluetooth.read();
delay(10);
eixoY = bluetooth.read();
}
delay(10);
if (bluetooth.available() != 0)
{
if (r == 'A')//anda para frente
{
digitalWrite(22, HIGH);
digitalWrite(23, HIGH);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
delay(2000);
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
if (r == 'B')//anda para trás
{
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, HIGH);
digitalWrite(25, HIGH);
delay(2000);
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
if (r == 'C')// vira a direita
{
digitalWrite(22, HIGH);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
delay(300);
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
if (r == 'D')// vira a esquerda
{
digitalWrite(22, LOW);
digitalWrite(23, HIGH);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
delay(300);
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
if (r == 'S')//interrompe o motor
{
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
}
else if (bluetooth.available() == 0)//evitar o acionamento do motor
{
digitalWrite(22, LOW);
digitalWrite(23, LOW);
digitalWrite(24, LOW);
digitalWrite(25, LOW);
}
}

void loop()
{
char r = bluetooth.read();
//delay(100);
//Serial.println®;
//delay(100);
while (bluetooth.available() > 0)
{
eixoX = bluetooth.read();
delay(10);
eixoY = bluetooth.read();
}

You will definitely have problems getting your X and Y values in the Arduino in the proper format and keeping them straight.

Look through the samples at FAQ Section: Bluetooth < version 4 (BlueTooth Client) and Arduino and see how multiple values are sent and converted from text to int.

Timing is a poor way to separate values, compared to text delimiter techniques.