Measure heart rate with Arduino

FunduinoPublished on

Den eigenen Herzschlag als Kurve sichtbar machen

Der Puls-Sensor gehört zu den Bauteilen, bei denen das Ergebnis sofort beeindruckt: Zwei Minuten nach dem Hochladen siehst du deinen eigenen Herzschlag als Kurve auf dem Bildschirm.

Dabei ist der Sensor technisch ganz einfach – er liefert nur eine Spannung an einen analogen Eingang, genau wie ein Temperatursensor. In dieser Anleitung stellst du diese Spannung im Seriellen Plotter dar und lässt zusätzlich eine LED im Takt deines Herzens blinken.

Round pulse sensor with three connection cables for a finger
The pulse sensor on the fingertip
Serial plotter with regularly recurring spikes
The voltage curve in the Serial Plotter – the peaks are the individual heartbeats
1 / 2

You need this

Pulse sensor - optical heart rate sensor, 0-5 V analog Pulse sensor - optical heart rate sensor, 0-5 V analog 3,03 € *Item no. F23106819About the product — Pulse sensor - optical heart rate sensor, 0-5 V analog
Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino

All 2 parts together 14,15 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

Material

For this project, you need:

  • 1× microcontroller with a suitable USB cable
  • 1× heart rate sensor (pulse sensor)

Nothing else is needed - the LED already on pin 13 of the microcontroller serves as the display.

How the pulse sensor works

The pulse sensor shines a very bright green LED into the skin and uses a light sensor to measure how much light is reflected back. With each heartbeat, the blood vessels briefly fill more with blood, changing the amount of reflected light.

From the outside, the sensor works as simply as a temperature sensor: It outputs a voltage to an analog input, and with each heartbeat, this value briefly rises. The Arduino software’s Serial Plotter turns this into a curve where you can clearly see each heartbeat.

The pulse sensor is a DIY component, not a medical device. Its readings are suitable for experimentation and learning, not for health assessments.

Serial plotter with regularly recurring spikes
The voltage curve in the Serial Plotter – the peaks are the individual heartbeats

Structure

Three wires are soldered to the back of the sensor and labeled +, −, and S on the circuit board:

  • + → 5V on the Arduino
  • − → GND on the Arduino
  • S → analog input A0

Then attach the sensor to a spot where the LED can shine through to a pulsating blood vessel – the tip of your ring finger or your earlobe are good options.

Round pulse sensor with three connection cables for a finger
The pulse sensor on the fingertip

Make the heartbeat visible

Upload the sketch, then open the following in the Arduino software: Tools the Serial Plotter - not the Serial Monitor.

The plotter first collects a few readings, then automatically adjusts itself so the curve is easy to see. This can take up to ten seconds. If the display isn't clear, try a different part of your body and hold the sensor steady.

Serial plotter with regularly recurring spikes
The voltage curve in the Serial Plotter – the peaks are the individual heartbeats
Sketch: Output a pulse signal and switch the LED in sync
int SensorPin = A0;    // Signal line at analog input A0
int LED = 13;          // The built-in LED on pin 13 is used
int Sensorwert;        // Variable for the sensor reading
int Grenzwert = 520;   // Threshold at which the LED should light up

void setup()
{
  pinMode(LED, OUTPUT); // Pin 13 is an output
  Serial.begin(9600);   // Start serial connection
}

void loop()
{
  // Read the sensor value and store it in the variable "Sensorwert"
  Sensorwert = analogRead(SensorPin);

  // Send the sensor value to the PC via the serial interface
  Serial.println(Sensorwert);

  // If the sensor value is above the threshold ...
  if (Sensorwert > Grenzwert)
  {
    digitalWrite(LED, HIGH); // ... then the LED should light up
  }
  else                       // Otherwise ...
  {
    digitalWrite(LED, LOW);  // ... the LED is off
  }

  delay(10); // Short pause so the readings are easier to see
}

Set the threshold for the LED

Even if the curve already looks good, the LED on pin 13 might not be blinking in the right rhythm yet. If so, the threshold value in the sketch doesn't match your readings.

Check the plotter to see the range of your readings. In our example, they fluctuate between 500 and 530, while the actual heartbeats are between 515 and 525. A threshold of 520 matches these peaks exactly - the LED then lights up in time with the heartbeat.

These numbers depend heavily on the body location and the person. So set the threshold just below your own peak values.

If the threshold is set too low, the LED stays lit continuously; if it is set too high, it stays off. Both are signs that the number needs adjusting - not that the circuit is wired incorrectly.

Serial plotter with regularly recurring spikes
The voltage curve in the Serial Plotter – the peaks are the individual heartbeats

Further information

The next step is to turn the signal into a number: To do this, measure the time between two heartbeats and convert it to beats per minute.

You can find ready-made libraries and detailed background information about this sensor from the manufacturer:

pulsesensor.com

Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.