Receive data to the phone via arduino

Hello, I've got a problem regarding receiving data via bluetooth by using arduino. If I print a simple hello on the label, it will show it (pic below)

If I want to print numbers, however, it won't show anything. I'll send both my arduino code and mit block, so that you can see better. Thanks in advance!



#include <dht_nonblocking.h>


static const int DHT_SENSOR_PIN = 12;
DHT_nonblocking dht_sensor( DHT_SENSOR_PIN, DHT_SENSOR_TYPE );
unsigned long lgUpdateTime;

void setup()
       lgUpdateTime = millis();
       pinMode(5, INPUT);        
 static bool measure_environment( float *temperature, float *humidity )
  static unsigned long measurement_timestamp = millis( );

  /* Measure once every four seconds. */
  if( millis( ) - measurement_timestamp > 2000ul )
    if( dht_sensor.measure( temperature, humidity ) == true )
      measurement_timestamp = millis( );
      return( true );

  return( false );

void loop()
{ float temperature;
  float humidity;
   // if(millis() - lgUpdateTime > 1000) //Loop approx every 1 seconds
     // {
       //    lgUpdateTime = millis();

           if (digitalRead(5) == HIGH) //check the status of the HC05 module
           {if( measure_environment( &temperature, &humidity ) == true )
    //Serial.print( "T = " );
    Serial.print( temperature, 1 );
    //Serial.print( " deg. C" );


Hello Manuel

Well, we can't see all of your Blocks. In future right-mouse in the Blocks work area and select "Download Blocks as image".

Your Arduino Sketch is very odd, where did you find it? Note that you typically have only 23 bytes for your data so you should only send values, decoration such as "T=" and "deg C" can be done in the App if required, which you seem to have discovered yourself. Your Sketch correctly uses Serial.println() to indicate end-of-data but have you set this in the App Blocks too?


...... and your data receive should be like this (note, -1 means "read all bytes")

Here is a sample BT Project:
BT_Basic_Setup_Receive.aia (8.4 KB)

Note that to avoid buffer overrun (aka phone lock-up or crash) it is important that the app timer interval is approx 20% faster than the Sketch Loop time interval, but it must be an adequate length of time for the App to perform the processes required. The Sketch Loop time interval should suit the task in hand. It is pointless sending values super-fast for real-time display because the human eye cannot cope with that.

1 Like

What if your constantly receiving data, do i use -1 method too?

Define "constantly receiving data".

1 Like

the video above, so i am using an FSR sensor and i print "d" when FSR > 200 else it just prints "n", in my app i want it to trigger an alarm whenever "d" is detected but it doesnt work :confused:

OK, looks like your code is good - what is the setting of the Clock Timer Interval and that of the Arduino? It may be that some data is simply missed.


Hi again, few things:

  1. TimerAlwaysFires: If the Phone is falling into 'black screen mode', you can use this setting and the timer will persist. Ensure that on exit of the App, the Clock is terminated.

  2. Do not enable the Timer until there is a connection and the App is ready to start receiving data.

  3. With the Sketch interval @ 400 milliseconds, the App Clock Timer interval should run @ 300 milliseconds.

  4. The App needs to know the EOD (End of Data). Serial.println() is Ascii LineFeed Char number 10.

  5. You should not use delay() with sensors. Please upload the full Sketch and I will modify it for you. Change the file extension to .txt

Here is a Basic BT Classic Project for you to plunder - study it carefully to take away the best tips, in particular the DelimiterByte.

There is a Procedure to exit the App - since you are using TimerAlwaysFires, set TimerAlwaysFires to false.

Note that it is best to make all Clock settings in the Blocks rather than the Designer palette, easier to use at tweaking time.

BT_Basic_Setup_Receive.aia (7.2 KB)

aa.txt (540 Bytes)
aa (1).aia (123.5 KB)

Thank you very much and I will have a close look

BtSendChar.txt (1.1 KB)

I notice something unusual about this sketch.

Most other projects have two data streams, Serial and BTSerial,
one for a debugging display somewhere and one to go to the BlueTooth output device.

This project has only one output stream.

Could this problem be one of omission?

Nope, it's just that the Project is very nearly correct and we have already seen the debug output in the Arduino Terminal, so it's not required.

Edit: Main culprit is within the Project - no Delimiter Byte specified.


Okay thank you and in the code where u used Serial.connected, I used if(Serial) and the app connects but when I put pressure on the sensor the app doesnt seemed to respond to what it suppose to do (setting the label colour and stuff)

What we can do is set a temporary label in the GUI and just stream the data into the label without any qualification (I think my example Project does that) - we then at least know the data has been received.

Ah yes - remove if (Serial.connected()) , that's only required when using the software serial.

//BtSendChar.ino  Chris Ward 28/03/2022 00:01:56

#include <Wire.h>

unsigned long lgUpdateTime;
int fsrAPin = A1; // FSR is connected to analog 
int iFSR;         // the Analog reading from the FSR resistor divider

void setup(void) {

  Serial.begin(9600); // Send data to App
  lgUpdateTime = millis();

void loop(void) {
	     if(millis() - lgUpdateTime > 400) //Loop approx every 400 milliseconds
               lgUpdateTime = millis();
               iFSR = analogRead(fsrAPin);
               if (iFSR >200){
                   Serial.println();  //This tells App "End of Data" = Ascii LineFeed Char Num 10
               } else{
                   Serial.println();  //This tells App "End of Data" = Ascii LineFeed Char Num 10 

I made another label (Label3) and it seems like the app is not receiving any data from the sensor because Label3 doesnt display anything

Is Location switched on (phone)?

... you could just test with my sample Project.

the location is off

Must be on (Google Android security measure)