// #include <Wire.h>
// #include "MAX30100_PulseOximeter.h"
// #define REPORTING_PERIOD_MS 1000 // Change this to your desired reporting interval
// PulseOximeter pox;
// unsigned long tsLastReport = 0; // Declare tsLastReport
// void setup() {
// Serial.begin(115200);
// // Initialize the MAX30100 sensor
// if (!pox.begin()) {
// Serial.println("MAX30100 initialization failed. Please check your connections.");
// while (1);
// }
// // Set the LED current (adjust as needed)
// pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);
// // Other setup code (if any)
// }
// void loop() {
// pox.update();
// // Your other code here
// // Example: Print SpO2 value
// if (millis() - tsLastReport > REPORTING_PERIOD_MS) {
// Serial.print("SpO2: ");
// Serial.println(pox.getSpO2()); // Use getSpO2 instead of getSpo2
// tsLastReport = millis();
// }
// }
// #include <Wire.h>
// #include "MAX30100_PulseOximeter.h"
// #define REPORTING_PERIOD_MS 1000
// PulseOximeter pox;
// uint32_t lastBeat = 0;
// void onBeatDetected()
// {
// Serial.println("Beat!");
// }
// void setup()
// {
// Serial.begin(115200);
// Serial.println("Initializing MAX30100...");
// if (!pox.begin())
// {
// Serial.println("MAX30100 was not found. Please check wiring/power.");
// while (1);
// }
// Serial.println("Place your index finger on the sensor to measure heart rate and SpO2...");
// pox.setOnBeatDetectedCallback(onBeatDetected);
// }
// void loop()
// {
// pox.update();
// if (millis() - lastBeat > REPORTING_PERIOD_MS)
// {
// lastBeat = millis();
// if (pox.getHeartRate() > 0)
// {
// Serial.print("Heart rate: ");
// Serial.print(pox.getHeartRate());
// Serial.print(" bpm\t");
// if (pox.getSpO2() > 0)
// {
// Serial.print("SpO2: ");
// Serial.print(pox.getSpO2());
// Serial.println("%");
// }
// else
// {
// Serial.println("SpO2: Not available");
// }
// }
// else
// {
// Serial.println("Heart rate: Not available");
// }
// }
// }
//
// #include <Wire.h>
// #include "MAX30100_PulseOximeter.h"
// #define SDA_PIN A4
// #define SCL_PIN A5
// #define REPORTING_PERIOD_MS 1000
// PulseOximeter pox;
// uint32_t lastBeat = 0;
// void onBeatDetected()
// {
// Serial.println("Beat!");
// }
// void setup()
// {
// Serial.begin(115200);
// Serial.println("Initializing MAX30100...");
// Wire.begin();
// // Wire.setSDA(SDA_PIN);
// // Wire.setSCL(SCL_PIN);
// // Initialize the MAX30100 sensor
// if (!pox.begin())
// {
// Serial.println("MAX30100 was not found. Please check wiring/power.");
// while (1); // Stay in an infinite loop if sensor not found
// }
// // Set the callback function for beat detection
// pox.setOnBeatDetectedCallback(onBeatDetected);
// Serial.println("Place your index finger on the sensor to measure heart rate and SpO2...");
// }
// void loop()
// {
// pox.update();
// if (millis() - lastBeat > REPORTING_PERIOD_MS)
// {
// lastBeat = millis();
// if (pox.getHeartRate() > 0)
// {
// Serial.print("Heart rate: ");
// Serial.print(pox.getHeartRate());
// Serial.print(" bpm\t");
// if (pox.getSpO2() > 0)
// {
// Serial.print("SpO2: ");
// Serial.print(pox.getSpO2());
// Serial.println("%");
// }
// else
// {
// Serial.println("SpO2: Not available");
// }
// }
// else
// {
// Serial.println("Heart rate: Not available");
// }
// }
// }
// #include <Wire.h>
// #include "MAX30100_PulseOximeter.h"
// #define SDA_PIN A4
// #define SCL_PIN A5
// #define REPORTING_PERIOD_MS 1000
// PulseOximeter pox;
// uint32_t lastBeat = 0;
// void onBeatDetected()
// {
// Serial.println("Beat!");
// }
// void setup()
// {
// Serial.begin(115200);
// Serial.println("Initializing MAX30100...");
// Wire.begin();
// // Wire.setSDA(SDA_PIN);
// // Wire.setSCL(SCL_PIN);
// if (!pox.begin())
// {
// Serial.println("MAX30100 was not found. Please check wiring/power.");
// while (1); // Stay in an infinite loop if sensor not found
// }
// pox.setOnBeatDetectedCallback(onBeatDetected);
// Serial.println("Place your index finger on the sensor to measure heart rate and SpO2...");
// }
// void loop()
// {
// pox.update();
// if (millis() - lastBeat > REPORTING_PERIOD_MS)
// {
// lastBeat = millis();
// if (pox.getHeartRate() > 0)
// {
// Serial.print("Heart rate: ");
// Serial.print(pox.getHeartRate());
// Serial.print(" bpm\t");
// if (pox.getSpO2() > 0)
// {
// Serial.print("SpO2: ");
// Serial.print(pox.getSpO2());
// Serial.println("%");
// }
// else
// {
// Serial.println("SpO2: Not available");
// }
// }
// else
// {
// Serial.println("Heart rate: Not available");
// }
// }
// }
// #include <Wire.h>
// #include <LiquidCrystal.h>
// #include "MAX30100_PulseOximeter.h"
// LiquidCrystal lcd(13, 12, 11, 10, 9, 8); // Initialize LCD with appropriate pins
// #define REPORTING_PERIOD_MS 1000
// PulseOximeter pox;
// uint32_t tsLastReport = 0;
// void onBeatDetected()
// {
// Serial.println("Beat!"); // You can customize this behavior
// }
// void setup()
// {
// Serial.begin(115200);
// Serial.println("Initializing MAX30100...");
// Wire.begin();
// // if (!pox.begin())
// // {
// // Serial.println("MAX30100 was not found. Please check wiring/power.");
// // while (1); // Stay in an infinite loop if sensor not found
// // }
// pox.setOnBeatDetectedCallback(onBeatDetected);
// lcd.begin(16, 2); // Initialize the LCD with 16 columns and 2 rows
// lcd.print("Heart Rate:"); // Display initial text on LCD
// lcd.setCursor(0, 1);
// lcd.print("SpO2:");
// Serial.println("Place your index finger on the sensor to measure heart rate and SpO2...");
// }
// void loop()
// {
// pox.update();
// if (millis() - tsLastReport > REPORTING_PERIOD_MS)
// {
// tsLastReport = millis();
// if (pox.getHeartRate() > 0)
// {
// Serial.print("Heart rate: ");
// Serial.print(pox.getHeartRate());
// Serial.print(" bpm\t");
// lcd.setCursor(12, 0); // Update LCD display for heart rate
// lcd.print(pox.getHeartRate());
// if (pox.getSpO2() > 0)
// {
// Serial.print("SpO2: ");
// Serial.print(pox.getSpO2());
// Serial.println("%");
// lcd.setCursor(6, 1); // Update LCD display for SpO2
// lcd.print(pox.getSpO2());
// lcd.print("%");
// }
// else
// {
// Serial.println("SpO2: Not available");
// lcd.setCursor(6, 1);
// lcd.print("N/A");
// }
// }
// else
// {
// Serial.println("Heart rate: Not available");
// lcd.setCursor(12, 0);
// lcd.print("N/A");
// }
// }
// // Add LM35 temperature sensor reading and display it on the LCD
// float temperatureC = analogRead(A0) * 0.48875; // Convert LM35 output to Celsius
// lcd.setCursor(0, 1);
// lcd.print("Temp: ");
// lcd.print(temperatureC);
// lcd.print("C");
// }
//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!!!");
}
const int SDA_PIN = 4; // Define SDA pin (replace with actual pin)
const int SCL_PIN = 5; // Define SCL pin (replace with actual pin)
MAX30100 pulseOximeter;
void setup()
{
Serial.begin(115200);
Serial.println("Initializing MAX30100 ....");
lcd.init();
lcd.backlight();
lcd.createChar(1 , smile);
lcd.createChar(2 , mod);
lcd.createChar(3 , sad);
lcd.setCursor(0, 0);
lcd.print(" Pulse");
lcd.setCursor(0, 1);
lcd.print(" Oximeter");
delay(2000);
Wire.begin();
// if (!pox.begin()) {
// Serial.println("FAILED");
// while (1);
// } 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);
}
}
}
// #include <Wire.h>
// #include "MAX30100_PulseOximeter.h"
// #define REPORTING_PERIOD_MS 1000
// int last_detected = LOW;
// MAX30100 sensor;
// uint16_t ir, red;
// uint16_t avg_ir = 0, avg_red = 0;
// void setup() {
// Serial.begin(115200);
// Serial.print("Initializing MAX30100..");
// if (sensor.begin()) {
// Serial.println("FAILED");
// // for (;;);
// } else {
// Serial.println("SUCCESS");
// }
// sensor.setMode(MAX30100_MODE_SPO2_HR);
// sensor.setLedsCurrent(MAX30100_LED_CURR_50MA, MAX30100_LED_CURR_27_1MA);
// sensor.setLedsPulseWidth(MAX30100_SPC_PW_1600US_16BITS);
// sensor.setSamplingRate(MAX30100_SAMPRATE_100HZ);
// sensor.setHighresModeEnabled(true);
// getReadings();
// }
// void loop() {
// sensor.update();
// while (sensor.getRawValues(&ir, &red)) {
// if (ir > 10 * avg_ir && red > 10 * avg_red) {
// if (last_detected == LOW) {
// Serial.println("Presence Detected!");
// last_detected = HIGH;
// }
// }
// else {
// last_detected = LOW;
// }
// }
// }
// void getReadings() {
// delay(50);
// for (int i = 0; i <= 9; i++) {
// sensor.update();
// sensor.getRawValues(&ir, &red);
// avg_ir += ir;
// avg_red += red;
// delay(50);
// }
// avg_ir /= 10;
// avg_red /= 10;
// }