🌈 ESP32-S3 Rainbow: ZX Spectrum Emulator Board! Get it on Crowd Supply →
View All Posts
read
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi

Building a Heart Rate Monitor with an ESP32-C3 and MAX30102

You know how it is. You buy one cute little module from AliExpress and then think ā€œit looks lonely, I’ll get anotherā€. Before you know it, you’ve got a drawer full of cute little modules. So it’s time to put one of them to work.

The ESP32-C3 Board

I’ve got a bunch of these tiny ESP32-C3 boards kicking around. Let’s take a look at one under the microscope.

The brains of the operation is an ESP32-C3 with built-in flash — four megabytes of it, which is pretty decent.

ESP32-C3 board under the microscope

There’s a 3.3 volt regulator on board, and the soldering looks nicely done. It’s a pretty clean, well-designed little board. The antenna is a ceramic one on the side — though I’ve read a few people saying that on these tiny compact boards you don’t get much Wi-Fi signal due to the antenna placement being a bit too close to the buttons and other components. So we’ll avoid Wi-Fi for this project.

ESP32-C3 board under the microscope

The MAX30102 Heart Rate and Blood Oxygen Sensor

For the actual sensor, I’m using a MAX30102 module — a heart rate and blood oxygen monitoring board that I picked up in a recent AliExpress order.

MAX30102 sensor module

The board has a 3.3 volt boost regulator and a 1.8 volt regulator. Some people have reported finding a 2.8 volt regulator instead of 1.8 on some boards — it’s worth checking yours is correct. Mine was fine.

How the Sensor Works

The really interesting part is the sensor itself. Under the microscope you can see:

Close-up of the MAX30102 sensor

  • Two LEDs behind a window — a red LED and an infrared LED
  • A photodetector with a bunch of DSP processing built in

The outputs from this device are just the value of the red channel and the value of the infrared channel. You stick your finger on top and it detects pulse rate using the red LED and blood oxygen levels using the infrared LED.

When you power it up, you can easily see the red LED. If you cover it up and move the lights away, you can even see a slight glow from the infrared LED — the camera on the microscope picks it up nicely.

MAX30102 LEDs

MAX30102 Infra Red LED

Wiring It Up

The wiring is pretty simple — it’s just I2C plus power:

const byte oxiInt = 2; // pin connected to MAX30102 INT
const int SENSOR_I2C_SDA_PIN = 5;
const int SENSOR_I2C_SCL_PIN = 6;
  • Pin 6 → SCL
  • Pin 5 → SDA
  • Pin 2 → Interrupt (tells us when data is ready)
  • 5V → Vin (the board has its own 3.3V regulator)
  • GND → GND

Wiring diagram

A quick I2C scan confirms everything is connected properly — two devices show up: the I2C display and the heart rate monitor.

The Code

The main loop reads samples from the MAX30102 into a ring buffer, then runs the heart rate and SpO2 algorithms once the buffer is full:

void loop() {
  float n_spo2, ratio, correl;
  int8_t ch_spo2_valid;
  int32_t n_heart_rate;
  int8_t ch_hr_valid;

  // Read UPDATE_STEP new samples into the ring buffer
  for(int32_t n = 0; n < UPDATE_STEP; ++n) {
    readNextSampleIntoRing(data_ready_timeout_us);
  }

  // Need a full buffer before we can calculate
  if(sample_count < BUFFER_SIZE) return;
  buildOrderedWindow();

  // Calculate heart rate and SpO2
  rf_heart_rate_and_oxygen_saturation(
    ordered_ir_buffer, BUFFER_SIZE, ordered_red_buffer,
    &n_spo2, &ch_spo2_valid,
    &n_heart_rate, &ch_hr_valid,
    &ratio, &correl);

  // Median filter smooths out noisy readings
  hr_filter.push(ch_hr_valid ? n_heart_rate : INVALID_HR);
  spo2_filter.push(ch_spo2_valid ? n_spo2 : INVALID_SPO2);

  updateDisplay(filtered_heart_rate, (int32_t)filtered_spo2);
}

The display code is pretty straightforward — just show the heart rate and oxygen percentage on the tiny OLED, or dashes if we don’t have a valid reading:

static void updateDisplay(int32_t hr, int32_t spo2) {
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_10x20_mr);
  u8g2.setCursor(0, 19);
  if (hr >= 30 && hr <= 250) {
    u8g2.printf("HR: %d", (int)hr);
  } else {
    u8g2.print("HR: --");
  }
  u8g2.setCursor(0, 39);
  if (spo2 >= 0 && spo2 <= 100) {
    u8g2.printf("O2: %d%%", (int)spo2);
  } else {
    u8g2.print("O2: --");
  }
  u8g2.sendBuffer();
}

There’s also a nice touch — the on-board LED flashes in time with your heartbeat.

Getting Readings

With the sketch uploaded and the OLED display showing results, it’s time to test.

Heart rate readings on the display

It can be a bit finicky about finger placement — you need to keep it very still. But once it settles, it starts producing results: heart rate and SpO2 percentage.

Comparing to a Commercial Device

The real test — how does it compare to a proper pulse oximeter?

With both running side by side:

  • Heart rate: around 70 BPM on the ESP32-C3, matching the commercial monitor
  • Blood oxygen: 99% on both devices

Side-by-side comparison with commercial pulse oximeter

Not bad at all. The main challenge is keeping your finger positioned accurately without squishing it on — it’s quite easy to lose the reading. But when you get a good contact, the results match up well.

Wrapping Up

The full code is on GitHub. Grab yourself one of these ESP32-C3 modules, a MAX30102 sensor, and a little OLED display, and you can build something equivalent to a commercial pulse oximeter for very little money. It’s a fun project — why not try it out?

Related Posts

Heart Rate Free - just released on the iPhone - Just found an iPhone app that creatively measures your heart rate simply using the flash on your phone. Thought I'd try the neat little tool and was fascinated with it. Can't wait to share more on how it works in an upcoming post.
Look at my shiny crystal balls - Just upgraded my basic AliExpress crystal balls with some tech wizardry - I've thrown in an ESP32-S3-MINI, a mic, and made them battery powered. Thanks to WLED software, they're now smart and responsive! Shared the KiCAD project for fellow tinkerers. Check out my video to see these balls in action!
A Potentially Explosive Error - Just received the new PCBs for the ESP32-TV project and they're looking sharp with only a tiny resistor tweak needed. But I discovered a sneaky, undocumented resistor causing a conflict between the ESP32 and USB2244 over the USB connection. Fixed that, but there's a bigger issue lurking in the design - check the schematic in the video and see if you can spot it before I reveal the explosive mistake!
The PCBs are in production - what have I messed up? - After some stress and trepidation, I finally took the plunge and sent my PCB design off for manufacturing. My design centers around building a large seven-segment clock with LED filaments. Jumping hurdles such as voltages, pin usage, and limiting the load on my power supply, I've settled on the ESP32 as the system's heart and come up with a final circuit design. While doing this, I've quickly realized I could improve my layout and fixed a small mistake. Also, I've prepared for either types of LED filaments - the high-voltage ones or the larger, 3v ones. However, I did bungle up a couple of things on the enable line of the shift registers and board layout. But hey, this is a learning curve, right? Can't wait to get the boards and see what other exciting errors surface!
10 Cent Music Machine - I built a tiny coin‑cell music board around the $0.10 WCH CH32V003J4M6 (8‑pin, 48MHz RISC‑V, 16K flash/2K RAM). The PCB is just 16.3Ɨ11.7mm with a piezo buzzer and transistor, and in standby it sips 7–8µA. I did hit a snag: playback caused 130mA peaks that browned out a CR2032. A LiPo fixed it, but I really wanted coin‑cell, so I upped the buzzer’s base resistor to 10k, dropping peaks to 56mA and average to ~7mA—now it runs happily (and loudly) from a coin cell. Pro tip: if standby bricks programming, wlink can erase via power-off mode. I’m bit‑banging audio, published a simple MIDI→buzzer tool with a 1‑bit SFX generator, and all the code’s on GitHub.

Related Videos

$3 AliExpress Heart Rate and Oxygen Sensor Module - You know how it is—you grab one cute little AliExpress module, then another… so I finally put an ESP32-C3 to work. Under the microscope it looks solid (nice 3.3V reg, ceramic antenna I’m not trusting for Wi‑Fi), and I paired it with a MAX30102 heart-rate/SpO2 sensor. Wired up I2C (SCL pin 6, SDA pin 5, INT to pin 2, 5V in), ran a scan, and boom—two devices found. After some finger-fiddling, the readings matched a commercial oximeter. Code’s on GitHub—cheap, fun, and it works.
Drones and Lasers? - It’s been a while since we’ve done an unbagging, and I’ve clearly been on an AliExpress bender. Big thanks to PCBWay for fueling the chaos. Today’s haul: a pair of tiny ESP32‑C3 OLED modules (no idea why I ordered two, but here we are), a finger pulse/SpO2 sensor, a USB‑C PD trigger with DIP switches that happily serves up 5/9/12/15/20V (1+3 gives 20V—very handy), an INMP441‑compatible MS8625 mic, a surprisingly nice transparent clock with temp/humidity, a couple of rechargeable nightlights that only charge on dumb USB because there are no CC resistors, a laser and matching detector (pew pew!), and, bizarrely, a ā€œsmartā€ insulated tea mug that lights up and says 20°. Lots of little projects to spin out from this lot.
AliExpress Unbagging: ESP32 PCBs, I²C Sensors, COB LED Strips & More - Another massive AliExpress bagging, plus fresh PCBs from PCBWay! I’ve got an ESP32-C3 dev board, an S3 board with a BLDC controller, and matching stencils ready for when the LCSC parts land. Then it’s a pile of fun bits: a laser level, shrimp peeler and kitchen temp probe, a USB boost converter, USB‑to‑UART, I2C current sensor, wood‑penetrating touch sensor, ToF and ultrasonic rangefinders (perfect for a head‑to‑head), I/O expanders, DC motor controller, magnetic stickers, USB sockets, an IR‑controlled RGB plate (tested!), syringes for paste, a sketchy touch dimmer to tear down, a color sensor, and ultra‑thin COB LED strips (lit up nicely). Lots to solder, test, and probably break—in the best possible way.
10Ā¢ MCU Music Hack - CH32V003 - I spun some tiny WCH boards at PCBWay around an 8‑pin MCU (48 MHz, 16k flash, 2k RAM) to beep tunes off a coin cell. I tried hand-soldering, then used my paste-dispensing PCB printer—expired paste still worked great. Standby sips under 8 µA, but it locks out programming; a WLink flash wipe rescued me. Wake draws ~3.3 mA, and audio peaks hit ~130 mA (~13–14 mA average), which browned out the coin cell. A tiny 80 mAh LiPo with a TP4056 (modded to ~100 mA) proved the design, then swapping the buzzer’s base resistor from 1k to 10k tamed it to ~56 mA peak and just over 7 mA average—coin cell friendly and still loud. I’m bit-banging audio for now (PWM/timers later). I also made a quick MIDI-to-note tool and a one-bit SFX generator. These boards are heading into my next project—stay tuned.
Level Shifter Circuit - simulation and real world test. - Hey there! If you're around my age, you'll probably get nostalgic over the sound of old school tape loading on the ZX Spectrum. I took a deep dive into how the data loads, using my oscilloscope to break it all down, and even built a circuit to handle the signal for my ESP32. Throw in some cool simulations using CircuitLab, and I'm all set! Plus, I discovered a neat trick using diodes to perfect the signal. Hands-on and really quite fun!
HELP SUPPORT MY WORK: If you're feeling flush then please stop by Patreon Or you can make a one off donation via ko-fi
Want to keep up to date with the latest posts and videos? Subscribe to the newsletter
Blog Logo

Chris Greening


Published

> Image

atomic14

A collection of slightly mad projects, instructive/educational videos, and generally interesting stuff. Building projects around the Arduino and ESP32 platforms - we'll be exploring AI, Computer Vision, Audio, 3D Printing - it may get a bit eclectic...

View All Posts