Techatronic
Published

How to make Heart Rate Monitor

This is a mini heart rate monitor that we made using Arduino and a pulse rate sensor.

IntermediateProtip2 hours2,178
How to make Heart Rate Monitor

Things used in this project

Story

Read more

Code

Code for the Project

C/C++
upload this code to the Arduino
#include <Adafruit_SSD1306.h>
#define OLED_Address 0x3C
Adafruit_SSD1306 oled(1);
int x=0;
int lastx=0;
int lasty=0;
int LastTime=0;
int ThisTime;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
#define UpperThreshold 560
#define LowerThreshold 500
void setup() {
oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
oled.clearDisplay();
oled.setTextSize(2);
}
void loop() 
{
if(x>127) 
{
oled.clearDisplay();
x=0;
lastx=x;
}
ThisTime=millis();
int value=analogRead(0);
oled.setTextColor(WHITE);
int y=60-(value/16);
oled.writeLine(lastx,lasty,x,y,WHITE);
lasty=y;
lastx=x;
// calc bpm
if(value>UpperThreshold)
{
if(BeatComplete)
{
BPM=ThisTime-LastTime;
BPM=int(60/(float(BPM)/1000));
BPMTiming=false;
BeatComplete=false;
tone(8,1000,250);
}
if(BPMTiming==false)
{
LastTime=millis();
BPMTiming=true;
}
}
if((value<LowerThreshold)&(BPMTiming))
BeatComplete=true;
// display bpm
oled.writeFillRect(0,50,128,16,BLACK);
oled.setCursor(0,50);
oled.print(BPM);
oled.print( BPM);
oled.display();
x++;
}

Github file

https://github.com/adafruit/Adafruit-GFX-Library/archive/master.zip

Github file

https://github.com/adafruit/Adafruit_SSD1306/archive/master.zip

Credits

Techatronic

Techatronic

72 projects • 122 followers
Electronic engineer

Comments