Practical Bench / Sensing, Optics & Medical · Intermediate · 75 min
Pulse sensor heart-rate meter (PPG)
Read the pulse waveform from an analog optical sensor, detect beats with a simple adaptive threshold, compute BPM and compare against a manual count.
Why it matters
Fitness bands, pulse oximeters and hospital finger clips use photoplethysmography: light through skin changes slightly with every heartbeat.
Toy or everyday hack
A cheap pulse sensor module costs less than a toy; the bright green LED on it is the light source
Safety
- Educational only. This is not a medical device and must not be used for diagnosis or to make health decisions.
- Power the setup from a laptop on battery or a power bank while a sensor touches skin. Do not use any mains-powered adapter of unknown quality.
- Do not tighten the strap enough to cut off blood flow. Use light pressure only.
- Get permission from every volunteer and do not store personal readings.
Parts list
| Part | Qty | Note |
|---|---|---|
| Arduino Uno or compatible | 1 | |
| Analog pulse sensor module (green LED + photodiode) | 1 | |
| Jumper wires | 3 | |
| Velcro strap or tape | 1 | To hold the sensor on a fingertip |
Tools and equipment
Connections
| From | To | Note |
|---|---|---|
| Sensor VCC (+) | Arduino 5 V | Some modules accept 3.3 V as well |
| Sensor GND (−) | Arduino GND | |
| Sensor signal (S) | Arduino A0 |
What you should see
The waveform shows a sharp rise and a slower fall per beat. BPM from the sensor should agree with a manual count within a few beats per minute when the finger is still. Movement, strong ambient light and cold fingers are the main sources of error.
Step by step
- Wire the sensor. Upload the sketch and open the Serial Plotter at 115200 baud to see the signal.
- Rest the sensor lightly on the fingertip pad. Keep the hand still and warm. You should see a clean wave with one peak per heartbeat.
- Open the Serial Monitor and read the BPM printed after about 10 beats.
- At the same time, count your own pulse at the wrist for 30 seconds and multiply by 2. Record both values.
- Repeat for three states: resting, after 20 seconds of light exercise and after 2 minutes of rest.
- Enter each trial in the logbook and review the mean absolute error.
Challenge: Log 60 seconds of BPM and compute the beat-to-beat variation. Explain why a smoother average hides fast changes.
Code (Arduino Uno (or compatible), Arduino IDE)
Check pin numbers against your board. Test the sketch on your own hardware before a class demo.
// Practical 6 - Pulse (PPG) heart-rate meter (Arduino Uno + analog pulse sensor on A0)
// Educational only. NOT a medical device.
const uint8_t SENSOR_PIN = A0;
const uint16_t SAMPLE_MS = 10; // 100 samples per second
float smooth = 0, baseline = 0, peak = 0; // three simple filters
bool rising = false;
uint32_t lastBeat = 0;
float bpm = 0;
void setup() { Serial.begin(115200); }
void loop() {
static uint32_t t0 = 0;
if (millis() - t0 < SAMPLE_MS) return;
t0 += SAMPLE_MS;
int raw = analogRead(SENSOR_PIN);
smooth += 0.3f * (raw - smooth); // 1) remove fast noise
baseline += 0.01f * (smooth - baseline); // 2) track slow drift (finger pressure)
float ac = smooth - baseline; // pulse wave now swings around zero
peak = max(ac, peak * 0.995f); // 3) decaying peak = adaptive amplitude
float thr = 0.6f * peak;
if (!rising && peak > 5 && ac > thr) { // beat = rising edge through the threshold
rising = true;
uint32_t now = millis(), ibi = now - lastBeat; // inter-beat interval
if (ibi > 300 && ibi < 2000) { // 30..200 BPM is plausible
float inst = 60000.0f / ibi;
bpm = (bpm == 0) ? inst : 0.8f * bpm + 0.2f * inst;
Serial.print(F("BPM ")); Serial.println(bpm, 0);
}
lastBeat = now;
}
if (rising && ac < 0.3f * thr) rising = false; // re-arm after the pulse falls
}Readings logbook
Type your measured values. Calculated columns and the analysis update as you type, and your entries are saved in this browser.
If it does not work
| Symptom | Likely cause and fix |
|---|---|
| Signal is flat or noisy | Too much or too little pressure, cold finger, or sensor facing bright light. Shield from ambient light and hold still. |
| BPM is double the real value | The threshold counts the dicrotic notch as a second peak. Raise the 0.6 factor in the sketch. |
| BPM is zero | Peak amplitude below the minimum of 5 counts. Improve contact or move to a lower-noise supply. |
| Values jump | Finger moved. Use a strap and rest the hand on a table. |