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.