I'm trying to send the readings of 3 sensors simultaneously to my Android phone on an app I made using MIT App Inventor 2 via the HC-05 bluetooth module.

For this, I'm sending a string like "20.067, 58.234, 12 |" where the "," allows the splitting of the text and "|" acts as a delimiter to tell the app that the whole string has reached it.

The problem I'm facing is that after a while(which varies from 2 seconds to a few minutes), the readings just stop and the app stops responding (ie; touching any butons on the app does nothing). However, this is a non-issue when I'm not using Bluetooth at all and just printing to the Serial Monitor.

To find the cause, I tried the following things:

  1. Sent text to the module via the normal Serial.print() function so that I can see it on my PC and my app at the same time. Strangely, after the readings stopped (on the serial monitor as well), as soon as I closed the Serial Monitor and opened it again, the readings were back and again stopped after a while.

  2. I used the SoftwareSerial.h library to define a different pair of RX/TX pins to send the text to the module and the serial monitor separately. This time, when the readings stopped, restarting the serial monitor had no effect.

I'm not exactly sure how to interpret these outcomes but it leads me to believe the problem lies in the serial communication.

Additional information:

  • The baud rate is set to 115200
  • I'm sending a string every 500ms and the app clock fires every 100ms

This is a screenshot of the codeblock on MIA 2: enter image description here

This is the relevant portion of the Arduino sketch. The rest of it just calculates the variables being printed

  // Sensor 1 data
  Serial.print(" X = ");
  Serial.print(" Y = ");
  Serial.print(" Z = ");

  // Sensor 2 data
  Serial.print(" X = ");
  Serial.print(" Y = ");
  Serial.print(" Z = ");

  // Sensor 3 data
  looper = millis();
  • 1
    opening Serial Monitor resets the Arduino. do you use String class? show the Arduino sketch – Juraj Jun 29 '19 at 11:50
  • Thanks, I didn't know that. That explains why it starts working again, but I still need to know why it stops in the first place. I've included the sketch as you said. – TEC0001 Jun 29 '19 at 15:12
  • the problem is not in this part of the sketch – Juraj Jun 29 '19 at 15:33
  • The rest of it is just maths, I don't know where else the problem could be – TEC0001 Jun 29 '19 at 18:32
  • 1
    you need to determine the location of the failure .... reduce your arduino loop() code to a single line that sends a fixed string like "20.067, 58.234, 12 |" and pauses 500ms ..... do not do any sensor reading, no interrupt handling, nothing more than minimal code that communicates with the android device – jsotola Jun 29 '19 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.