Bluetooth Send crashes when triggered by Clock

Dear community,

unfortunately I have to ask for your wise words again. After days of trying to solve the problem on my own, I can now say what exactly thew problem is, at least: It seems that whenever the BluetoothClient Send Text is triggered by a clock it tends to crash (app freezes and bluetooth connection gets lost) after running for a while. No matter if executed via companion or built version.

Attached you can find an excerpt of my code including when ClockClicktrack Timer which basically is a for-loop with varying wait commands according to this method (Multiple wait commands in one project - #5 by ChrisWard) that triggers Bluetooth Sends every now and then. As well as when ButtonBlack Click which triggers just the same Bluetooth Sends, but manually.

I did quite a lot of troubleshooting with this problem so I was able narrow down the issue. I now know it's not a general bluetooth connection problem, it's not the clock based for loop that's not working correctly, it's not a problem that a wrong character is sent, ... everything seems to be nice and clean. I can manually trigger the Bluetooth Sends as often as I like, no matter how fast, everything is fine, but the same command triggerd by a clock will cause the app to irregularly crash after 2-3 repetitions of the clock based for-loop like shown in this example.

I also tried to move the Bluetooth Send command out of this particular clock based for-loop into a procedure, or into another clock based trigger but without any success. Sorry for describing my problem so extensively and as always I'm very thankful for any advance!

Many thanks!

Well you have not followed my example - you do not need more than one BT Client and I think that is where the issues are probably born.

Hi Chris,

thanks for your quick response. Unfortunately I need four clients for four Bluettoth devices (HC-05) that are paired and connected at the same time. I might be wrong and there is a way to send different Bluetooth signals to multiple devices with only only Bluetooth Client?

But anyway, that's a source of error I was also able to eliminate as the same problem occurs when everything is cut down to only one Bluetooth client. Furthermore the four parallel clients work just fine when they are triggered manually.


We would need to see your microcontroller scripts/sketches.

The issue is, your phone does not have four separate Bluetooth Channels, so you can't send signals to four devices at the same time?

Describe your project to us - what exactly are you trying to do? What are the four individual devices?

Of course, the whole setup is quickly explained. The four devices are identical stagelights for live concerts, each containing a HC-05 bluetooth module, an Arduino Uno, a power supply and 264 LEDs.

Even though the phone might not be able to send it exact the same time, the occuring delay is not noticable and never caused any inference. I've been using this method now for the last two years and it was stable.

Attached you can find a excerpt of the Arduino Code. Although the whole code contains lots of functions for various light effects, I reduced it to the the necessary lines for the testing example shown in my post - switching bewteen two colors. Regarding the Arduino code, do you think that the serial.print command, sending something back once the Bluetooth signal is received, could cause the error? For testing purpose I waived any Bluetooth receive commands in this app inventor project. Could it still be a problem?

The improvement I wanted to achieve with adding this clock based for-loop is that the change of light effects doesn't have to be triggered manually but via a preprogrammed sequence of events with a mp3 clicktrack for the drummer being played simulaniously.

Again many thanks Chris for digging into this topic!


I see a conflict in your use of the global variable CMD_List.

It is supposed to be a table(list of lists), but at several places you set it to a blank text.

That will cause all attempts to take length of list on it to fail.

The proper value to give it is create empty list.

1 Like

Very likely - it could occur just as a signal is sent by the phone, so unless it is vital to get a signal from an UNO, I would avoid it.


That's also something I've already tried without getting any better results. Even though I only tried it while playing around - as you are sure about what you are doing, I'll still change them back to creaty empty list. Many thanks!


HI Chris,

not vital but comfortable, anyway for the sake of solving this problem I'll continue without sending responses from the UNOs. Thanks! This might take some days but I'll keep you updated!


I double checked, and got confirmation with a little test:
length of list blank

Hi Chris,

it's working now. I removed every Serial.print in the Arduino script. Seems there was a timing problem in the bluetooth serial and the Arduinos answer caused the bluettoh send command in AI2 to crash irregularly. Still it's very strange that this problem only occured when triggered automatically. Anyway, many thanks, I'm just glad it works now!