max30100

hello programers
I lost all of my day trying to just turn on the buzzer if the SpO2 was less than 95% for one minute and I couldn't because any delay that I am adding to the program makes the sensor does not gives any reads they still zero at all the time.
so shortly I need to make an alarm when the SpO2 is less than 95% for one minute does anybody knows how to make this happens???
the module is max30100
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 1000
#define buz 3
#define Lp 95
// 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(115200);
Serial.print("Initializing pulse oximeter..");
pinMode(buz, OUTPUT);
// 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);
}

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) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");

tsLastReport = millis();
if(pox.getSpO2()<Lp)
{
digitalWrite(buz, HIGH);
}
else
{
digitalWrite(buz, LOW);
}
}

}

thanks for advice, I need the same of this condition but the alarm I want it to work just after one minute the SpO2 is less than 95%

Please post your full sketch.

If possible you should always post code directly in the forum thread as text using code tags (</> button on the toolbar). This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the forum will allow then it's OK to add it as an attachment. If you click the "Reply" button on this forum thread, you will see an "Attachments and other options" button.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

When your code requires a library that's not included with the Arduino IDE please post a link (using the chain links icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.

hello programers
I lost all of my day trying to just turn on the buzzer if the SpO2 was less than 95% for one minute and I couldn't because any delay that I am adding to the program makes the sensor does not gives any reads they still zero at all the time.
so shortly I need to make an alarm when the SpO2 is less than 95% for one minute does anybody knows how to make this happens???
the module is max30100
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 1000
#define buz 3
#define Lp 95
// 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(115200);
Serial.print("Initializing pulse oximeter..");
pinMode(buz, OUTPUT);
// 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);
}

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) {
Serial.print("Heart rate:");
Serial.print(pox.getHeartRate());
Serial.print("bpm / SpO2:");
Serial.print(pox.getSpO2());
Serial.println("%");

tsLastReport = millis();
if(pox.getSpO2()<Lp)
{
digitalWrite(buz, HIGH);
}
else
{
digitalWrite(buz, LOW);
}
}

}

thanks for the advice, I need the same of this condition but the alarm I want it to work just after one minute the SpO2 is less than 95%

Please don't cross post!
http://forum.arduino.cc/index.php?topic=587059
I have reported this thread to the moderators.

Duplicate posts waste the time of the people helping you. I might spend 15 minutes writing a detailed answer on this thread, without knowing that someone already did the same in the other thread. This behavior is not very respectful to the people you're asking for assistance. Just because we give our time freely doesn't mean it has no value.

In the future, take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, which you would already know if you had read the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.

Threads merged.