Monitor Heart Rate using Pulse Sensor and Arduino

In this tutorial, we will learn to monitor heart rate using a pulse sensor (SEN-11574) and Arduino. Firstly, We will discuss the introduction, pinout, working, and connection diagram of the pulse sensor (SEN-11574) with Arduino. After that, we will three examples such as controlling LED with pulse rate, plotting data on serial monitor, and visualizing pulse sensor data with processing library. W can use this sensor to measure the heart beat rate (BPM). Additionally, by using a processing visualizer library we will show BPM and IBI in real time in an interactive way.

monitor detect Heart Rate using Pulse Sensor and Arduino

SEN-11574 Pulse Sensor Introduction

The SEN-11574 pulse sensor is mainly used for sensing heartbeat rate. Normally it is a very difficult task to measure the exact heartbeat rate, but this has become so much easy with the help of this pulse sensor amped. If we talk about heartbeat, then heart beat is a periodic signal that is produced by any software or hardware system for giving intimation to normal of working of any system. For measuring this periodic intimation signal, many sensors have been used currently in the market but here we shall only talk about SEN-11574 pulse sensor amped. This is basically plugged and play heartbeat sensor and can be used by athletes, game developers, and students in their hardware projects. It is easily available in the market or online shops.

A simple heartbeat pulse sensor is shown below:

Heart beat pulse sensor
Pulse sensor front and back view

It has many applications in our daily life. Some common ones include using the sensor in exercise machines for heart beat measurement during workout and heart beat meter for local use at home.

Pulse Sensor Circuit

The following figure shows the internal circuit diagram of a pulse sensor. It consists of optical heart beat sensor, an amplification circuit, and a noise cancellation circuit.

SEN-11574 heart pulse sensor schematic
Internal block diagram of an SEN-11574 pulse sensor

The front side of the pulse sensor, where the heart shape is drawn, consists of a central LED. This is a hole from where Kingbright’s reverse installed green LED glows and helps the sensor for detecting heartbeat rate. Just under the LED is a photodetector sensor. Besides this, there is another circuitry below the LED. This circuitry is called noise elimination circuitry. It is used for eliminating the noise to enhance the reading of the heart rate pulse sensor.

Heart Pulse Sensor diagram

Pinout

This pulse sensor consists of three pins.

  • First one is the GND pin which is used for supplying ground to this sensor and it is connected to source ground pin.
  • The middle pin is the VCC pin which is used to supply power to the sensor. This sensor is powered on at almost 3.3V to 5V dc voltages.
  • Similarly, the last one is the A0 pin which is an analogue pin and it is used for receiving analogue signal. The sensor gives the output in the form of voltage. We need to measure this voltage waveform and extract heart beat rate out of this waveform.this sensor also consists of a central LED. This LED helps the sensor for detecting heartbeat rate. Beside this, there is another circuitry below LED and this circuitry is called noise elimination circuitry. This circuitry is used for eliminating the noise which effects on the reading of the heart rate pulse sensor.

The pin configuration of this heart rate sensor is shown in the picture below:

Heart Pulse Sensor pin out
SEN-11574 Pinout

Specifications

The table below shows some key specifications of the SEN-11574 sensor.

Operating Temperature-40°C to +80°C
Input Voltage (VCC)3V to 5.5V
Output Voltage 0.3V to VCC
Supply Current3mA to 4mA
Dimensions (L x W)15.8mm

How Pulse Sensor Works?

The working principle of this heartbeat rate sensor is very simple. If we talk about heartbeat rate, then heartbeat rate is the ratio of time between two consecutive heartbeats. Similarly, when the human blood is circulated in human body then this blood is squeezed in capillary tissues. As a result, the volume of capillary tissues is increased but this volume is decreased after each heartbeat. This change in volume of capillary tissues affects the LED light of heart rate pulse sensor, which transmits light after each heartbeat. This change in light is very small but this can be measured by connecting any controller with this pulse sensor. This means the LED light which has every pulse sensor helps for measuring pulse rate.

The working of this sensor could be checked by placing a human finger in front of this pulse sensor. When a finger is placed in front of this pulse sensor then the reflection of LED light is changed based on the volume of blood change inside capillary vessels. This means during the heartbeat the volume of blood in capillary vessels will be high and then will be low after each heartbeat. So, by changing this volume the LED light is changed. This change in of LED light measures the heartbeat rate of a finger. This phenomenon is known as “Photoplethysmogram.”

Interfacing Pulse Sensor with Arduino

We will require the following components for this tutorial.

Required Components:

  • Arduino board
  • SEN-11574 pulse sensor
  • Connecting Wires

As we know already that the pulse sensor has three pins that we have to connect with our Arduino UNO. These include the GND, VCC, and signal pin.

Follow the table and the schematic diagram below to successfully connect your circuit.

Arduino Pulse Sensor
GNDGND
A0 (ANALOG IN)A0
5VVCC
Arduino UNO with pulse sensor schematic diagram
Arduino UNO with Pulse Sensor

As the pulse sensor requires an operating voltage in the range of 3.3-5V hence we will connect the VCC terminal of the sensor with 5V terminal of Arduino UNO. Both the grounds will be in common. Additionally, the analog signal pin of the sensor will be connected with A0 pin of the Arduino board.

Installing Pulse Sensor Arduino Library

We will use Arduino IDE to program our Arduino UNO. Thus, you should have the latest version of Arduino IDE. Open Arduino IDE and click on Sketch > Library > Manage Libraries

MPU-6050 Install library

The following window will open up.

search library Arduino IDE

Type ‘pulsesensor’ in the search bar and press enter. Install the latest version of the library.

Installing Pulse sensor library

After installation of the library, restart your IDE.

Pulse Sensor Example Sketches for Arduino

In this section, we will show you how to use example sketches available in the Arduino IDE for PulseSensor Playground library that we just installed. We will look at different examples to effectively learn how to use the pulse sensor with our Arduino UNO.

LED blinking with hear beat using Pulse Sensor

Open your Arduino IDE and go to File > Examples > PulseSensor Playground > GettingStartedProject.

The following program code will open. This example sketch will blink the built-in LED of Arduino UNO in synchronization with your heart beat when you hold the sensor in between your fingers.

/*  PulseSensor Starter Project and Signal Tester
 *  The Best Way to Get Started  With, or See the Raw Signal of, your PulseSensor.com™ & Arduino.
 *
 *  Here is a link to the tutorial
 *  https://pulsesensor.com/pages/code-and-guide
 *
 *  WATCH ME (Tutorial Video):
 *  https://www.youtube.com/watch?v=RbB8NSRa5X4
 *
 *
-------------------------------------------------------------
1) This shows a live human Heartbeat Pulse.
2) Live visualization in Arduino's Cool "Serial Plotter".
3) Blink an LED on each Heartbeat.
4) This is the direct Pulse Sensor's Signal.
5) A great first-step in troubleshooting your circuit and connections.
6) "Human-readable" code that is newbie friendly."

*/


//  Variables
int PulseSensorPurplePin = 0;        // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED13 = 13;   //  The on-board Arduion LED


int Signal;                // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 550;            // Determine which Signal to "count as a beat", and which to ingore.


// The SetUp Function:
void setup() {
  pinMode(LED13,OUTPUT);         // pin that will blink to your heartbeat!
   Serial.begin(9600);         // Set's up Serial Communication at certain speed.

}

// The Main Loop Function
void loop() {

  Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value.
                                              // Assign this value to the "Signal" variable.

   Serial.println(Signal);                    // Send the Signal value to Serial Plotter.


   if(Signal > Threshold){                          // If the signal is above "550", then "turn-on" Arduino's on-Board LED.
     digitalWrite(LED13,HIGH);
   } else {
     digitalWrite(LED13,LOW);                //  Else, the sigal must be below "550", so "turn-off" this LED.
   }


delay(10);


}

How the Code Works?

Now let us understand how the code is working.

Firstly, some variables are defined that include the GPIO through which the sensor’s signal pin is connected with. It is A0. Next, the built-in LED’s GPIO pin number is stated. It is GPIO13. The signal variable of data type integer holds the ADC data and the threshold variable will help in differentiating a valid heart beat. By default it is set to 550.

int PulseSensorPurplePin = 0;   
int LED13 = 13;   
int Signal;            
int Threshold = 550;  

setup()

Inside the setup() function, the serial connection is opened at a baud rate of 9600.

 Serial.begin(9600); 

Using the pinMode() function, the built-in LED will be configured as an output pin.

 pinMode(LED13,OUTPUT); 

loop()

Inside the loop() function, first by using analogRead() on the A0 pin the ADC signal data will get saved in the ‘Signal’ variable. This is the same variable that we defined earlier.

Signal = analogRead(PulseSensorPurplePin);

Next, print this value in the serial monitor/serial plotter for debugging purposes and can also be used to set the threshold value.

Serial.println(Signal)

The following lines of code will check whether the value saved in the signal variable is greater than the set threshold value. If it is, then turn the built-in LED ON. Otherwise, turn it OFF.

 if(Signal > Threshold){                    
     digitalWrite(LED13,HIGH);
   } else {
     digitalWrite(LED13,LOW);      
   }
delay(10);

Demonstration

To see the demonstration of the above code, upload the code to Arduino. But, before uploading code, make sure to select the Arduino board from Tools > Board and also select the correct COM port to which the Arduino board is connected from Tools > Port.

select Arduino uno

Once the code is uploaded to Arduino, hold the sensor in between your fingers. Do not hold it very tightly or very lightly. Make sure you apply normal pressure while holding the sensor. This will result in a better clean signal.

The built-in LED of Arduino UNO will start blinking with your heart beat. If for some reason the built-in LED is not blinking properly change the threshold value. The threshold value can take values from 0-1023.

controlling Arduino LED with pulse sensor heartbeat Arduino IDE

Plotting Heart Beat Signal using Pulse Sensor

Now, we will plot the same signal retrieved from the pulse sensor through the Serial Plotter. We are using the same sketch as above. This time, however, we will show you a graph of the user’s pulse.

Once the code is uploaded to Arduino, hold the sensor in between your fingers. Do not hold it very tightly or very lightly. Make sure you apply normal pressure while holding the sensor. This will result in a better clean signal.

Now go to Tools > Serial Plotter and set its baud rate to 9600. On the serial plotter you will be able to see the signal take various values within a certain range. After a while, the signal will stabilize and you will get a clearer heart beat signal. This is the signal that we obtained.

Pulse sensor serial plotter demo
Serial Plotter

Monitoring BPM with Pulse Sensor and Arduino

Open your Arduino IDE and go to File > Examples > PulseSensor Playground > Getting_BPM_to_Monitor. The following program code will open. This example sketch will detect a heart beat and beats per minute (BPM) also known as heart rate. This will be displayed in the serial monitor.

Do not use this BPM monitor for medical purposes as it is not very accurate.

/*  Getting_BPM_to_Monitor prints the BPM to the Serial Monitor, using the least lines of code and PulseSensor Library.
 *  Tutorial Webpage: https://pulsesensor.com/pages/getting-advanced
 *
--------Use This Sketch To------------------------------------------
1) Displays user's live and changing BPM, Beats Per Minute, in Arduino's native Serial Monitor.
2) Print: "♥  A HeartBeat Happened !" when a beat is detected, live.
2) 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.analogInput(PulseWire);   
  pulseSensor.blinkOnPulse(LED13);       //auto-magically blink Arduino's LED with heartbeat.
  pulseSensor.setThreshold(Threshold);   

  // 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("♥  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.

}

  

To see the demonstration of the above code, upload the code to Arduino. But, before uploading code, make sure to select the Arduino board from Tools > Board and also select the correct COM port to which the Arduino board is connected from Tools > Port.

select Arduino uno

Once the code is uploaded to Arduino, hold the sensor in between your fingers. Do not hold it very tightly or very lightly. Make sure you apply normal pressure while holding the sensor. This will result in a better clean signal. Open your serial monitor and set the baud rate to 9600. After a few moments you will be able to see the heart rate.

Pulse sensor BPM demo
Serial Monitor

Processing Visualizing Pulse Sensor Data

Now we will use the processing visualization application to view the user’s heart beat, their BPM and IBI in real time. This will be achieved inside the software where it acquires the signal data from the programmed Arduino UNO connected with the pulse sensor.

In order to use this tool, we just need the PulseSensor_BPM Arduino sketch (available in the PulseSensor Playground library examples) uploaded to our development board. No additional programming or modifications are required. Follow the steps in the given order to successfully set up the application and view the signal.

Open your Arduino IDE and go to File > Examples > PulseSensor Playground > PulseSensor_BPM. The following example sketch will open.

/*
   Code to detect pulses from the PulseSensor,
   using an interrupt service routine.

   Here is a link to the tutorial\
   https://pulsesensor.com/pages/getting-advanced

   Copyright World Famous Electronics LLC - see LICENSE
   Contributors:
     Joel Murphy, https://pulsesensor.com
     Yury Gitman, https://pulsesensor.com
     Bradford Needham, @bneedhamia, https://bluepapertech.com

   Licensed under the MIT License, a copy of which
   should have been included with this software.

   This software is not intended for medical use.
*/

/*
   Every Sketch that uses the PulseSensor Playground must
   define USE_ARDUINO_INTERRUPTS before including PulseSensorPlayground.h.
   Here, #define USE_ARDUINO_INTERRUPTS true tells the library to use
   interrupts to automatically read and process PulseSensor data.

   See ProcessEverySample.ino for an example of not using interrupts.
*/
#define USE_ARDUINO_INTERRUPTS true
#include <PulseSensorPlayground.h>

/*
   The format of our output.

   Set this to PROCESSING_VISUALIZER if you're going to run
    the Processing Visualizer Sketch.
    See https://github.com/WorldFamousElectronics/PulseSensor_Amped_Processing_Visualizer

   Set this to SERIAL_PLOTTER if you're going to run
    the Arduino IDE's Serial Plotter.
*/
const int OUTPUT_TYPE = SERIAL_PLOTTER;

/*
   Pinout:
     PULSE_INPUT = Analog Input. Connected to the pulse sensor
      purple (signal) wire.
     PULSE_BLINK = digital Output. Connected to an LED (and 220 ohm resistor)
      that will flash on each detected pulse.
     PULSE_FADE = digital Output. PWM pin onnected to an LED (and resistor)
      that will smoothly fade with each pulse.
      NOTE: PULSE_FADE must be a pin that supports PWM. Do not use
      pin 9 or 10, because those pins' PWM interferes with the sample timer.
*/
const int PULSE_INPUT = A0;
const int PULSE_BLINK = 13;    // Pin 13 is the on-board LED
const int PULSE_FADE = 5;
const int THRESHOLD = 550;   // Adjust this number to avoid noise when idle

/*
   All the PulseSensor Playground functions.
*/
PulseSensorPlayground pulseSensor;

void setup() {
  /*
     Use 115200 baud because that's what the Processing Sketch expects to read,
     and because that speed provides about 11 bytes per millisecond.

     If we used a slower baud rate, we'd likely write bytes faster than
     they can be transmitted, which would mess up the timing
     of readSensor() calls, which would make the pulse measurement
     not work properly.
  */
  Serial.begin(115200);

  // Configure the PulseSensor manager.

  pulseSensor.analogInput(PULSE_INPUT);
  pulseSensor.blinkOnPulse(PULSE_BLINK);
  pulseSensor.fadeOnPulse(PULSE_FADE);

  pulseSensor.setSerial(Serial);
  pulseSensor.setOutputType(OUTPUT_TYPE);
  pulseSensor.setThreshold(THRESHOLD);

  // Now that everything is ready, start reading the PulseSensor signal.
  if (!pulseSensor.begin()) {
    /*
       PulseSensor initialization failed,
       likely because our particular Arduino platform interrupts
       aren't supported yet.

       If your Sketch hangs here, try PulseSensor_BPM_Alternative.ino,
       which doesn't use interrupts.
    */
    for(;;) {
      // Flash the led to show things didn't work.
      digitalWrite(PULSE_BLINK, LOW);
      delay(50);
      digitalWrite(PULSE_BLINK, HIGH);
      delay(50);
    }
  }
}

void loop() {
  /*
     Wait a bit.
     We don't output every sample, because our baud rate
     won't support that much I/O.
  */
  delay(20);

  // write the latest sample to Serial.
 pulseSensor.outputSample();

  /*
     If a beat has happened since we last checked,
     write the per-beat information to Serial.
   */
  if (pulseSensor.sawStartOfBeat()) {
   pulseSensor.outputBeat();
  }
}

We will modify one line in this example sketch. While defining the OUTPUT_TYPE variable, set it to PROCESSING_VISUALIZER. By default, it was set to SERIAL_PLOTTER.

const int OUTPUT_TYPE = PROCESSING_VISUALIZER;

To see the demonstration of the above code, upload the code to Arduino. But, before uploading code, make sure to select the Arduino board from Tools > Board and also select the correct COM port to which the Arduino board is connected from Tools > Port. Press the upload button to upload the code to your Arduino UNO.

Installing PulseSensor Amped Processing Visualizer

Before proceeding further, make sure you have the latest version of Processing installed on your system. Download it from here (https://processing.org/download)

We will use GitHub to download the processing code and then place it in the Processing Documents folder. First, click here to open the GitHub page to download the code. The webpage when you open the link will look something like this.

Installing Pulse Sensor processing visualizer

Click the Code button and go to the Download Zip option as highlighted in the figure. Your zip file will get downloaded to your computer right away. After the download is complete, extract the .zip file and copy the PulseSensorAmpd_Processing_Visualizer folder inside the Processing Documents folder.

Now open Processing. Go to File > Sketchbook > PulseSensorAmped_Processing_Visualizer. The sketch will open up. Press the run button as shown below.

pulse processing visualizer pic1

Now select the serial port through which your board is connected.

pulse processing visualizer pic2

Now you will be able to view the pulse, the heart rate, and the inter-beat interval (IBI) in real-time.

Conclusion

In conclusion, we have learned about a simple pulse sensor that detected pulse on the basis of light. Through various example sketches from the PulseSensor Playground library, we saw its different features. We monitored the user’s pulse through blinking the onboard LED as well as plotting it in the serial monitor. The heart rate (BPM) was also demonstrated through another example sketch. Additionally, we also used the pulse processing visualizer app to show the BPM, IBI, and pulse in real time.

Have a look at pulse sensor-related articles below:

Leave a Comment