HC-05 Bluetooth Android App with MAX30100 - update problem

Hello!
I'm working on a project which i called Health Monitor. In my project i use Arduino UNO, HC-05 BT Module, MAX30100 and MLX90614.

Without using Android App, everything work very well. I connected to arduino 2 Buttons and 2 of my sensor has reacted of this. I had some problems with pox.update() functio, because of the library requires very strict timing updates for its goal of 100Hz sampling rate, but i fixed it - MAX30100 not responding to bottom, but it runs continuously and only giving out valid results.

When i decided to create app, and get rid of physical buttons, my problems have begun.

In my app i have 2 Buttoms, temperature measurement and puls&saturation measurement.
My code:

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SoftwareSerial.h>
#include <Adafruit_MLX90614.h>

#define REPORTING_PERIOD_MS     1000

SoftwareSerial Pins(2,3);
long int data;
long int password1= 79;
long int password2= 92;

uint32_t tsLastReport = 0;
PulseOximeter pox;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

   int i=0;
   int j=0;
   int x=0;
   int y=0;

   int SO2;
   int so2_tab[10];
   int suma_so2=0;
   int srednia_so2=0;

   float Puls;
   float puls_tab[10];
   float suma_puls=0;
   float srednia_puls=0;

   int t1=0;
   int t2=0;
   float tempObjec;
   float temp_tab[100];
   float suma_temp=0;
   float srednia_temp=0;

void onBeatDetected()
{
    Serial.println("Beat!");
}


void setup() {
    Serial.begin(9600);
    Pins.begin(9600);

    Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
    mlx.begin();
    //pinMode(buttonPin, INPUT_PULLUP);
    //pinMode(buttonPin2, INPUT_PULLUP);

    //pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {

    data = Pins.parseInt();

    pox.update();

    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Puls=pox.getHeartRate();
        Serial.println(Puls);
        SO2=pox.getSpO2();
        tsLastReport = millis();

    }

    if(Puls>0 && i<10){
      puls_tab[i]=Puls;
      i++;
    }

    if(SO2>0 && j<10){
      so2_tab[j]=SO2;
      j++;
    }

    if(data == password1){
        t1=0;
        t2=0;
        suma_temp=0;
        srednia_temp=0;
        for(t1; t1<100; ){
        tempObjec = mlx.readObjectTempC();
        if(tempObjec>0)
            {
            temp_tab[t1]=tempObjec;
            t1++;
            }
        }
        for(t2; t2<100;t2++)
            {
            suma_temp=suma_temp+temp_tab[t2];
            temp_tab[t2]=0;
            }
        srednia_temp=suma_temp/100;

        Pins.print("Srednia temperatura: ");
        Pins.print(srednia_temp);
        Pins.print("°C");

        Serial.print("Srednia temperatura: ");
        Serial.print(srednia_temp);
        Serial.print("°C");
    }

    if(data == password2 && i>8 && j>8){
      i=0;
      j=0;
      x=0;
      y=0;
      for(x; x<10;x++)
          {
          suma_puls=suma_puls+puls_tab[x];
          puls_tab[x]=0;
          }
      srednia_puls=suma_puls/10;
      suma_puls=0;
      for(y; y<10; y++){
          suma_so2=suma_so2+so2_tab[y];
          so2_tab[y]=0;
          }
      srednia_so2=suma_so2/10;
      suma_so2=0;

      Pins.println("Sredni puls: ");
      Pins.print(srednia_puls);
      Pins.print("bpm");
      srednia_puls=0;

      Serial.println("Sredni puls: ");
      Serial.print(srednia_puls);
      Serial.print("bpm");

      Pins.print("Srednia saturacja: ");
      Pins.print(srednia_so2);
      Pins.print("%");
      srednia_so2=0;
    }

}

With this configuration, MAX30100 doesn't work. Sensor show only 0:

When I removed function which observ output from App (data = Pins.parseInt() ) everything working well again.

I this function, I can see that MAX30100 is updating once every 1000ms:

 if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Puls=pox.getHeartRate();
        Serial.println(Puls);
        SO2=pox.getSpO2();
        tsLastReport = millis();

    }

I chceck, that execution of the function data = Pins.parseInt(); takes 1000ms.

So i decided to fix it like this:
...

    data = Pins.parseInt();
    pox.update();
        Puls=pox.getHeartRate();
        Serial.print(Puls);
        SO2=pox.getSpO2();

...
I removed IF, but it isn't help. MAX30100 still show only 0 and i dont know how to fix it. It looks like this sensor cannot work with bluetooth module (ofc when we wont controll this sensor by BT module) but it cannot be true. Please help me how to fix it.

Sorry for my english and correctness.
I really need help, because i have to bring this project to the end in this form.

I'm not an expert on this, but I recently did some work with the hc-05 bluetooth module. If you connect tx and rx to pin 0 and 1 on arduino, it will receive input and send output via Serial.read(); and Serial.println();. (Just remember when uploading code to the arduino, disconnect the tx and rx pins).

Hope this may help.

Hello
Try this

if (Pins.available()) data = Pins.parseInt();

Have a nice day and enjoy coding in C++.

I did this, but know, Arduino doesn't react to my App.
Thats my code:

#include <Adafruit_MLX90614.h>

#define REPORTING_PERIOD_MS     1000

long int data;
long int password1= 79;
long int password2= 92;

uint32_t tsLastReport = 0;
PulseOximeter pox;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

   int i=0;
   int j=0;
   int x=0;
   int y=0;
   
   int SO2;
   int so2_tab[10];
   int suma_so2=0;
   int srednia_so2=0;
   
   float Puls;
   float puls_tab[10];
   float suma_puls=0;
   float srednia_puls=0;

   int t1=0;
   int t2=0;
   float tempObjec;
   float temp_tab[100];
   float suma_temp=0;
   float srednia_temp=0;

void onBeatDetected()
{
    Serial.println("Beat!");
}
 

void setup() {
    Serial.begin(9600);
    
    Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
    mlx.begin();
    //pinMode(buttonPin, INPUT_PULLUP);
    //pinMode(buttonPin2, INPUT_PULLUP);
    
    //pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {

    data = Serial.read();
    //Serial.print(data);

    pox.update();
    
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Puls=pox.getHeartRate();
        Serial.println(Puls);
        Serial.print(data);
        SO2=pox.getSpO2();
        tsLastReport = millis();

    }

    if(Puls>0 && i<10){
      puls_tab[i]=Puls;
      i++;
    }

    if(SO2>0 && j<10){
      so2_tab[j]=SO2;
      j++;
    }
    
    if(data == password1){
        t1=0;
        t2=0;
        suma_temp=0;
        srednia_temp=0;      
        for(t1; t1<100; ){
        tempObjec = mlx.readObjectTempC();
        if(tempObjec>0)
            {
            temp_tab[t1]=tempObjec;
            t1++;
            }
        }
        for(t2; t2<100;t2++)
            {
            suma_temp=suma_temp+temp_tab[t2];
            temp_tab[t2]=0;
            }
        srednia_temp=suma_temp/100;
        
        Serial.print("Srednia temperatura: ");
        Serial.print(srednia_temp);
        Serial.print("°C"); 
    }

    if(data == password2 && i>8 && j>8){
      i=0;
      j=0;
      x=0;
      y=0;
      for(x; x<10;x++)
          {
          suma_puls=suma_puls+puls_tab[x];
          puls_tab[x]=0;
          }
      srednia_puls=suma_puls/10;
      suma_puls=0;
      for(y; y<10; y++){
          suma_so2=suma_so2+so2_tab[y];
          so2_tab[y]=0;
          }
      srednia_so2=suma_so2/10;
      suma_so2=0;

      Serial.println("Sredni puls: ");
      Serial.print(srednia_puls);
      Serial.print("bpm");
      srednia_puls=0;

      Serial.print("Srednia saturacja: ");
      Serial.print(srednia_so2);
      Serial.print("%");
      srednia_so2=0;
    }
    
}

And now, Pulse&Saturation sensor work well, but Serial.read() doesn't recognize information from Android App. I decided to print data (which is data=Serial.read()) but it constantly print "-1". Maybe i did something wrong?

Maybe test the bluetooth on its own.
This is my test code:

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}
int dat;
void loop() {
  if (Serial.available() > 0) {
    dat = Serial.read();
    if (dat == '1') {
      digitalWrite(13, HIGH);
    }
    if (dat == '2') {
      digitalWrite(13, LOW);
    }
  }
}

Also what app are you using?

What shoud be happend after run your code? I can connect to my Bluetooth but thas all whats happend.
I use my own App - first i choose device which i want to connect and after this i have 2 buttoms, 1(Temperature) send to Arduino '79' and 2(PulsandSaturation) send to arduino '92'. On App i can see print from Arduino.
When i use Pins(2,3) i can controll Temperature sensor and i can see results of measurement, but Pulse sensor didn't work.
When i use Serial.read() with 0,1 Pins I see print from Arduino in my App, but i Arduino doesn't react to Buttoms in my App.

Yeah! Thats almostn help - now sensor collect information, but after i clicked to send this information to my App, i see the results but after this in senser the retrieval of information is disrupted (only what i see is "0.00"). Maybe i can restart the sensor but i dont know if it help and i dont know how to do this. Do u have any idea?

Hello
To add serial.println() to the sketch helps to find out how the dataflow and controlflow works sometimes.
Have a nice day and enjoy coding in C++.

I use serial.println() and thats what happend:
Sensor collect information. When I decided to click Buttom Puls&Saturation to see the results of measurement I see results. I want to do this multiple times - but after 1st ButtomClicked in App, sensor starts showing only "0.00" - doesn't collect information like when i create this topic. I think it can be because pox.update() funtcion could have been interrupted. Do you have any idea how to fix it?
It is my code now:

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
#include <SoftwareSerial.h>
#include <Adafruit_MLX90614.h>

#define REPORTING_PERIOD_MS     1000

SoftwareSerial Pins(2,3);
long int data;
long int password1= 79;
long int password2= 92;

uint32_t tsLastReport = 0;
PulseOximeter pox;

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

   int i=0;
   int j=0;
   int x=0;
   int y=0;
   
   int SO2;
   int so2_tab[10];
   int suma_so2=0;
   int srednia_so2=0;
   
   float Puls;
   float puls_tab[10];
   float suma_puls=0;
   float srednia_puls=0;

   int t1=0;
   int t2=0;
   float tempObjec;
   float temp_tab[100];
   float suma_temp=0;
   float srednia_temp=0;

void onBeatDetected()
{
    Serial.println("Beat!");
}
 

void setup() {
    Serial.begin(9600);
    Pins.begin(9600);
    
    Serial.print("Initializing pulse oximeter..");
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
    mlx.begin();
    //pinMode(buttonPin, INPUT_PULLUP);
    //pinMode(buttonPin2, INPUT_PULLUP);
    
    //pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
    
    if(Pins.available()){
    data = Pins.parseInt();}


    pox.update();
    
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Puls=pox.getHeartRate();
        Serial.println(Puls);
        SO2=pox.getSpO2();
        tsLastReport = millis();

    }

    if(Puls>0 && i<10){
      puls_tab[i]=Puls;
      i++;
      Puls=0;
    }

    if(SO2>0 && j<10){
      so2_tab[j]=SO2;
      j++;
      SO2=0;
    }
    
    if(data == password1){
        t1=0;
        t2=0;
        suma_temp=0;
        srednia_temp=0;      
        for(t1; t1<100; ){
        tempObjec = mlx.readObjectTempC();
        if(tempObjec>0)
            {
            temp_tab[t1]=tempObjec;
            t1++;
            tempObjec=0;
            }
        }
        for(t2; t2<100;t2++)
            {
            suma_temp=suma_temp+temp_tab[t2];
            temp_tab[t2]=0;
            }
        srednia_temp=suma_temp/100;
        
        Pins.print("Srednia temperatura: ");
        Pins.print(srednia_temp);
        Pins.print("°C");
        
        Serial.print("Srednia temperatura: ");
        Serial.print(srednia_temp);
        Serial.print("°C"); 
    }

    if(data == password2 && i>8 && j>8){
      i=0;
      j=0;
      x=0;
      y=0;
      for(x; x<10;x++)
          {
          suma_puls=suma_puls+puls_tab[x];
          puls_tab[x]=0;
          }
      srednia_puls=suma_puls/10;
      suma_puls=0;
      for(y; y<10; y++){
          suma_so2=suma_so2+so2_tab[y];
          so2_tab[y]=0;
          }
      srednia_so2=suma_so2/10;
      suma_so2=0;

      Pins.println("Sredni puls: ");
      Pins.print(srednia_puls);
      Pins.print("bpm");
      srednia_puls=0;

      Serial.println("Sredni puls: ");
      Serial.print(srednia_puls);
      Serial.print("bpm");

      Pins.print("Srednia saturacja: ");
      Pins.print(srednia_so2);
      Pins.print("%");
      srednia_so2=0;
    }
    
}

Hello
check how often the sensor is able to provide a new datum.
Does the libary provides a "new data available" flag?

In PulseOximeter.h i see:

#define SAMPLING_FREQUENCY                  100
#define CURRENT_ADJUSTMENT_PERIOD_MS        500

And only metods:

    bool begin(PulseOximeterDebuggingMode debuggingMode_=PULSEOXIMETER_DEBUGGINGMODE_NONE);
    void update();
    float getHeartRate();
    uint8_t getSpO2();
    uint8_t getRedLedCurrentBias();
    void setOnBeatDetectedCallback(void (*cb)());
    void setIRLedCurrent(LEDCurrent irLedCurrent);
    void shutdown();
    void resume();

In this code i see that this sensor works once per 1000ms:

pox.update();
    
    if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
        Puls=pox.getHeartRate();
        Serial.println(Puls);
        Serial.print(data);
        SO2=pox.getSpO2();
        tsLastReport = millis();

    }