Heart rate monitor with OLED
Build it step by step
0 of 4 doneWire the I2C bus
Both modules share 3V3, GND, SDA on GPIO21 and SCL on GPIO22.
Upload
Upload at 115200 baud. The OLED should say "Place your finger".
Measure
Rest your fingertip on the sensor with light, steady pressure. Keep still for 10 to 15 s.
Compare
Count your pulse at the wrist for 30 s and double it. Compare with the screen.
How do you build a heart rate monitor with OLED?
A MAX30102 sensor reads your pulse from a fingertip and an ESP32 shows beats per minute on an OLED. You need ESP32 DevKit V1, MAX30102 pulse oximeter and heart rate sensor, SSD1306 OLED Display, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 4 steps and about 75 minutes.
- Level
- Intermediate
- Time
- About 75 min
- Parts
- 6
Wiring
| From | To | Why |
|---|---|---|
| MAX30102 VIN / GND | ESP32 3V3 / GND | Sensor power |
| MAX30102 SDA / SCL | ESP32 GPIO21 / GPIO22 | I2C (address 0x57) |
| OLED VCC / GND | ESP32 3V3 / GND | Display power |
| OLED SDA / SCL | ESP32 GPIO21 / GPIO22 | Same I2C bus (address 0x3C) |
Code
Arduino IDE with the ESP32 board package. Install "SparkFun MAX3010x Pulse and Proximity Sensor Library" and "Adafruit SSD1306".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include "MAX30105.h"
#include "heartRate.h"
#include <Adafruit_SSD1306.h>
MAX30105 sensor;
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
const byte N = 4;
byte rates[N]; byte spot = 0;
long lastBeat = 0; int avg = 0;
void setup() {
Serial.begin(115200);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextColor(SSD1306_WHITE);
if (!sensor.begin(Wire, I2C_SPEED_FAST)) { Serial.println("MAX30102 not found"); while (true) delay(100); }
sensor.setup(); // library defaults
sensor.setPulseAmplitudeRed(0x0A); // red LED low: we only need IR here
}
void loop() {
long ir = sensor.getIR();
if (checkForBeat(ir)) {
long dt = millis() - lastBeat; lastBeat = millis();
float bpm = 60000.0 / dt;
if (bpm > 40 && bpm < 200) {
rates[spot++ % N] = (byte)bpm;
avg = 0; for (byte i = 0; i < N; i++) avg += rates[i]; avg /= N;
}
}
static unsigned long drawn = 0;
if (millis() - drawn > 250) {
drawn = millis();
oled.clearDisplay(); oled.setTextSize(1); oled.setCursor(0, 0);
oled.print(ir < 50000 ? "Place your finger" : "Hold still...");
oled.setTextSize(3); oled.setCursor(0, 24);
if (ir >= 50000 && avg) { oled.print(avg); oled.setTextSize(1); oled.print(" BPM"); }
oled.display();
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| No finger | "Place your finger", IR reading under 50000 |
| Finger resting on the sensor | After about 10 s a BPM between 50 and 100 at rest |
| Compared with a wrist count | Within about 5 BPM when you keep still |
If it does not work
"MAX30102 not found"
Check SDA/SCL and 3V3. Some boards need the 3.3 V / 1.8 V jumper set to 3.3 V.
Numbers jump around
Press more lightly and keep still. Movement and room light disturb the signal.
Not a medical device
This shows how pulse sensing works. Never use it to make health decisions.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the heart rate monitor with OLED?
ESP32 DevKit V1, MAX30102 pulse oximeter and heart rate sensor, SSD1306 OLED Display, Breadboard 830 Tie Points, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).
How long does the heart rate monitor with OLED take to build?
About 75 minutes for a intermediate maker, in 4 steps.
How do I know the heart rate monitor with OLED works?
No finger: "Place your finger", IR reading under 50000. Finger resting on the sensor: After about 10 s a BPM between 50 and 100 at rest. Compared with a wrist count: Within about 5 BPM when you keep still.
MAX30102 not found: what should I check?
Check SDA/SCL and 3V3. Some boards need the 3.3 V / 1.8 V jumper set to 3.3 V.
Numbers jump around: what should I check?
Press more lightly and keep still. Movement and room light disturb the signal.
Not a medical device: what should I check?
This shows how pulse sensing works. Never use it to make health decisions.
