My bluetooth was already connected but why the data from the coding not appear on mit apps?

hello, i want to design MIT app, basically, the data is from the sensor of my prototype mini project, and i used the Bluetooth HC05 to send the data from the sensor to the mit apps. the Bluetooth is connected but the data not come out to the screen, i dont know either my coding or the block was not correct, please help me as soon as possible because i want to present by prototype by this week, huhuhuhu..
btw, i used STM32duino for my coding.


(this is my block)

this is my coding set up
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>
#include <DHT.h>

// === LCD Setup ===
LiquidCrystal_I2C lcd(0x27, 16, 2);

// === DHT11 Setup ===
#define DHTPIN PC1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

// === Ultrasonic Pins ===
const int trig1 = PA0;
const int echo1 = PA1;
const int trig2 = PC10;
const int echo2 = PC11;
const int trig3 = PA6;
const int echo3 = PA7;

// === LED Pins ===
const int led_green = PB0;
const int led_red = PB1;

// === Servo & Button ===
const int servoPin = PB6;
const int buttonPin = PC0;

// === Buzzer ===
const int BUZZER_PIN = PC2;

// === Thresholds ===
const float TEMP_LOW = 10.0;
const float TEMP_HIGH = 40.0;
const float HUMID_LOW = 55.0;
const float HUMID_HIGH = 90.0;

// === Variables ===
Servo myservo;
bool doorOpened = false;
bool lastButtonState = HIGH;
float distance1, distance2, distance3;

// === Custom Characters (✓ and ✗) ===
byte checkmark[8] = {
0b00000,
0b00001,
0b00010,
0b10100,
0b01000,
0b00000,
0b00000,
0b00000
};

byte cross[8] = {
0b00000,
0b10001,
0b01010,
0b00100,
0b01010,
0b10001,
0b00000,
0b00000
};

// === HC-05 via UART2 ===
HardwareSerial &BTSerial = Serial2;

void setup() {
Serial.begin(9600); // Debug ke PC (USB)
BTSerial.begin(9600); // HC-05 via Serial2 (PA2=TX, PA3=RX)

// LCD
lcd.init();
lcd.backlight();
lcd.createChar(0, checkmark); // ✓
lcd.createChar(1, cross); // ✗

// DHT11
dht.begin();

pinMode(trig1, OUTPUT); pinMode(echo1, INPUT);
pinMode(trig2, OUTPUT); pinMode(echo2, INPUT);
pinMode(trig3, OUTPUT); pinMode(echo3, INPUT);

// LED setup
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);

// Servo & button
myservo.attach(servoPin);
pinMode(buttonPin, INPUT_PULLUP);
myservo.write(0); // start closed

// Buzzer
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW);
}

float getDistance(int trigPin, int echoPin) {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
long duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) return 999;
return (duration * 0.034) / 2;
}

void buzzWarning() {
for (int i = 0; i < 3; i++) {
digitalWrite(BUZZER_PIN, HIGH);
delay(200);
digitalWrite(BUZZER_PIN, LOW);
delay(200);
}
}

void loop() {

distance1 = getDistance(trig1, echo1);
distance2 = getDistance(trig2, echo2);
distance3 = getDistance(trig3, echo3);

// === LED logic ===
bool isEmpty = (distance1 > 5 && distance2 > 5 && distance3 > 5);
digitalWrite(led_green, !isEmpty);
digitalWrite(led_red, isEmpty);

// === Button buka/tutup servo ===
bool currentButtonState = digitalRead(buttonPin);
if (lastButtonState == HIGH && currentButtonState == LOW) {
doorOpened = !doorOpened;
myservo.write(doorOpened ? 90 : 0);
delay(100);
}
lastButtonState = currentButtonState;

// === Baca suhu & kelembapan ===
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();

if (!isnan(temperature) && !isnan(humidity)) {
bool tempAlert = (temperature < TEMP_LOW || temperature > TEMP_HIGH);
bool humidAlert = (humidity < HUMID_LOW || humidity > HUMID_HIGH);

if (tempAlert || humidAlert) {
  buzzWarning();
} else {
  digitalWrite(BUZZER_PIN, LOW);
}

// === Hantar data ke HC-05 (Bluetooth) ===
BTSerial.println(String(temperature,1) + "," +String(humidity,1) + "," +(isEmpty ? "EMPTY" : "AVAILABLE"));


Serial.print("TEMP: ");
Serial.print(temperature);
Serial.print("C, HUMID: ");
Serial.print(humidity);
Serial.print("%, STATUS: ");
Serial.println(isEmpty ? "EMPTY" : "AVAILABLE");

} else {
Serial.println(":x: Gagal baca sensor DHT!");
}

// === Papar ke LCD ===
lcd.clear();
if (isEmpty) {
lcd.setCursor(0, 0); lcd.print("no food");
lcd.setCursor(0, 1); lcd.print("right now");
} else {
lcd.setCursor(0, 0); lcd.print("please serve yourself");
lcd.setCursor(0, 1);
lcd.print(" B1:"); lcd.write(distance1 < 5 ? 0 : 1);
lcd.print(" B2:"); lcd.write(distance2 < 5 ? 0 : 1);
lcd.print(" B3:"); lcd.write(distance3 < 5 ? 0 : 1);
}

delay(1000);
}

Here is an updated blocks sample illustrating these ideas ...

BlueTooth_delimiter_sample.aia (3.4 KB) global message

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.

In addition to ALL that @ABG has already said, particularly to the BT receiving text method, in your app's code there are several things to correct:

image
The red circled block is useless at that point, therefore the whole "if" statement can be removed and you can just leave the Bluetooth .Connect and assign its result to a boolean variable, for example, like this:

More, here:
image
You can do like this:
image

These two comparisons will never be true because of the AND.
The value cannot be less then 10 AND contemporary greater than 40, therefore if your aim is to detect a value outside those limits, you shall use to OR block instead.

The same applies to the AND below
image

Other things can be improved but, let's go step by step...
Best wishes for your project.

PS I havent had a look to your Arduino code, yet, therefore I assume it is working fine. To be confident that the Arduino part is working, you can use on your Android device a very powerful app: Serial Bluetooth Terminal, that you can download free from google playstore.
Give it a try.

EDIT:
The clock1 can be rewritten like below:

1 Like