Summary
Learn how to build a heart rate and SpO2 monitor with the MAX30102 and Arduino. We cover the pinout, a MAX30100 comparison, wiring to an Arduino UNO and ESP32, library setup and code, an OLED display add-on, and practical tips for stable readings. A student project, not a medical device.

The MAX30102 is an optical sensor that shines red (660 nm) and infrared (880 nm) light into a fingertip and measures how much of it is reflected back. An Arduino reads these values over I2C at address 0x57 and calculates heart rate and blood oxygen saturation (SpO2) from them.
In this tutorial, we cover the pinout, the MAX30100 comparison, wiring to an Arduino UNO and ESP32, heart rate and SpO2 code, and an OLED display.
Disclaimer: This is a student project, not a medical device. The readings are not calibrated against a certified pulse oximeter. Do not use them to diagnose, monitor or treat any health condition.
What Is the MAX30102?
The MAX30102 is a pulse oximeter and heart rate sensor from Maxim Integrated, now part of Analog Devices. It combines a red LED, an IR LED, a photodetector and an 18-bit ADC in one package that talks to a microcontroller over I2C.
It works on photoplethysmography (PPG). Each heartbeat pushes a small surge of blood into the fingertip, which changes how much light the tissue absorbs. Counting these ripples gives heart rate.
For SpO2, the sensor compares the two colours: oxygen-rich haemoglobin absorbs more infrared light, and oxygen-poor haemoglobin absorbs more red light. Our guide on what a pulse sensor is explains PPG in more detail.

The sensor only measures light. Every number is calculated on the Arduino, so the result depends on the algorithm, the finger placement and how still the finger stays. For other health sensors, see our beginner's guide to biomedical sensors.
Components and Supplies
MAX30102 Pinout and Specs
Most MAX30102 modules have seven pins in a row. We only need four of them: VIN, GND, SDA and SCL.

| Pin | Function | Used here? |
|---|---|---|
| VIN | Power input, 3.3V to 5V | Yes |
| SCL | I2C clock | Yes |
| SDA | I2C data | Yes |
| INT | Interrupt output | Optional |
| IRD | External IR LED drive | No |
| RD | External red LED drive | No |
| GND | Ground | Yes |
| Specification | Value |
|---|---|
| LEDs | Red 660 nm, infrared 880 nm |
| Module supply | 3.3V to 5V (chip core runs at 1.8V) |
| Interface | I2C, up to 400 kHz, address 0x57 |
| ADC resolution | Up to 18-bit |
| Sample rate | 50 to 3200 samples per second |
| FIFO buffer | 32 samples |
| Operating temperature | -40 °C to +85 °C |
Important: Some modules connect their I2C pull-up resistors to the chip's 1.8V supply, which a 5V Arduino UNO may not read reliably. We cover the fix in the wiring section.
MAX30102 vs MAX30100
The MAX30102 is the successor to the MAX30100. Both use red and IR LEDs and the same I2C address, but the MAX30102 has a finer ADC, a larger buffer and a faster sample rate.
| Feature | MAX30102 | MAX30100 |
|---|---|---|
| ADC resolution | Up to 18-bit | Up to 16-bit |
| FIFO buffer | 32 samples | 16 samples |
| Maximum sample rate | 3200 samples/s | 1000 samples/s |
| I2C address | 0x57 | 0x57 |
| Common Arduino library | SparkFun MAX3010x | MAX30100lib (oxullo) |
For new projects, we recommend the MAX30102. The two chips use different registers, so code written for one will not run on the other.
Already have a MAX30100 module? Follow our MAX30100 Arduino heart rate sensor tutorial instead.
Parts list
- 1 x MAX30102 Pulse Oximeter and Heart Rate Sensor Module
- 1 x Arduino UNO (or Nano), or 1 x ESP32 development board
- 1 x 0.96 inch I2C OLED display, 128 x 64, SSD1306 (optional, for the display section)
- Breadboard and jumper wires
- USB cable for your board
- Optional: 2 x 4.7 kΩ resistors, only if your module needs the pull-up fix described below
Wiring to Arduino UNO and ESP32
The MAX30102 needs only four wires. INT, IRD and RD stay unconnected.
| MAX30102 pin | Arduino UNO / Nano | ESP32 (DevKit) |
|---|---|---|
| VIN | 5V | 3.3V |
| GND | GND | GND |
| SDA | A4 | GPIO 21 |
| SCL | A5 | GPIO 22 |
On an ESP32, power the module from 3.3V, because the ESP32's pins are not 5V tolerant. On an Arduino Mega, SDA is pin 20 and SCL is pin 21.

Check the I2C pull-up voltage on your module
Many purple MAX30102 boards pull SDA and SCL up to 1.8V. A 5V UNO often cannot read that as a logic HIGH, so the sketch reports "MAX30102 not found" even when the wiring is correct.
There are two ways to fix this:
- Move the solder jumper. Look for a three-pad jumper near the resistors on the module. Move the solder bridge from the 1.8V side to the 3.3V side.
- Add external pull-ups. Connect a 4.7 kΩ resistor from SDA to 3.3V and another from SCL to 3.3V.
Black modules with built-in level shifting, and ESP32 boards, rarely have this problem.
Library Setup and Code
We use the SparkFun MAX3010x Pulse and Proximity Sensor Library, version 1.1.2. It supports the MAX30102 despite its MAX30105 class name, and it includes a beat detector and Maxim's SpO2 algorithm.
Install the library
- In the Arduino IDE, go to Sketch > Include Library > Manage Libraries.
- Search for
MAX3010xand install SparkFun MAX3010x Pulse and Proximity Sensor Library by SparkFun Electronics. - For an ESP32, also install the ESP32 board package from Tools > Board > Boards Manager.
Code 1: Heart rate (BPM)
This sketch detects each heartbeat in the IR signal and prints the BPM with a four-beat average.
#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"
MAX30105 sensor;
byte rates[4];
byte rateIndex = 0;
long lastBeat = 0;
void setup() {
Serial.begin(115200);
if (!sensor.begin(Wire, I2C_SPEED_FAST)) {
Serial.println("MAX30102 not found");
while (1);
}
sensor.setup(); // default settings
sensor.setPulseAmplitudeRed(0x0A); // dim red LED, IR does the work
}
void loop() {
long ir = sensor.getIR();
if (ir < 50000) { // no finger on the sensor
Serial.println("No finger detected");
return;
}
if (checkForBeat(ir)) {
float bpm = 60000.0 / (millis() - lastBeat);
lastBeat = millis();
if (bpm > 30 && bpm < 220) { // ignore noise
rates[rateIndex++ % 4] = bpm;
int avg = (rates[0] + rates[1] + rates[2] + rates[3]) / 4;
Serial.print("BPM: ");
Serial.print(bpm, 0);
Serial.print(" Avg: ");
Serial.println(avg);
}
}
}
An IR reading below 50,000 means nothing is on the sensor. checkForBeat() flags each pulse peak, and the sketch turns the time between two beats into BPM, discarding values outside 30 to 220.
Code 2: Heart rate and SpO2
SpO2 needs both LEDs and a few seconds of data. This sketch keeps a window of 100 samples (about 4 seconds), adds 25 new samples each second and reruns Maxim's algorithm.
#include <Wire.h>
#include "MAX30105.h"
#include "spo2_algorithm.h"
MAX30105 sensor;
#define BUFFER_LEN 100
// UNO: 16-bit buffers to fit in 2 KB of RAM
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__)
uint16_t irBuffer[BUFFER_LEN], redBuffer[BUFFER_LEN];
#define SHIFT 2
#else
uint32_t irBuffer[BUFFER_LEN], redBuffer[BUFFER_LEN];
#define SHIFT 0
#endif
int32_t spo2, heartRate;
int8_t validSPO2, validHR;
uint32_t lastIR = 0;
void readSamples(byte from, byte to) {
for (byte i = from; i < to; i++) {
while (!sensor.available()) sensor.check();
redBuffer[i] = sensor.getRed() >> SHIFT;
lastIR = sensor.getIR();
irBuffer[i] = lastIR >> SHIFT;
sensor.nextSample();
}
}
void setup() {
Serial.begin(115200);
if (!sensor.begin(Wire, I2C_SPEED_FAST)) {
Serial.println("MAX30102 not found");
while (1);
}
// brightness, averaging, mode 2 (red + IR), sample rate, pulse width, ADC range
sensor.setup(60, 4, 2, 100, 411, 4096);
readSamples(0, BUFFER_LEN);
}
void loop() {
for (byte i = 25; i < BUFFER_LEN; i++) { // keep the newest 75 samples
redBuffer[i - 25] = redBuffer[i];
irBuffer[i - 25] = irBuffer[i];
}
readSamples(75, BUFFER_LEN);
maxim_heart_rate_and_oxygen_saturation(irBuffer, BUFFER_LEN, redBuffer,
&spo2, &validSPO2, &heartRate, &validHR);
if (lastIR < 50000) {
Serial.println("No finger detected");
return;
}
Serial.print("HR: ");
if (validHR && heartRate > 30 && heartRate < 220) Serial.print(heartRate);
else Serial.print("--");
Serial.print(" bpm SpO2: ");
if (validSPO2 && spo2 > 70 && spo2 <= 100) Serial.print(spo2);
else Serial.print("--");
Serial.println(" %");
}
Mode 2 turns on both LEDs, and a 411 µs pulse width gives the full 18-bit resolution. On the UNO, we scale each reading down by 4 to fit 16-bit buffers. This does not change the result, because SpO2 depends on the ratio between the two signals. The sketch prints -- whenever the algorithm marks a result as invalid.
Upload and test
Upload the sketch, open the Serial Monitor at 115200 baud and rest a fingertip lightly on the sensor. Valid readings appear after about 5 to 10 seconds.
Example output (your values will differ):
HR: -- bpm SpO2: -- %
HR: 76 bpm SpO2: 97 %
HR: 75 bpm SpO2: 98 %
No finger detected
The first lines show -- while the buffer fills. Large jumps between lines usually mean the finger moved.
Add an OLED Display
A 0.96 inch SSD1306 OLED turns the project into a standalone monitor. The OLED uses I2C address 0x3C, so it shares the SDA and SCL pins with the MAX30102: connect its VCC, GND, SDA and SCL to the same pins as the sensor.

We use the SSD1306Ascii library instead of Adafruit SSD1306, because the Adafruit library's 1 KB screen buffer leaves too little RAM on an UNO for the SpO2 buffers. Install it from the Library Manager by searching SSD1306Ascii. New to OLEDs? See our 0.96 inch OLED with Arduino and ESP32 guide.
Start from Code 2 and make three changes. Add the library and display object at the top:
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
SSD1306AsciiWire oled;
Start the display at the beginning of setup():
Wire.begin();
oled.begin(&Adafruit128x64, 0x3C);
oled.setFont(System5x7);
Replace the Serial printing at the end of loop(), from Serial.print("HR: ") onwards:
oled.clear();
oled.set2X();
oled.print("HR ");
if (validHR && heartRate > 30 && heartRate < 220) oled.println(heartRate);
else oled.println("--");
oled.print("O2% ");
if (validSPO2 && spo2 > 70 && spo2 <= 100) oled.println(spo2);
else oled.println("--");
Getting Stable Readings
Most problems come from how the finger sits on the sensor, not from the code.
Finger pressure
Rest the fingertip lightly and keep it still. Pressing hard squeezes blood out of the tissue and flattens the pulse. A rubber band or tape gives gentle, even pressure.
Ambient light
Sunlight or a desk lamp can swamp the sensor. Cover the finger and sensor, or build the project into an enclosure.
3.3V logic and power
If the sensor drops out at random, check the pull-up voltage described in the wiring section, and use short wires and a stable supply.
Quick troubleshooting
| Problem | Likely cause | Fix |
|---|---|---|
| "MAX30102 not found" | SDA/SCL swapped or 1.8V pull-ups | Check wiring, then apply the pull-up fix |
| Always "No finger detected" | Weak IR signal | Cover the sensor fully; raise LED brightness |
| BPM jumps around | Movement or heavy pressure | Press lightly and hold still |
| IR value stuck at maximum | Signal saturated | Lower LED brightness to 30 to 40 |
Conclusion
With the readings stable, a natural next step is to use the ESP32's Wi-Fi to send heart rate and SpO2 to a phone or dashboard. Whatever we build on top of it, the MAX30102 stays a learning tool, not a replacement for a certified medical pulse oximeter.









