#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
// Create an instance of the MAX30100 sensor
MAX30100_PulseOximeter pox;
// Variable to store heart rate and SpO2 values
float heartRate;
float spo2;
void setup() {
Serial.begin(115200);
// Initialize the sensor
if (!pox.begin()) {
Serial.println("MAX30100 not detected. Please check wiring.");
while (1);
}
pox.setOnBeatDetectedCallback(onBeatDetected);
}
void loop() {
// Update the sensor readings
pox.update();
// Print out the heart rate and SpO2 values
heartRate = pox.getHeartRate();
spo2 = pox.getSpO2();
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.print(" bpm");
Serial.print(" | SpO2: ");
Serial.print(spo2);
Serial.println(" %");
delay(1000); // Delay for 1 second
}
void onBeatDetected() {
Serial.println("Beat detected!");
}