The Pulse Sensor is a well-designed low-power plug-and-play heart-rate sensor for the Arduino. Anyone who wants to incorporate real-time heart-rate data into their work—students, artists, athletes, makers, and game and mobile developers—can benefit from it.

The best part is that this sensor plugs right into Arduino and easily clips onto a fingertip or earlobe. It is also super small (button-shaped) and has holes for sewing into fabric.

Did you know?

Pulse Sensor is an open source device developed by PulseSensor.com. They began in 2011 as a Kickstarter project. As of 2013, 491 backers had pledged $18,418 to help bring this project to life.

Hardware Overview

The front of the sensor, with the heart logo, is where you put your finger. You’ll also notice a tiny circular opening through which the Kingbright’s reverse mounted green LED shines.

pulse sensor front side hardware overview

Just beneath the circular opening is a small ambient light photo sensor – APDS-9008 from Avago. This sensor is similar to the ones used in cell phones, tablets, and laptops to adjust the screen’s brightness based on the ambient lighting conditions.

On the back of the module are an MCP6001 Op-Amp from Microchip and a few resistors and capacitors that make up the R/C filter network. Additionally, there is a reverse protection diode to prevent damage in the event that the power leads are accidentally reversed.

pulse sensor back side hardware overview

The module requires a DC power supply ranging from 3.3 to 5V and draws less than 4mA of current.

Technical Specifications

Here are the technical specifications:

Maximum RatingsVCC3.0 – 5.5V
IMax (Maximum Current Draw)< 4mA
VOut (Output Voltage Range)0.3V to Vcc
WavelengthLED Output565nm
Sensor Input525nm
DimensionsL x W (PCB)15.8mm (0.625″)
Lead Length20cm (7.8″)

How Does a Pulse Sensor Work?

The theory behind optical heart-rate sensors is very simple. If you’ve ever shined a flashlight through your fingers and observed your heartbeat pulsing, the concept of optical heart-rate pulse sensors can be easily grasped.

light sensor led pulse detection photoplethysmogram

A pulse sensor, like any other optical heart-rate sensor, works by shining a green light (~ 550nm) on the finger and measuring the amount of reflected light with a photosensor.

This optical pulse detection technique is known as a Photoplethysmogram.

pulse detection heart rate sensor working photoplethysmogram

The oxygenated hemoglobin in arterial blood has the property of absorbing green light. The redder the blood (the higher the hemoglobin), the greater the absorption of green light. With each heartbeat, blood is pumped through the finger, causing a change in the amount of reflected light, which in turn produces a waveform at the photosensor’s output.

As you keep shining light and taking photosensor readings, you quickly begin to obtain a heart-beat pulse reading.

This signal from the photosensor is typically small and noisy; therefore, it is passed through an R/C filter network and then amplified with an Op-Amp to create a signal that is significantly larger, cleaner, and easier to detect.

Pulse Sensor Pinout

The sensor comes with a 24″ flat ribbon cable with three male header connectors. The pinout is shown in the figure below.

pulse sensor pinout

S (Signal) is the signal output. Connects to analog input of an Arduino.

+ (VCC) is the VCC pin. Connects to 3.3 or 5V.

– (GND) is the Ground pin.

Warning:

Many times, the cable is not color coded, so check the markings on the back of the module to ensure that you have the correct identification of the three wires.

Wiring a Pulse Sensor to an Arduino

Connecting the Pulse Sensor to an Arduino is a breeze. You only need to connect three wires: two for power and one for reading the sensor value.

The module can be supplied with either 3.3V or 5V. Positive voltage is connected to ‘+,’ while ground is connected to ‘-.’ The third ‘S’ wire is the analog signal output from the sensor, which will be connected to the Arduino’s A0 analog input.

The following is the wiring diagram for the Pulse Sensor experiments:

wiring connecting pulse sensor with arduino

Library Installation

To run the following sketches, you must first install the ‘PulseSensor Playground’ library.

To install the library, navigate to Sketch > Include Library > Manage Libraries… Wait for the Library Manager to download the libraries index and update the list of installed libraries.

manage libraries

Filter your search by entering ‘pulsesensor’.There should only be a single entry. Click on that and then choose Install.

pulse sensor library installation

PulseSensor Example Sketches

The PulseSensor library includes several example sketches. We’ll go over a few of them here, but you can also experiment with the others.

To access the example sketches, navigate to File > Examples > PulseSensor Playground.

You will see a selection of example sketches. You can choose any of them to load the sketch into your IDE. Let’s start off with the GettingStartedProject.

pulse sensor example sketches

Load the GettingStartedProject sketch from the example sketches into your Arduino IDE. This is a basic Arduino sketch. Upload the code to your Arduino and clip the sensor to your earlobe or fingertip. You should see the Arduino’s onboard LED blink in time with your heartbeat!

int const PULSE_SENSOR_PIN = 0;   // 'S' Signal pin connected to A0

int Signal;                // Store incoming ADC data. Value can range from 0-1024
int Threshold = 550;       // Determine which Signal to "count as a beat" and which to ignore.

void setup() {
	pinMode(LED_BUILTIN,OUTPUT);  // Built-in LED will blink to your heartbeat
	Serial.begin(9600);           // Set comm speed for serial plotter window
}

void loop() {

	Signal = analogRead(PULSE_SENSOR_PIN); // Read the sensor value

	Serial.println(Signal);                // Send the signal value to serial plotter

	if(Signal > Threshold){                // If the signal is above threshold, turn on the LED
		digitalWrite(LED_BUILTIN,HIGH);
	} else {
		digitalWrite(LED_BUILTIN,LOW);     // Else turn off the LED
	}
	delay(10);
}

Code Explanation

The sketch is extremely simple. It starts with defining the pin used to connect the Pulse Sensor. Two variables are also defined; the Signal variable holds the incoming ADC data and the Threshold variable determines which signal to “count as a beat” and which signal to disregard.

int const PULSE_SENSOR_PIN = 0;

int Signal;
int Threshold = 550;

In the setup, we configure the onboard LED pin (pin 13) to act as an output and set up the serial monitor.

void setup() {
	pinMode(LED_BUILTIN,OUTPUT);
	Serial.begin(9600);
}

In the loop, we read the analog signal from the Pulse Sensor and activate the onboard LED when the signal exceeds a threshold value.

void loop() {
	Signal = analogRead(PULSE_SENSOR_PIN); // Read the sensor value

	if(Signal > Threshold){                // If the signal is above threshold, turn on the LED
		digitalWrite(LED_BUILTIN,HIGH);
	} else {
		digitalWrite(LED_BUILTIN,LOW);     // Else turn off the LED
	}
	delay(10);
}

Trouble Seeing a Heartbeat?

Here’s what to do if you’re having trouble seeing a heartbeat.

  1. If you hold the sensor too tightly, you will squeeze all the blood from your fingers and there will be no sign! If you hold it too lightly, you will invite noise from movement and ambient light. Sweat Spot pressure (neither too hard nor too soft) on the pulse sensor will produce a good, clean signal.
  2. Variations in pressure can affect the blood flow in your finger, resulting in inaccurate sensor readings. Try to maintain constant pressure by securing the sensor to your finger with a rubber band or other tightening device.
  3. Test the sensor on different parts of your body that have capillary tissue (such as earlobe or lower lip).
  4. Try adjusting the threshold value. You’re free to pick a value for the threshold anywhere from 0 to 1023, but it’s recommended that you tweak it in increments of 5 or 10. Lowering the threshold makes the sensor more sensitive, and vice versa. Try experimenting with different threshold values until you find one that works better.

Arduino Example 2 – Heart Beat Plotting

The previous GettingStartedProject sketch is designed to work with the Arduino Serial Plotter – a nice tool included with the Arduino IDE for visualizing analog signals in real-time.

While the sketch is running and your Arduino board is connected to your computer via USB, navigate to Plotter > Serial Plotter

The signal might take a while to stabilize, but once it does, you should see something similar.

pulse sensor heart rate plotting on arduino serial monitor

Feel your wrist pulse and watch it mimic the blips.

Arduino Example 3 – Measuring Heart-Rate (BPM)

In our third example, we will attempt to measure heart rate (Beats Per Minute or BPM). Load the Getting_BPM_to_Monitor example from the PulseSensor Playground examples menu into your Arduino IDE.

pulse sensor bpm heart ratemeasurement sketch

This sketch calculates the time between pulses to determine the heart rate and outputs the result to the Serial Monitor.

Warning:

Because this sketch detects heart rate optically, it may produce incorrect results. Please DO NOT USE IT FOR ACTUAL MEDICAL DIAGNOSIS.

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

const int PulseWire = 0;       // 'S' Signal pin connected to A0
const int LED13 = 13;          // The on-board Arduino LED
int Threshold = 550;           // Determine which Signal to "count as a beat" and which to ignore
                               
PulseSensorPlayground pulseSensor;  // Creates an object

void setup() {
	Serial.begin(9600);

	// Configure the PulseSensor object, by assigning our variables to it
	pulseSensor.analogInput(PulseWire);   
	pulseSensor.blinkOnPulse(LED13);       // Blink on-board LED with heartbeat
	pulseSensor.setThreshold(Threshold);   

	// Double-check the "pulseSensor" object was created and began seeing a signal
	if (pulseSensor.begin()) {
		Serial.println("PulseSensor object created!");
	}
}

void loop() {
	int myBPM = pulseSensor.getBeatsPerMinute();      // Calculates BPM

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

	delay(20);
}

The readings won’t make sense right away after you upload the sketch, so try to keep your finger as steady as you can while you wait. You will see something like this.

pulse sensor heart rate bpm measurement sketch output

Processing Visualizer

The Pulse Sensor developers have created software to visualize the Pulse Sensor data on your computer. It is written in the Processing programming language. This software displays all of the data that the Arduino receives from the Pulse Sensor. It plots the user’s heart rate in real time. It also displays the BPM (Beats Per Minute) and plots IBI (Interbeat Interval) over time.

This Processing sketch does not perform any calculations! They are all done on the Arduino board, so to use the visualizer, you must have an Arduino running the PulseSensor_BPM sketch. This software simply reads the Serial Port and visualizes the data.

pulse sensor processing visualizer output

Upload Sketch

Look for PulseSensor_BPM in the File > Examples > PulseSensor Playground examples menu and load it into your Arduino IDE.

pulse sensor processing visualizer arduino sketch

Before running the PulseSensor_BPM sketch, you must change a variable called outputType in the Arduino code to allow your Arduino board to communicate with the visualizer. It is set to SERIAL_PLOTTER by default. It must be changed to PROCESSING_VISUALIZER.

changes in processing visualizer arduino sketch

Upload the Arduino Sketch now. Your board should be ready to send data in the format that the Processing Visualizer prefers!

Installation

Download the Processing code from github. Unzip the download and place the PulseSensorAmpd_Processing_Visualizer folder in your Documents/Processing folder.

Then, launch Processing to access the code through your Sketch folder. Click on File > Sketchbook…, then choose PulseSensorAmped_Processing_Visualizer

pulse sensor processing visualizer sketch

Setup

As soon as the Sketch starts, you will be prompted to select the USB port to which your Arduino board is connected. If you don’t see your Arduino, use the Refresh Serial Ports button to refresh the ports list.

pulse sensor processing visualizer port selection

You will begin to see heartbeat data once you choose the proper port!

Functions

There are a few things you can do while the sketch is running:

  1. Press the ‘s’ key to take a screenshot of the program window. The image will be saved as a .jpg in the sketch folder.
  2. Press the ‘r’ key to reset the data windows to zero.

Login
ADS CODE