आज के समय में health monitoring हर घर की ज़रूरत बन चुकी है। In this tutorial we build a heart rate and pulse monitoring system using an ESP32, a low-cost optical pulse sensor and a 0.96-inch SSD1306 OLED display. The device detects every heartbeat from your fingertip, calculates beats per minute (BPM), shows it on … Read more
Need it ready-made? Buy Ready Project

आज के समय में health monitoring हर घर की ज़रूरत बन चुकी है। In this tutorial we build a heart rate and pulse monitoring system using an ESP32, a low-cost optical pulse sensor and a 0.96-inch SSD1306 OLED display. The device detects every heartbeat from your fingertip, calculates beats per minute (BPM), shows it on the OLED, blinks an LED on each beat and prints the live signal to the Serial Plotter. You get the full components list, a pin-to-pin wiring table, complete working code, step-by-step instructions, troubleshooting tips and an FAQ.
Important: this is an educational hobby project, not a medical device. Do not use it to diagnose or treat any health condition. Also note: a BMP180 is a barometric (air) pressure sensor and cannot measure blood pressure. Real blood pressure measurement needs an inflatable cuff and a calibrated pressure transducer, so this tutorial focuses on heart rate only.
How the Pulse Sensor Works
The common “Pulse Sensor” module (green LED plus ambient light photo-sensor) works on photoplethysmography (PPG). The green LED shines into your fingertip, and the photo-sensor measures how much light is reflected back. Every time your heart pumps, the volume of blood in the capillaries rises for a moment, which changes the reflected light. The module amplifies this into an analog voltage that rises and falls with each heartbeat.
The ESP32 samples this voltage about 100 times per second with its 12-bit ADC (values 0 to 4095). When the signal crosses a threshold on the way up, we count a beat. The time between two beats is the inter-beat interval (IBI) in milliseconds, and the heart rate is simply BPM = 60000 / IBI. To make the number stable, the code uses a running average and ignores intervals that are physically impossible (faster than 200 BPM or slower than 30 BPM).
Components Required
- ESP32 development board (ESP32-WROOM-32 DevKit V1 or similar) – 1
- Pulse Sensor module (analog, 3-pin: +, −, S) – 1
- 0.96-inch SSD1306 OLED display, 128×64, I2C (4-pin: VCC, GND, SCL, SDA) – 1
- Breadboard and male-to-male / male-to-female jumper wires
- Micro-USB (or USB-C) data cable
- Optional: Velcro strap or the ear clip supplied with the sensor for steady contact
Circuit Diagram / Wiring Table (Pin-to-Pin)
Both modules run on 3.3 V, which keeps the pulse sensor output inside the ESP32 ADC range (never feed more than 3.3 V into an ESP32 pin). GPIO34 is used because it is on ADC1, which keeps working when Wi-Fi is on (ADC2 pins do not).
| Module | Module Pin | ESP32 Pin | Notes |
|---|---|---|---|
| Pulse Sensor | + (VCC, red) | 3V3 | Power at 3.3 V only |
| Pulse Sensor | − (GND, black) | GND | Common ground |
| Pulse Sensor | S (Signal, purple) | GPIO34 | Analog input (ADC1_CH6) |
| OLED SSD1306 | VCC | 3V3 | |
| OLED SSD1306 | GND | GND | |
| OLED SSD1306 | SDA | GPIO21 | Default I2C SDA |
| OLED SSD1306 | SCL | GPIO22 | Default I2C SCL |
| On-board LED | — | GPIO2 | Built into most DevKit boards |
Libraries and Board Setup
- Install the ESP32 board package by Espressif: in Arduino IDE open File → Preferences, add
https://espressif.github.io/arduino-esp32/package_esp32_index.jsonto Additional Boards Manager URLs, then install “esp32” from Boards Manager. (Source: espressif/arduino-esp32, LGPL-2.1.) - Adafruit SSD1306 – OLED driver (GitHub, BSD license).
- Adafruit GFX Library – graphics/text functions used by the SSD1306 library (GitHub, BSD license).
Wire.his built into the ESP32 core. The beat-detection logic below is original code written for this tutorial, so no pulse-sensor library is needed.
Complete Arduino Code
// Heart Rate (BPM) Monitor - ESP32 + Pulse Sensor + SSD1306 OLED
// Libraries: Adafruit SSD1306, Adafruit GFX (install from Library Manager)
// Board: "ESP32 Dev Module" (Espressif ESP32 Arduino core)
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const int PULSE_PIN = 34; // Pulse sensor signal (ADC1, input-only pin)
const int LED_PIN = 2; // On-board LED blinks on every beat
int threshold = 2200; // 12-bit ADC (0-4095); tune using Serial Plotter
const int HYSTERESIS = 100;
unsigned long lastBeat = 0;
bool aboveThreshold = false;
float bpmAvg = 0;
void setup() {
Serial.begin(115200);
pinMode(LED_PIN, OUTPUT);
analogReadResolution(12);
Wire.begin(21, 22); // SDA, SCL
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("SSD1306 not found - check wiring/address");
while (true) delay(10);
}
display.clearDisplay();
display.setTextColor(SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.println("Place your finger");
display.println("on the sensor...");
display.display();
}
void loop() {
int signal = analogRead(PULSE_PIN);
unsigned long now = millis();
// Rising edge = heartbeat
if (signal > threshold && !aboveThreshold) {
aboveThreshold = true;
unsigned long ibi = now - lastBeat; // inter-beat interval (ms)
if (lastBeat == 0 || ibi > 300) { // ignore noise (>200 BPM)
if (lastBeat > 0 && ibi < 2000) { // valid range 30-200 BPM
float bpm = 60000.0 / ibi;
bpmAvg = (bpmAvg == 0) ? bpm : (bpmAvg * 0.8 + bpm * 0.2);
}
lastBeat = now;
digitalWrite(LED_PIN, HIGH);
}
}
if (signal < threshold - HYSTERESIS && aboveThreshold) {
aboveThreshold = false;
digitalWrite(LED_PIN, LOW);
}
if (lastBeat > 0 && now - lastBeat > 3000) bpmAvg = 0; // finger removed
static unsigned long lastDraw = 0;
if (now - lastDraw > 500) {
lastDraw = now;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.println("Heart Rate Monitor");
display.setTextSize(3);
display.setCursor(0, 22);
if (bpmAvg > 0) {
display.print((int)bpmAvg);
display.setTextSize(1);
display.print(" BPM");
} else {
display.setTextSize(1);
display.print("No pulse detected");
}
display.display();
Serial.printf("Signal:%d BPM:%.0f\n", signal, bpmAvg);
}
delay(10); // ~100 samples per second
}Code Explanation
- analogReadResolution(12) sets the ADC to 0–4095, so the idle signal sits roughly around 1800–2100 and peaks rise above it.
- Threshold with hysteresis: a beat is counted when the signal goes above
threshold; the next beat can only be counted after the signal drops 100 points below it. This stops one noisy peak from being counted twice. - IBI filter: intervals shorter than 300 ms (above 200 BPM) are ignored as noise, and intervals longer than 2 seconds are not used for BPM.
- Running average:
bpmAvg = bpmAvg*0.8 + bpm*0.2smooths the display so the number does not jump on every beat. - Finger removed: if no beat is detected for 3 seconds the BPM resets and the OLED shows “No pulse detected”.
- The OLED refreshes every 500 ms; drawing more often would slow down sampling.
Step-by-Step Instructions
- Place the ESP32 across the middle of the breadboard so both pin rows are free.
- Connect the 3V3 and GND pins of the ESP32 to the breadboard power rails.
- Wire the pulse sensor: + to 3V3, − to GND, S to GPIO34.
- Wire the OLED: VCC to 3V3, GND to GND, SDA to GPIO21, SCL to GPIO22.
- Install the ESP32 board package and the two Adafruit libraries listed above.
- Open Arduino IDE, select Tools → Board → ESP32 Dev Module and the correct COM port.
- Paste the code, click Upload. If upload hangs at “Connecting…”, hold the BOOT button on the ESP32 until it starts writing.
- Open Tools → Serial Plotter at 115200 baud. Rest your fingertip lightly on the sensor (do not press hard) and watch the waveform.
- Note the typical peak value and the resting value, and set
thresholdto roughly halfway between them. Upload again. - Keep your hand still for 10–15 seconds; the OLED will show a stable BPM. Compare it with counting your pulse at the wrist for 60 seconds.
Troubleshooting
| Problem | Likely Cause | Fix |
|---|---|---|
| OLED stays blank / “SSD1306 not found” | Wrong I2C address or SDA/SCL swapped | Most modules use 0x3C; some use 0x3D. Run an I2C scanner sketch and check wiring. |
| BPM always 0 | Threshold too high or poor finger contact | Check Serial Plotter, lower threshold, cover the sensor from room light. |
| BPM too high (150+ while resting) | Noise counted as beats | Raise threshold or HYSTERESIS; keep the finger still; use a short ground wire. |
| Signal flat at 0 or 4095 | Wrong pin or sensor powered at 5 V | Use GPIO34 and power the sensor from 3V3. |
| Readings unstable with Wi-Fi added later | Using an ADC2 pin | Stay on ADC1 pins (GPIO32–39). |
| Upload fails | Charge-only USB cable or missing driver | Use a data cable; install CP210x or CH340 USB driver. |
Ideas to Extend This Project
- Send BPM to a phone dashboard (Blynk, ThingSpeak or a simple ESP32 web server).
- Upgrade to a MAX30102 sensor to measure both heart rate and SpO2 (blood oxygen) over I2C.
- Add a buzzer that beeps on every beat, or an alert when BPM goes outside a set range.
- Log readings to an SD card or Google Sheets for daily tracking.
Frequently Asked Questions
Can this project measure blood pressure?
No. Blood pressure needs a cuff and a calibrated pressure sensor. The BMP180 or BMP280 measures air pressure, not blood pressure. This project measures heart rate (BPM) only.
Can I use Arduino Uno instead of ESP32?
Yes. Connect the signal to A0, power the sensor at 5 V, use pins A4 (SDA) and A5 (SCL) for the OLED, remove Wire.begin(21, 22) and analogReadResolution(12), and change the threshold to around 550 because the Uno ADC is 10-bit (0–1023).
Why does my reading change when I press harder?
Pressing too hard squeezes blood out of the fingertip and weakens the signal. Rest the finger lightly, or use the ear clip.
How accurate is it?
With a still finger and a tuned threshold it is usually within a few BPM of a manual count, but it is not a certified medical instrument.
Which pins can I use for the sensor?
Any ADC1 pin: GPIO32, 33, 34, 35, 36 or 39. Update PULSE_PIN in the code if you change it.
Related Projects
- ESP32 DHT11 Weather Station with Web Server
- ESP32 Digital Spirit Level with MPU6050
- ESP32 RFID Door Lock with RC522
- LoRa GPS Tracker with ESP32 and NEO-6M
Browse more ESP32 Projects on Arduino Project Hub.
1 thought on “Heart and Pulse Monitoring System using ESP32 and Pulse Sensor”