No Pulse Detected Error in ESP32 Heart Rate Monitor with MAX30102

I am designing a heart rate monitor system using an ESP32 microcontroller, tested on a breadboard setup, to simulate the functioning of a pacemaker. The system continuously monitors heart rate using a pulse sensor (MAX30102 module) and triggers an alert if the heart rate falls below or rises above specific thresholds (e.g., < 50 bpm or > 120 bpm). However, I keep getting the error: "No pulse detected. Check sensor placement." What could be causing this issue?

Here’s my code:
#include <Wire.h>
#include "MAX30105.h" 
#include "heartRate.h"

MAX30105 particleSensor;
const int alertPin = 15;  // Pin for LED alert
const int minHeartRate = 50;
const int maxHeartRate = 120;

void setup() {
  Serial.begin(115200);
  pinMode(alertPin, OUTPUT);
  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) {
    Serial.println("MAX30102 not detected. Check wiring.");
    while (true);  // Freeze in case of error
  }

  particleSensor.setup();  // Configure sensor settings
  particleSensor.setPulseAmplitudeRed(0x0A);
}

void loop() {
  long irValue = particleSensor.getIR();
  if (irValue > 50000) { // If a valid pulse is detected
    int heartRate = averageHeartRate();  // Calculate heart rate
    Serial.print("Heart Rate: ");
    Serial.println(heartRate);

    // Check for abnormal heart rate
    if (heartRate < minHeartRate || heartRate > maxHeartRate) {
      digitalWrite(alertPin, HIGH);  // Trigger alert
      Serial.println("Alert! Abnormal heart rate detected.");
    } else {
      digitalWrite(alertPin, LOW);  // No alert
    }
  } else {
    Serial.println("No valid pulse detected. Check sensor placement.");
  }

  delay(1000);  // Delay for 1 second between readings
}

int averageHeartRate() {
  return random(40, 130);  // Simulated heart rate for testing
}
Was this page helpful?