Webotricks
Published

How to use the heart pulse sensor with Arduino | Heart pulse

In this tutorial, we will learn how to use the heart pulse sensor with Arduino.

BeginnerProtip2 hours90
How to use the heart pulse sensor with Arduino | Heart pulse

Things used in this project

Hardware components

Arduino Uno
×1
OLED display
×1
Jumper Wires
×1

Story

Read more

Code

Code

Arduino
	/*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;
    }
  }
}

Credits

Webotricks
28 projects • 9 followers
Contact

Comments

Please log in or sign up to comment.