Arduino Heart Rate Monitor Project

Introduction

The heart rate monitor is a crucial device for health monitoring, measuring heart rate in beats per minute (BPM). In this project, we will build a simple heart rate monitor using an Arduino and a pulse sensor. This guide will walk you through the entire process, from gathering materials to coding and testing the device.

Materials Required

  • Arduino Uno (or any compatible board)
    Arduino Uno
  • Pulse Sensor (e.g., Pulse Sensor Amped)
    Pulse Sensor
  • Breadboard
    Breadboard
  • Jumper Wires
    Jumper Wires
  • LED (optional)
    LED
  • Resistor (10k ohm)
  • 220-ohm Resistor (for the LED, optional)
  • USB Cable (for Arduino)
  • Arduino IDE (installed on your computer)

Circuit Diagram

Below is the circuit diagram illustrating how to connect the components:

Circuit Diagram

Pin Connections

Make the following connections between the components and the Arduino:

Component Connection
Pulse Sensor
  • VCC5V (Arduino)
  • GNDGND (Arduino)
  • SignalA0 (Analog pin on Arduino)
LED (optional)
  • Anode (+)Digital Pin 13 (Arduino)
  • Cathode (-)220-ohm ResistorGND

Arduino Code

Copy and paste the following code into your Arduino IDE:


// Define the pin for the pulse sensor
const int pulsePin = A0; // Pulse Sensor is connected to analog pin A0
const int ledPin = 13;    // LED is connected to digital pin 13

int signal;               // Variable to store the pulse signal
int threshold = 550;      // Threshold for detecting a heartbeat
int heartRate;            // Variable to store heart rate
long lastBeat = 0;        // Time of the last beat
long beatInterval = 0;    // Interval between beats

void setup() {
  Serial.begin(9600);     // Initialize serial communication
  pinMode(ledPin, OUTPUT); // Set the LED pin as output
}

void loop() {
  signal = analogRead(pulsePin); // Read the pulse signal

  // If the signal is above the threshold, it's a beat
  if (signal > threshold) {
    if (millis() - lastBeat > 200) { // Debounce the beat
      heartRate = 60000 / (millis() - lastBeat); // Calculate heart rate
      lastBeat = millis(); // Update the last beat time
      digitalWrite(ledPin, HIGH); // Turn on the LED (optional)
    }
  } else {
    digitalWrite(ledPin, LOW); // Turn off the LED (optional)
  }

  // Print heart rate to the Serial Monitor
  if (heartRate > 0) {
    Serial.print("Heart Rate: ");
    Serial.print(heartRate);
    Serial.println(" BPM");
  }

  delay(100); // Short delay for stability
}

    

Code Explanation

  • Variables:
    • pulsePin: The analog pin where the pulse sensor is connected.
    • signal: Variable to store the reading from the pulse sensor.
    • threshold: Set the threshold value to detect heartbeats.
    • heartRate: Variable to store the calculated heart rate.
  • Setup Function:
    • Initializes serial communication and sets the LED pin as output.
  • Loop Function:
    • Reads the pulse signal from the sensor.
    • Checks if the signal exceeds the threshold to detect a heartbeat.
    • Calculates the heart rate based on the time interval between beats.
    • Prints the heart rate to the Serial Monitor.

Testing Your Heart Rate Monitor

1. Upload the code to your Arduino.

2. Open the Serial Monitor (Ctrl + Shift + M) in the Arduino IDE.

3. Place the pulse sensor on your fingertip or earlobe.

4. Observe the heart rate displayed in the Serial Monitor.

Conclusion

You have successfully built a simple heart rate monitor using Arduino. This project is a great introduction to working with sensors and can be expanded upon in various ways, such as adding an LCD to display the heart rate or logging data over time.

References

Comments