Sensor Frequency Adjustment

We are currently working on a project that uses a sensor in order to monitor heartrate and oxygen saturation, but the sensor is fluctuating frequently because I believe it updates many times in a second. How can we adjust the time it updates?

here's the code that we are using

//scientist BENIELS LAB
/* CREATED BY: HOW TO ELECTRONICS | MODIFIED BY: SCIENTIST BENIELS  LAB */

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 1000

LiquidCrystal_I2C lcd(0x27, 16, 2);


PulseOximeter pox;
uint32_t tsLastReport = 0;

void onBeatDetected() {

  Serial.println("Beat!!!");
}

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.print(1, "RED");
  lcd.print(2, "ORANGE");
  lcd.print(3, "YELLOW");
  lcd.print(4, "GREEN");
  lcd.setCursor(0, 0);
  lcd.print("   MEDI-WATCH");
  lcd.setCursor(0, 1);
  lcd.print("Triage Assistant");
  delay(10000);

  if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;)
      ;
  } else {
    Serial.println("SUCCESS");
  }
  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

  pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
  pox.update();
  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("BPM : ");
    lcd.print(pox.getHeartRate());
    lcd.setCursor(0, 1);
    lcd.print("Sp02: ");
    lcd.print(pox.getSpO2());
    lcd.print("%");
    tsLastReport = millis();

    if (pox.getSpO2() <= 80) {
      lcd.setCursor(13, 1);
      lcd.print("RED");
    } else if (pox.getSpO2() <= 89 && pox.getSpO2() >= 81) {
      lcd.setCursor(10, 1);
      lcd.print("ORANGE");
    } else if (pox.getSpO2() <= 94 && pox.getSpO2() >= 90) {
      lcd.setCursor(10, 1);
      lcd.print("YELLOW");
    } else if (pox.getSpO2() >= 95) {
      lcd.setCursor(11, 1);
      lcd.print("GREEN");
    }
  }
}

Consult the library you are using.

Start with the example code coming with the library before writing your own code. If there is no example code then search the forum or use a better supported library.

This makes your updates happen every one second (1000 milliseconds).

https://forum.arduino.cc/t/adjusting-the-sensitivity-of-the-sensor/1139136

Good Evening, we are currently programming a MAX30100, but the result that it provide in the pulse rate is too high. Is there anyway to make the sensitivity of the sensor to make the result more accurate or closer to real result?

here's the code that we are using:

//scientist BENIELS LAB
/* CREATED BY: HOW TO ELECTRONICS | MODIFIED BY: SCIENTIST BENIELS  LAB */

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS 3000

LiquidCrystal_I2C lcd(0x27, 16, 2);


PulseOximeter pox;
uint32_t tsLastReport = 0;

void onBeatDetected() {

  Serial.println("Beat!!!");
}

void setup() {
  Serial.begin(115200);
  lcd.init();
  lcd.backlight();
  lcd.print(1, "RED");
  lcd.print(2, "ORANGE");
  lcd.print(3, "YELLOW");
  lcd.print(4, "GREEN");
  lcd.setCursor(0, 0);
  lcd.print("   MEDI-WATCH");
  lcd.setCursor(0, 1);
  lcd.print("Triage Assistant");
  delay(1000);

  if (!pox.begin()) {
    Serial.println("FAILED");
    for (;;)
      ;
  } else {
    Serial.println("SUCCESS");
  }
  pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

  pox.setOnBeatDetectedCallback(onBeatDetected);
}

void loop() {
  pox.update();
  if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("");
    Serial.print(pox.getHeartRate());
    lcd.setCursor(0, 1);
    lcd.print("");
    Serial.print(pox.getSpO2());
    Serial.print("%");
    tsLastReport = millis();

    if (pox.getSpO2() < 90) {
      lcd.setCursor(7, 0);
      lcd.print("RED");
    } else if (pox.getSpO2() < 90 && pox.getHeartRate() > 120 && pox.getHeartRate() < 40) {
      lcd.setCursor(6, 0);
      lcd.print("ORANGE");
    } else if (pox.getSpO2() < 95 && pox.getSpO2() > 91) {
      lcd.setCursor(6, 0);
      lcd.print("YELLOW");
    } else if (pox.getSpO2() > 96) {
      lcd.setCursor(7, 0);
      lcd.print("GREEN");
    }
  }
}

also, we would like to integrate the temperature reading function of the device in addition to the heart rate and oxygen saturation, is there a way to combine the features? we are beginners in the arduino programming world, so this is really a great help. Thanks in advance!

see Sensor Frequency Adjustment

1 Like

thank you for your response on my other question, it really helped us a lot. However, we are now currently working on another issue which is regarding the sensitivity of the sensor. Iss there any way we can reduce the sensitivity of MAX30100?

@mucckx, please do not cross-post. Threads merged.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.