How to use the heart pulse sensor with Arduino | Heart pulse monitoring system
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.
The PIN diagram of this sensor
OK, let’s learn how this sensor works with Arduino. For that, the required components are given below.
- Arduino UNO board x1 — Our Store / Amazon
- Heart pulse sensor x 1 — Our Store / Amazon
- OLED display x 1 — Our Store / Amazon
- Jumper wires x 1 — Our Store / Amazon
Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.
Step 1
Firstly, identify these components.
Step 2
Secondly, connect these components. For that, use the circuit diagram below.
Step 3
Thirdly, let’s create the program for this project. It’s as follows.
- BusIO library — Download
- SSD1306 — Download
- GFX-library — Download
- The complete program of this project — Download
/*Heart pulse sensor with Arduino
* https://srituhobby.com
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 srituhobby = 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);
srituhobby.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x32
delay(1000);
srituhobby.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;
srituhobby.clearDisplay();
}
srituhobby.drawLine(sX, sY, x, y, WHITE);
sX = x;
sY = y;
x ++;
BPM();
srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.display();
}
void BPM() {
if (Svalue > Highpulse) {
Stime = millis() - Ltime;
count++;
if (Stime / 1000 >= 60) {
Ltime = millis();
Serial.println(count);
srituhobby.setCursor(60, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}
Code explanation
Firstly, library files are included.
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Secondly, an object is created for the OLED display
Adafruit_SSD1306 srituhobby = 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;
int 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
srituhobby.begin(SSD1306_SWITCHCAPVCC, 0x3C);// Address 0x3C for 128x32
delay(1000);
//All characters are cleared in the screen
srituhobby.clearDisplay();
}
In the loop function,
void loop() {
//Gets sensor values
Svalue = 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;
srituhobby.clearDisplay();
}
srituhobby.drawLine(sX, sY, x, y, WHITE);
sX = x;
sY = y;
x ++;
//This is BPM calculate function.
BPM();
//The heartbeat is printed on the screen
srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.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);
srituhobby.setCursor(60, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}
Step 4
Now, select board and port. After, upload this code to the Arduino board.
Ok, enjoy this project. The complete video guide is given below. So, we will meet in the next tutorial.
How to use the heart pulse sensor with Arduino | Heart pulse monitoring system
hello sir , can u send me the circuit diagram for this project
Check this blog