How to Use MAX30100 Arduino as Heart Rate Sensor

What is the MAX30100 sensor?

MAX30100 sensor is a device that is used to monitor the heart rate and it is also used as a pulse oximeter. The Pulse oximeter consists of Light-emitting diodes and an IR sensor. And signal processing unit to improve the quality of the output signal. It works on the input voltage of 1.8V to 3.3V.

How does the MAX30100 sensor module?

Whenever we breathe in oxygen, the oxygen enters our lungs and passed into our blood. The blood carries oxygen to various organs of our body. Blood carries oxygen to our body, by means of hemoglobin. During a pulse oximetry reading, a small clam-like device is attached to our finger, earlobe, or toe.

 

A small beam of light is passed through the finger. This light passes the finger and is used to measure the content of oxygenated or deoxygenated blood.

Working of MX30100 pulse oximeter sensor:

The sensor has two light-emitting diodes and one photodiode. The LED’s are used to emit the light and the photodiode is used to detect and measure the intensity of the received light. In MAX30100 one LED emits monochromatic light and the other LED emits infrared light.

What is the MAX30100 sensor

 

The MAX30100 pulse oximeter can measure both the heart pulse rate and the oxygen level in the blood. The Redlight that the red LED emits is used to measure the pulse rate. And for measuring the oxygen level, both the LEDs are used.

 

 

When the heart pumps the blood, the oxygenated blood is increased in the body. And when the heart relaxes the volume of the oxygenated blood is decreased in the body. As a result, the time variation in the change of the volume of the oxygenated blood, the pulse rate are calculated. (One variation = one pump of the heart). This whole change in the light is detected and measured by the photodiode.

 

The oxygen content is measured by using both the Light-emitting diodes. The oxygenated blood in our body absorbs more infrared light and allows red light to pass through it. And the deoxygenated blood absorbs more red light and allows infrared light to pass through it. The photodiode in the MAX30100 sensor is used to measure the change in the intensity of the light. Using this photodiode, the intensity of the light which is passed into the finger and the through the blood is measured by the photodiode and passes the signal to the analog to digital converter and gives the output data in form of I2c serial communication protocol. And using a microcontroller the pulse rate and the blood oxygen measurement are monitored.

How to interface MAX30100 Pulse oximeter with Arduino?

As we know that the MAX30100 Pulse oximeter sensor works on the I2C communication protocol, we have to find out the I2C pins of our Arduino. In the case of Arduino UNO, A4 and A5 will be the I2C pins. The A4 and A5 are SDA and SCL respectively of the Arduino UNO.

 interface MAX30100 Pulse oximeter with Arduino

 

The connection has to be made as shown in the below diagram. If you are using Arduino UNO.

 

Arduino UNO Side

MAX30100 Side

5V

VIN

GND

GND

A4

SDA

A5

SCL

Code:

The below code is used to display the Pulse and the oxygen reading.

 

#include <Wire.h>

#include "MAX30100_PulseOximeter.h"

 

#define REPORTING_PERIOD_MS     1000

// Create a PulseOximeter object

PulseOximeter pox;

// Time at which the last beat occurred

uint32_t tsLastReport = 0;

// Callback routine is executed when a pulse is detected

void onBeatDetected() {

   Serial.println("Beat!");

}

void setup() {

   Serial.begin(9600);

   Serial.print("Initializing pulse oximeter..");

   // Initialize sensor

   if (!pox.begin()) {

       Serial.println("FAILED");

       for(;;);

   } else {

       Serial.println("SUCCESS");

   }

   // Configure sensor to use 7.6mA for LED drive

   pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

   // Register a callback routine

   pox.setOnBeatDetectedCallback(onBeatDetected);

}

void loop() {

   // Read from the sensor

   Pox update();

   // Grab the updated heart rate and SpO2 levels

   if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

       Serial.print("Heart rate:");

       Serial.print(pox.getHeartRate());

       Serial.print("bpm / SpO2:");

       Serial.print(pox.getSpO2());

       Serial.println("%");

       tsLastReport = millis();

   }

}

 

Explanation:

Let’s start at the top of the example. Two libraries viz. MAX30100_PulseOximeter.h and Wire.h are included, a constant called REPORTING_PERIOD_MS is defined to delay the measurements, PulseOximeter object is created and a variable called tsLastReport is created to store the time at which the last beat occurred.

 

#include <Wire.h>

#include "MAX30100_PulseOximeter.h"

#define REPORTING_PERIOD_MS     1000

PulseOximeter pox;

uint32_t tsLastReport = 0;

 

Next, a callback routine is defined which is executed when a pulse is detected. You can write some interesting code in it, for example, to watch the built-in LED blink with your heartbeat!

 

void onBeatDetected() {

   Serial.println("Beat!");

}

Next let’s look at the setup. There are three functions to point out. First, the pox.begin() function call makes sure that we can communicate with the sensor. begin() function returns 1 on success (or 0 if it fails). It also configures the MAX30100 to begin collecting data.

 

if (!pox.begin()) {

   Serial.println("FAILED");

   for(;;);

} else {

   Serial.println("SUCCESS");

}

 

Secondly and equally as important the setIRLedCurrent() function sets the current through the IR LED. The following line sets the current of 7.6mA through the IR LED.

 

 pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA);

 

By default the library sets the IR LED current to 50mA which can sometimes cause problems like the LED not turning on or getting the Initializing pulse oximeter.. FAILED message on the serial monitor. In that case, set the LED current to a lower value. Here are the other possible values you can use on the setIRLedCurrent() function.

  • MAX30100_LED_CURR_0MA
  • MAX30100_LED_CURR_4_4MA
  • MAX30100_LED_CURR_7_6MA
  • MAX30100_LED_CURR_11MA
  • MAX30100_LED_CURR_14_2MA
  • MAX30100_LED_CURR_17_4MA
  • MAX30100_LED_CURR_20_8MA
  • MAX30100_LED_CURR_24MA
  • MAX30100_LED_CURR_27_1MA
  • MAX30100_LED_CURR_30_6MA
  • MAX30100_LED_CURR_33_8MA
  • MAXlearnedLED_CURR_37MA
  • MAX30100_LED_CURR_40_2MA
  • MAX30100_LED_CURR_43_6MA
  • MAX30100_LED_CURR_46_8MA
  • MAX30100_LED_CURR_50MA

Remember! The higher the current, the brighter the LED and the deeper it reaches your skin. So, you can play with it while you figure it out.

Finally setOnBeatDetectedCallback() registers callback’s the function.

 

 pox.setOnDetectedCallback(onBeatDetected);

In the main loop, the biometric data is collected from the MAX30100 sensor with the update()  function. It pulls data in from sensor FIFO.  (FIFO: The buffer that stores data samples from the sensor. The FIFO has a 16-sample memory bank, which means it can hold up to 16 SpO2 and heart rate samples)

 

 pox.update();


We then print the biometric data on the serial monitor once every second (REPORTING_PERIOD_MS is set to 1000; change it as per your requirement). For this we use millis() instead of delay(). Since delay() pauses the entire code, we cannot get the updated measurement.

 

if (millis() - tsLastReport > REPORTING_PERIOD_MS) {

       Serial.print("Heart rate:");

       Serial.print(pox.getHeartRate());

       Serial.print("bpm / SpO2:");

       Serial.print(pox.getSpO2());

       Serial.println("%");

       tsLastReport = millis();

   }

 

Serial Monitor:

Conclusion:

In this blog, we have learned, how the MAX30100 pulse oximeter sensor works and  interfaced with the Pulse Oximeter sensor with the Arduino microcontroller board. We have seen the components required and the code for reading the heart pulse rate and the volume of oxygen in the blood.

Frequently Asked Questions

1. Which is better MAX30100 or MAX30102?

The MAX30100 comes with a 16-bit FIFO and the MAX30102 comes with a 32-bit FIFO. This means the MAX30102 has higher storage, which is transferred to the microcontroller

2. How do I test my MAX30100 sensor?

The MAX30100 sensor can be tested by running the I2C detect code from Arduino and then printing the MAX30100 values on the serial monitor by running the code mentioned above in the blog. If the values of the Heart rate and the SpO2 value changes to the normal readings (60 to 100 beats per minute and Sp02 as 90-95%), when the finger is placed on the sensor. Then the sensor can be considered as working. If any part of this process fails, then the sensor might be faulty.

Leave a comment

Please note, comments must be approved before they are published