Hey Guys how you doing?
In this article, you will learn about the MAX30100 Pulse Oximeter heart rate monitor sensor, and how we can use it to make a simple Oximeter with ESP32 DEV Board.
So let's get started.
MaterialsFollowing are the things used in this build-
- MAX30100 Sensor module
- ESP32 Wemos D32 pro
- Breadboard
- Jumper Wires
- Arduino nano (optional)
The MAX30100 is integrated pulse oximetry and heart rate monitor sensor made by maxim integrated.
It combines a photodetector, optimized optics, and low-noise analog signal processing to detect pulse oximetry and heart-rate signals when we rest our fingertips on the sensor.
It operates from 1.8V and 3.3V power source. To use this sensor properly, its Module comes with an Onboard Voltage regulator that regulates 5V into 3.3V for optimal working.
It even has an On-Chip Temperature Sensor. The temperature sensor for (optionally) calibrating the temperature dependence of the SpO2 subsystem. The SpO2 algorithm is relatively insensitive to the wavelength of the IR LED, but the red LED’s wavelength is critical to the correct interpretation of the data.
The temperature sensor data can be used to compensate for the SpO2 error with ambient temperature changes.
The MAX30100 integrates red and IR LED drivers to drive LED pulses for SpO2 and HR measurements. The LED current can be programmed from 0mA to 50mA and we can do that by changing the below line in code with given lines.
pox.setIRLedCurrent(MAX30100_LED_CURR_7_6MA); //Current set at 7mA
Here are a few lines for different current levels, the more you increase the current of LED, the more will the glow of LED and accuracy will increase drastically.
- MAX30100_LED_CURR_4_4MA
- MAX30100_LED_CURR_7_6MA
- MAX30100_LED_CURR_11MA
- MAX30100_LED_CURR_14_2MA
- MAX30100_LED_CURR_40_2MA
- MAX30100_LED_CURR_43_6MA
- MAX30100_LED_CURR_46_8MA
- MAX30100_LED_CURR_50MA
Here's its datasheet.
https://datasheets.maximintegrated.com/en/ds/MAX30100.pdf
How does it measure Heart rate and Blood Oxygen LevelSo here's how the MAX30100 Sensor works, it contains two LEDs one red led and one IR Led, Both of these LEDs have different wavelengths (660nm and 880nm).
When we place our finger onto the Sensor, both LED light goes into the fingertip and it gets reflected, a photo sensor picks up this light and calculates how much is the heart rate and what is the blood oxygen level.
This process is known as photoplethysmogram and its widespread use in similar medical equipment.
PCBWAY GiftshopAs for sourcing the Sensor Module, I used PCBWAY's Giftshop for ordering the sensor.
Aside from PCB Services, PCBWAY also has a dedicated components store.
PCBWAY GIFTSHOP is an online marketplace from where we can source all the major electronics stuff, like Arduino boards, Raspberry Pi boards, Modules, sensors, etc.
PCBWAY have this system that lets us purchase anything from their gift shop through beans, Beans are like a redeemable currency or coupons that we get by placing an order on PCBWAY or by sharing your projects in the community to get beans.
Check PCBWAY out for getting great PCB service from here- https://www.pcbway.com/
Correction in Sensor ModuleBefore getting started, we first need to change something in the Sensor module, let me explain what and why.
So this module is based on MAX30100 Sensor and it requires two different voltages to work, one for LED and one for the sensor itself.
In this module, there are three 4.7kOhm Resistors that are connected in between the SDA, SCL, and INT signal lines and 1.8V from the voltage regulator.
If we connect this module with an Arduino or ESP32 Board that takes high logic level (3.3V and 5V).
1.8V Logic Level won't show up on the I2C Bus and this module is practically unusable.
Here's the solution, we cut down the Track between the SOT23 Voltage Regulator and the first resistor, then we add a connection between the first resistor's pad and the other voltage regulator's VCC (3.3V one).
By doing this, this module will show up on I2C Bus and pick up pickup readings from it.
CONNECTION DIAGRAMAs for the connections, I have used an ESP32 Based Lolin D32 Pro Board but you can use any ESP32 Board or even Arduino boards like Nano or UNO.
The connection will stay the same for every Dev Board.
- We add the VCC of the Module to 5V of the Microcontroller
- GND to GND
- SDA of Module to SDA of Microcontroller which was D21 in ESP32
- SCL of Module to SCL of Microcontroller which was D22 in ESP32
As for the Code, I'm using two sketches in this tutorial, first one is for getting the Heat Rate and Blood Oxygen level and the other one is for getting the raw data from both LEDs.
As for the library, we use the MAX30100 Library by OXULLO which can be downloaded from GitHub or you can search the library in library manager and download it from there.
Reading Heartbeat and Blood Oxygen levelFor the first test, we will be measuring the heartbeat per minute and the Blood Oxygen Level.
We first upload this below sketch to the setup and then open the serial monitor.
#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");
}
pox.setIRLedCurrent(MAX30100_LED_CURR_46_8MA);
// 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();
}
}
We place our fingertip on the sensor, make sure to push down the module tightly, and try not to move the fingertip or you'll get false readings. wait for 10 seconds as this is the minimum time that is required for reading to get stabilized.
Reading Raw Readings and Plotting GraphNext, we use the below sketch to get readings from the Module and plot a graph in the Serial Plotter, we again push down the sensor with our fingertip and let the sensor settles down for 10 seconds.
#include <Wire.h>
#include "MAX30100_PulseOximeter.h"
// Create a MAX30100 object
MAX30100 sensor;
void setup() {
Serial.begin(115200);
Serial.print("Initializing MAX30100..");
// Initialize sensor
if (!sensor.begin()) {
Serial.println("FAILED");
for(;;);
} else {
Serial.println("SUCCESS");
}
// Configure sensor
configureMax30100();
}
void loop() {
uint16_t ir, red;
sensor.update();
while (sensor.getRawValues(&ir, &red)) {
Serial.print(red);
Serial.print(", ");
Serial.println(ir);
}
}
void configureMax30100() {
sensor.setMode(MAX30100_MODE_SPO2_HR);
sensor.setLedsCurrent(MAX30100_LED_CURR_50MA, MAX30100_LED_CURR_27_1MA);
sensor.setLedsPulseWidth(MAX30100_SPC_PW_1600US_16BITS);
sensor.setSamplingRate(MAX30100_SAMPRATE_100HZ);
sensor.setHighresModeEnabled(true);
}
Here's the graph and the value of both LEDs are shown in a different colors.
Conclusion and Version 2Here's what I learned whiles tinkering with this setup.
The MAX30100 Sensor is an interesting device, it works on some level but it's not precise enough to be used in a proper DIY Oximeter setup.
As for Version 2, I will be making an Oximeter Setup anyway by using an ESP32 Wroom Module with the MAX30100 Sensor and an OLED display that will show the data readings.
This is it for today folks, I hope this small tutorial was helpful to you guys.
Thanks, PCBWAY for supporting this project, do check out their page for getting all sorts of PCB RElated services for an economic cost.
Thanks again and peace out.
Comments