Pulse sensor with esp32 not working

hello i have esp32 node mcu, i try to use pulss sensoer to get the BPM i use the play ground examples but only the getting started project is working
how can i chack the BPM?
this is the esp and the BPM code:

code -

/* Getting_BPM_to_Monitor prints the BPM to the Serial Monitor, using the least lines of code and PulseSensor Library.

--------Use This Sketch To------------------------------------------

  1. Displays user's live and changing BPM, Beats Per Minute, in Arduino's native Serial Monitor.
  2. Print: ":heart: A HeartBeat Happened !" when a beat is detected, live.
  3. Learn about using a PulseSensor Library "Object".
  4. Blinks LED on PIN 13 with user's Heartbeat.

#define USE_ARDUINO_INTERRUPTS true // Set-up low-level interrupts for most acurate BPM math.
#include <PulseSensorPlayground.h> // Includes the PulseSensorPlayground Library.

// Variables
const int PulseWire = 0; // PulseSensor PURPLE WIRE connected to ANALOG PIN 0
const int LED13 = 13; // The on-board Arduino LED, close to PIN 13.
int Threshold = 550; // Determine which Signal to "count as a beat" and which to ignore.
// Use the "Gettting Started Project" to fine-tune Threshold Value beyond default setting.
// Otherwise leave the default "550" value.

PulseSensorPlayground pulseSensor; // Creates an instance of the PulseSensorPlayground object called "pulseSensor"

void setup() {

Serial.begin(9600); // For Serial Monitor

// Configure the PulseSensor object, by assigning our variables to it.
pulseSensor.blinkOnPulse(LED13); //auto-magically blink Arduino's LED with heartbeat.

// Double-check the "pulseSensor" object was created and "began" seeing a signal.
if (pulseSensor.begin()) {
Serial.println("We created a pulseSensor Object !"); //This prints one time at Arduino power-up, or on Arduino reset.

void loop() {

int myBPM = pulseSensor.getBeatsPerMinute(); // Calls function on our pulseSensor object that returns BPM as an "int".
// "myBPM" hold this BPM value now.

if (pulseSensor.sawStartOfBeat()) { // Constantly test to see if "a beat happened".
Serial.println(":heart: A HeartBeat Happened ! "); // If test is "true", print a message "a heartbeat happened".
Serial.print("BPM: "); // Print phrase "BPM: "
Serial.println(myBPM); // Print the value inside of myBPM.

delay(20); // considered best practice in a simple sketch.



Hi, @royhendel
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you post link to spec/data of the sensor?
Can you post a circuit diagram please?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

1 Like

This is, so far, my best attempt at making one of those things work, using an ESP32.

#include "sdkconfig.h" // used for log printing
#include "esp_system.h"
#include <SimpleKalmanFilter.h>
#include <Wire.h>
#include "MAX30105.h"
#include <PeakDetection.h>

MAX30105 particleSensor;
PeakDetection peakDetection;
SimpleKalmanFilter KF_HB( .50f, 1.0f, .01f );
uint64_t TimePastKalman  = esp_timer_get_time();
float ps = 0.0f;
float slope;
float x1, x2;
float q1 = xTaskGetTickCount() / 1000.0f , q2 = xTaskGetTickCount() / 1000.0f;
float dx, dy;
bool currentSlope = false;
int PulseCount = 0;
int mTime = xTaskGetTickCount();
int restTime = xTaskGetTickCount();
int currentPeak = 0;
int pastPeak = 0;

 * https://github.com/leandcesar/PeakDetection
void setup()

  Serial.begin( 115200 );

  peakDetection.begin( 5, 1, .4 );


  // Initialize sensor
  if (!particleSensor.begin(Wire, I2C_SPEED_FAST)) //Use default I2C port, 400kHz speed
    log_i("MAX30105 was not found. Please check wiring/power. ");
    while (1);

  //Setup to sense a nice looking saw tooth on the plotter
  byte ledBrightness = 0x1F; //Options: 0=Off to 255=50mA
  byte sampleAverage = 8; //Options: 1, 2, 4, 8, 16, 32
  byte ledMode = 3; //Options: 1 = Red only, 2 = Red + IR, 3 = Red + IR + Green
  int sampleRate = 400; //Options: 50, 100, 200, 400, 800, 1000, 1600, 3200
  int pulseWidth = 411; //Options: 69, 118, 215, 411
  int adcRange = 4096; //Options: 2048, 4096, 8192, 16384

  particleSensor.setup(ledBrightness, sampleAverage, ledMode, sampleRate, pulseWidth, adcRange); //Configure sensor with these settings


void loop()

  ps = particleSensor.getIR();
  KF_HB.setProcessNoise( (esp_timer_get_time() - TimePastKalman) / 1000000.0f ); //get time, in microsecods, since last readings
  ps = KF_HB.updateEstimate( ps ); // apply simple Kalman filter
  TimePastKalman = esp_timer_get_time(); // time of update complete
  ps = ps * (1.0f/10000.0f);
  peakDetection.add( ps );
  currentPeak = peakDetection.getPeak();
  float filtered = peakDetection.getFilt();
  Serial.print( currentPeak );

1 Like

You, also, might want to change your pin references to match a ESP32, like pin 13 is NOT the LED pin for a ESP32.

HI Tom
The sensor is - The "GettingStartedProject" – World Famous Electronics llc.
but the circuit is just the sensor and the esp32
thanks :slight_smile: :slightly_smiling_face:

Does the example in the YouTube clip work for you?

Tom.. :grinning: :+1: :coffee: :australia:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.