How to Use the Heart Pulse Sensor With Arduino | Heart Pulse Monitoring System

by Webotricks in Circuits > Arduino

4 Views, 0 Favorites, 0 Comments

How to Use the Heart Pulse Sensor With Arduino | Heart Pulse Monitoring System

Untitled design (65).png

Hello, welcome back. In this tutorial, we will learn how to use the heart pulse sensor with Arduino. This sensor is designed using an attractive look with a heart logo. Also, it is a small one and very cheap. Therefore, you can buy it and check out your body’s heart pulse rate easily. For that, I will guide you step by step through this tutorial. Also, this sensor is most important for athletes, students and software developers, etc. Keep reading.

The internal structure of this sensor

This sensor is created mainly using two components. That is, the ADPS-9008 light photosensor and the one green LED. Next, on the backside of this sensor, we can see additional components with the LED. Among these, we can see resistors, capacitors, op-amp, and one reverse protection diode. It is very important for beginners.

How heart pulse sensor works?

When your finger is close to the sensor, the green light on the sensor falls on your fingertip, and the light is reflected also towards the sensor. Then, this green light is absorbed into the hemoglobin of the blood. Also, as the amount of blood in our body is constantly pumping, the amount of hemoglobin in the blood also increases or decreases. Therefore, the amount of reflected light also increases or decreases. This difference is captured by the photosensor. (This is known as optical heart rate sensory theory) Finally, we can get this signal as an analog value.

Supplies

OK, let’s learn how this sensor works with Arduino. For that, the required components are given below.


Arduino Uno - Buy Now


OLED display - BUY NOW


Jumper Wires - BUY NOW


Heart pulse sensor

Firstly, identify these components.

Secondly, connect these components.

Thirdly, create the program for this project. It’s given below.

Code explanation

Firstly, library files are included.

#include

#include

#include

#include

Secondly, an object is created for the OLED display

Adafruit_SSD1306 = Adafruit_SSD1306(128, 64, &Wire);

Thirdly, the sensor pin and the high pulse value are defined. After, variables are created to help the program

#define sensor A0

#define Highpulse 540

int sX = 0;

int sY = 60; i

nt x = 0; int Svalue;

int value; long Stime = 0;

long Ltime = 0;

int count = 0;

int Bpm = 0;

In the setup function,

void setup() { //The serial monitor is begun

Serial.begin(9600); //The OLED display is begun webotricks.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x32 delay(1000); //All characters are cleared in the screen

webotricks.clearDisplay(); }

In the loop function,

void loop() { //Gets sensor values S

value = analogRead(sensor);

Serial.println(Svalue); //These values are changed from 0 to 45

value = map(Svalue, 0, 1024, 0, 45); //These are the heartbeat design codes

int y = 60 - value;

if (x > 128) { x = 0;

sX = 0;

webotricks.clearDisplay();

}

webotricks.drawLine(sX, sY, x, y, WHITE);

sX = x; sY = y; x ++; //This is BPM calculate function.

BPM(); //The heartbeat is printed on the screen

webotrickssetCursor(0, 0);

webotricks.setTextSize(2);

webotricks.setTextColor(SSD1306_WHITE);

webotricks.print("BPM :");

webotricks.display();

}

This is the heart pulse calculate function.

void BPM() { if (Svalue > Highpulse)

{

Stime = millis() - Ltime; count++;

if (Stime / 1000 >= 10)

{

Ltime = millis();

Serial.println(count);

webotricks.setCursor(60, 0);

webotricks.setTextSize(2);

webotricks.setTextColor(SSD1306_WHITE);

webotricks.print(count);

webotricks.print(" ");

webotricks.display();

count = 0;

}

}

}

Now, select board and port. After, upload this code to the Arduino board.

Ok, enjoy this project.



/*Heart pulse sensor with Arduino
* https://webotricks.com
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 webotricks = Adafruit_SSD1306(128, 64, &Wire);
#define sensor A0
#define Highpulse 540
int sX = 0;
int sY = 60;
int x = 0;
int Svalue;
int value;
long Stime = 0;
long Ltime = 0;
int count = 0;
int Bpm = 0;
void setup() {
Serial.begin(9600);
webotricks.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x32
delay(1000);
webotricks.clearDisplay();
}
void loop() {
Svalue = analogRead(sensor);
Serial.println(Svalue);
value = map(Svalue, 0, 1024, 0, 45);
int y = 60 - value;
if (x > 128) {
x = 0;
sX = 0;
webotricks.clearDisplay();
}
webotricks.drawLine(sX, sY, x, y, WHITE);
sX = x;
sY = y;
x ++;
BPM();
webotricks.setCursor(0, 0);
webotricks.setTextSize(2);
webotricks.setTextColor(SSD1306_WHITE);
webotricks.print("BPM :");
webotricks.display();
}
void BPM() {
if (Svalue > Highpulse) {
Stime = millis() - Ltime;
count++;
if (Stime / 1000 >= 60) {
Ltime = millis();
Serial.println(count);
webotricks.setCursor(60, 0);
webotricks.setTextSize(2);
webotricks.setTextColor(SSD1306_WHITE);
webotricks.print(count);
webotricks.print(" ");
srituhobby.display();
count = 0;
}
}
}
1