Problem sending Heartbeat and spo2 data to Firebase using MAX30100_Minimal code

Hello everyone!

I am using GY-MAX30100 sensor to measure HeartRate and spo2. I am getting proper readings from the sensor when I am not sending my readings to firebase but when I start sending my readings to firebase, my sensor stops measuring heart rate and spo2 reading and only sending 0 bpm and 0 spo2 readings to firebase and even to my serial monitor.

Here is my code, when I am sending my readings to Firebase:

#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

// Set these to run example.
#define FIREBASE_HOST "test-8bc5c.firebaseio.com"
#define FIREBASE_AUTH "JATYiyaws143Yd68A12wjlG38MBa3UjFAn4BZ2Rv"
#define WIFI_SSID "TP-LINK_8D8E"
#define WIFI_PASSWORD "qwerty1234"

#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
float bpm = 0.0;
float oxygen = 0.0;

#define REPORTING_PERIOD_MS     1000
 
// PulseOximeter is the higher level interface to the sensor
// it offers:
//  * beat detection reporting
//  * heart rate calculation
//  * SpO2 (oxidation level) calculation
PulseOximeter pox;
 
uint32_t tsLastReport = 0;
 
// Callback (registered below) fired when a pulse is detected
void onBeatDetected()
{
    Serial.println("Beat!");
}
 
void setup()
{
    Serial.begin(230400);
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    
 
    Serial.print("Initializing pulse oximeter..");
 
    // Initialize the PulseOximeter instance
    // Failures are generally due to an improper I2C wiring, missing power supply
    // or wrong target chip
    if (!pox.begin()) {
        Serial.println("FAILED");
        for(;;);
    } else {
        Serial.println("SUCCESS");
    }
 
    // The default current for the IR LED is 50mA and it could be changed
    //   by uncommenting the following line. Check MAX30100_Registers.h for all the
    //   available options.
    // pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
 
    // Register a callback for the beat detection
    pox.setOnBeatDetectedCallback(onBeatDetected);
    
    
    
    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
 
void loop()
{
    // Make sure to call update as fast as possible
    pox.update();
    
    // Asynchronously dump heart rate and oxidation levels to the serial
    // For both, a value of 0 means "invalid"
      if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
          bpm = pox.getHeartRate();
          oxygen = pox.getSpO2();
          Serial.print("Heart rate:");
          Serial.print(bpm);
          Serial.print("bpm / SpO2:");
          Serial.print(oxygen);
          Serial.println("%");
          
          delay(100);
          tsLastReport = millis();
                
      }
     Firebase.setInt("/heartbeat", bpm);             
     Firebase.setInt("/oxygen", oxygen); 
  
}

Here are my readings when I am trying to send data to Firebase:

Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%
Heart rate:0.00bpm / SpO2:0.00%

I will be very thankful to you if you will look into my problem.
Thank You!

PS: I have also attached my sensor’s picture:

Not really familiar with firebase but the example demo code has error checking which you do not

Firebase.setFloat("number", 42.0);
  // handle error
  if (Firebase.failed()) {
      Serial.print("setting /number failed:");
      Serial.println(Firebase.error());  
      return;

That may help shed some light on what is going wrong.

You also make your firebase calls EVERY time through loop() - maybe put them inside your time delay loop like your serial output.

Thank you blh64 for your help. Actually, the problem is with the code it generates the heartbeat and oxygen in a particular time so, if we add another code with it, it will add delay, which stops reading heart rate and oxygen from the sensor.

So far, I did not find any proper solution. What I did is just add ESP.restart() command after sending data to firebase because I was getting zero reading after sending data to firebase.

1 Like

Did you solve this problem? Im having the same issue

Hi.

Try to move the line:

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

before

if (!pox.begin()) {}

so as to "make sure to call update as fast as possible".

Also try to add two lines before and after

Firebase.setInt();

as follows:

pox.shutdown();
Firebase.setInt("/heartbeat", bpm);
Firebase.setInt("/oxygen", oxygen);
pox.resume();

I have met a similar problem when using MAX30100 with Ambient, the Iot data visualizing service, on M5stickc.
I haven't tried it with Firebase, but by doing so it worked well anyway on Ambient.

I'm a beginner of Arduino so I'm afraid it might be misguided advice.
I hope it helps you.

Thanks,

Any one solve this issue? I am also facing the same issue.

I will be very greatful to if any one can fix my isses.

Thanks in advance.

Hi guys :slight_smile:

I found the solution, and it’s not necessary to restart the ESP.

Here you have the code.

//Unidades Tecnologicas de Santander
//Ingenieria de Telecomunicaciones
//Andres F. Ramirez B.

#include <Arduino.h>
#include <Wire.h>
#include “MAX30100_PulseOximeter.h”
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include “ESP8266WebServer.h”
#include <FirebaseArduino.h>

#define REPORTING_PERIOD_MS 1000

#define FIREBASE_HOST “THE LINK OF UR DB PROJECT”
#define FIREBASE_AUTH “THE KEY OF UR FIREBASE PROJECT”

#define WIFI_SSID “YOUR SSID”
#define WIFI_PASSWORD “YOUR PASS”

PulseOximeter pox;

unsigned long previousMillis=0;
const long interval=1000;
volatile boolean heartBeatDetected = false;

void onBeatDetected()
{
heartBeatDetected = true;
Serial.println(“Beat!”);

}

void setup()
{
Serial.begin(115200);

WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“Connecting”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("Connected with IP: ");
Serial.println(WiFi.localIP());

Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

if (Firebase.failed()) {
Serial.print(“setting /message failed:”);
Serial.println(Firebase.error());
}

if (!pox.begin()) {
Serial.println(“FAILED”);
for(;;);
} else {
Serial.println(“SUCCESS”);
}

pox.setOnBeatDetectedCallback(onBeatDetected);
}

void leerDatos(){

float bpm = pox.getHeartRate();
float SpO2 =pox.getSpO2();

if( heartBeatDetected && bpm !=0) {

if(SpO2>0){

// here you put the variables what you have in ur db

Firebase.setFloat(“Dato/Ritmo cardiaco”, bpm);
Firebase.setFloat(“Dato/SpO2”, SpO2);

// you can delete this line below, it’s just to know it send the datas in the serial monitor
Serial.print(“Envia”);

}

}

}

void loop()
{

pox.update();

unsigned long currentMillis=millis();
if(currentMillis-previousMillis>=interval)
{
pox.shutdown();
leerDatos();
pox.resume();
previousMillis=currentMillis;

}

}

hi
how you make it work ? i think i have same problem this my post:

i'm new to arduino can you help ?