I cant figure out the problem, arduino uno3,bluetooth hc-06,flexibility sensor and a FSR

im building a project for school and im using arduino uno3,bluetooth hc-06,flexibility sensor and a FSR pressure sensor.
i want the app to show me if something is detected or not but it shows me the information only in one lane.
in the serial monitor everything is working fine but in the app isnt.
so the problem is only in the mit app not in the code itself...i think so

Here is the code:

int fsrAnalogPin = 1;
int fsrReading;
int force = 0;

int flex = A0;
int data = 0;
int flexReading = 0;

void setup(void) {
pinMode(SensorPin, INPUT);
pinMode(flex, INPUT);

void loop(void){
fsrReading = analogRead(fsrAnalogPin);
if(fsrReading > 1) {
force = 1;
Serial.print("Force detected");
else {
force = 0;
data = analogRead(flex);
if( data >= 250)
flexReading = 0;
flexReading = 1;
Serial.print("flexibility detected");

You are not taking advantage of the println() in the ai2 app.
Here is the standard technique ...

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. 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.
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:

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.

1 Like