Max30102 read oxigen but not heart rate

I managed to set up the I2C connection, but for some reason, the sensor won't pick up the heart pulse signal. Can anybody help?

my code

#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"

MAX30105 particleSensor;
#define debug Serial

void setup() {
  debug.begin(115200);
  debug.println("=== MAX30105: Heart Rate & SpO2 ===");

  if (!particleSensor.begin()) {
    debug.println("❌ Error: MAX30105 not found. Check connections!");
    while (1);
  }

  // Configure sensor
  particleSensor.setup();
  // You can experiment with changing the LED values if needed (e.g., 0x7F)
  particleSensor.setPulseAmplitudeRed(0x3F);  // Red LED brightness
  particleSensor.setPulseAmplitudeIR(0x3F);   // Infrared LED brightness

  debug.println("\nTimestamp (ms) | IR Value    | Heart Rate (BPM) | SpO2 (%)");
  debug.println("-----------------------------------------------------------");
}

void loop() {
  long irValue = particleSensor.getIR();  // Read IR value

  // Lower the threshold if the signal is weak
  if (irValue < 30000) {
    debug.print("⚠️ Sensor not in contact or weak signal. IR = ");
    debug.println(irValue);
  } else {
    float bpm = checkBPM();       // Read heart rate
    float spo2 = estimateSpO2();  // Estimate SpO2

    debug.printf("%10lu ms  | %10ld | %16.2f | %8.2f\n", millis(), irValue, bpm, spo2);
  }

  delay(1000);
}

// Function to calculate heart rate BPM
float checkBPM() {
  static float heartRate = 0;
  // If checkForBeat function detects a beat, calculate the time interval between beats
  if (checkForBeat(particleSensor.getIR())) {
    static long lastBeat = 0;
    long delta = millis() - lastBeat;
    lastBeat = millis();
    // Avoid division by 0 or unrealistic values
    if (delta > 300 && delta < 2000)
      heartRate = 60.0 / (delta / 1000.0);
  }
  return heartRate;
}

// Function to estimate SpO2 (simple estimation)
float estimateSpO2() {
  static float spo2 = 98.0;  // Default value
  return spo2 - (random(0, 5) / 10.0);
}

Did you use the evaluation kit to learn how to use the device? And now you are attempting the same processes using an Arduino?

1 Like

Your spO2 data is fake.

Is the ESP32 using the same voltage level as the MAX30102?

1 Like

I still a student, This is my first time use arduino so yes

Yes the logic level set at 3.3v
I clearly see that the spo2 is not real i was trying to get the heart rate because my school project only need it, you saying that max30102 need real spo2 data to get the heart rate, if so i will try it as soon as i can.

Debug your code by using serial.Print() statements so you can see what is happening. Right now you are only guessing and asking strangers to guess with you.

Start with the message showing you actually executed the function.
Then add a message showing that the "if" statement was true. Add an "else" after each "if" with a message showing the "if" returned false.

1 Like