#include <Wire.h>
#include <MAX30100_PulseOximeter.h>
MAX30100_PulseOximeter pox; // Create an instance of the MAX30100 sensor
void setup() {
Serial.begin(115200);
// Initialize the sensor
if (!pox.begin()) {
Serial.println("MAX30100 not detected!");
while (1);
}
// Configure the sensor
pox.setIRLedCurrent(MAX30100_PulseOximeter::LED_CURR_50MA); // Set IR LED current to 50mA
}
void loop() {
// Update the sensor and get readings
pox.update();
// Get the pulse rate and SpO2 levels
float heartRate = pox.getHeartRate();
float SpO2 = pox.getSpO2();
if (heartRate != -1) {
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.println(" bpm");
} else {
Serial.println("Heart rate could not be detected.");
}
if (SpO2 != -1) {
Serial.print("SpO2: ");
Serial.print(SpO2);
Serial.println(" %");
} else {
Serial.println("SpO2 could not be detected.");
}
delay(1000); // Wait 1 second before reading again
}