How to create threshold and show a value?

So we are currently programming MAX30100 Sensor into arduino in order to monitor someone's oxygen saturation as well as their heart rate.

After getting the values from the sensor, we would like for it to show on the LCD Display as an interpretation. For example if the read on oxygen saturation is >95 and the heart rate is 50-100, then the LCD Display would show "GREEN". Hoping for someone to help us in this. Thanks in advance!

P.S. This is the code that we are using, and we got it from google, it works but it only show the raw value on the screen and not the interpretation.

//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);

byte smile[] = {
B00000,
B00000,
B01010,
B00000,
B10001,
B01110,
B00000,
B00000
};
byte mod[] = {
B00000,
B00000,
B01010,
B00000,
B11111,
B00000,
B00000,
B00000
};
byte sad[] = {
B00000,
B00000,
B01010,
B00000,
B01110,
B10001,
B00000,
B00000
};

PulseOximeter pox;
uint32_t tsLastReport = 0;

void onBeatDetected()
{

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

}

void setup()
{
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.createChar(1 , smile);
lcd.createChar(2 , mod);
lcd.createChar(3 , sad);
lcd.setCursor(0, 0);
lcd.print(" Pluse");
lcd.setCursor(0, 1);
lcd.print(" Oximeter");
delay(2000);

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() >= 96) {
  lcd.setCursor(15 , 1);
  lcd.write(1);                 
}
else if (pox.getSpO2() <= 95 && pox.getSpO2() >= 91) {
  lcd.setCursor(15 , 1);
  lcd.write(2);                 
}
else if (pox.getSpO2() <= 90) {
  lcd.setCursor(15 , 1);
  lcd.write(3);
}

}
}

Use the logical operators to compare the acquired data to the threshold values.

An example:

int o2 = 97;
int bpm = 60;

int o2Threshold = 95;
int bpmThresholdUpper = 100;
int bpmThresholdLower = 50;

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

void loop()
{
   static unsigned long timer = 0;
   unsigned long interval = 1000;
   if (millis() - timer >= interval)
   {
      timer = millis();
// if the o2 is over 95 and (bpm is under 100 and bpm is over 50)
      if (o2 > o2Threshold && (bpm < bpmThresholdUpper && bpm > bpmThresholdLower))
      {
         Serial.println("Parameters OK");
      }
      else
      {
         Serial.println("ALARM");
      }
   }
}

Change the values of o2 and bpm to see how this works.

Please read the forum guidelines to see how to properly post code and some information on making a good post.

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in a code block.

Please go back and fix your original post.

2 Likes

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