MEGA DAS
Published © Apache-2.0

Arduino Heart Beat with ECG Display & Sound

If you want a device that could measure your heart beat and plot its curve trace on an OLED display, then this will be your best guide.

BeginnerFull instructions provided18 hours1,995
Arduino Heart Beat with ECG Display & Sound

Things used in this project

Hardware components

Arduino UNO & Genuino UNO
Arduino UNO & Genuino UNO
×1
ProtoCentral Pulse Oximeter & Heart Rate Sensor based on MAX30100
ProtoCentral Pulse Oximeter & Heart Rate Sensor based on MAX30100
×1
Grove - OLED Display 1.12'' V2
Seeed Grove - OLED Display 1.12'' V2
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Materia 101
Arduino Materia 101
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

STL files

Schematics

Schematic PDF file

GERBER files

Code

Arduino Code

Arduino
/************************************************************************************************************************************************************************                                              
 * - Author               : BELKHIR Mohamed                        *                                               
 * - Profession           : (Electrical Ingineer) MEGA DAS owner   *                                                                                              
 * - Main purpose         : Industrial Application                 *                                                                                 
 * - Copyright (c) holder : All rights reserved                    *
 * - License              : BSD 2-Clause License                   * 
 * - Date                 : 08/15/2019                             *
 * ***********************************************************************************************************************************************************************/
 
 /*********************************** NOTE **************************************/
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:

// * Redistributions of source code must retain the above copyright notice, this
//  list of conditions and the following disclaimer.

// * Redistributions in binary form must reproduce the above copyright notice,
//  this list of conditions and the following disclaimer in the documentation
//  and/or other materials provided with the distribution.

// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED
/*_____________________________________________$$____________$$
__________________________________________$$$__$_$$____$$_$__$$$
_________________________________________$__$__$$__$__$__$$__$__$
_________________________________________$__$$$_$__$$$$__$_$$$_$$
________________________________________$$$$_____$$$__$$$_____$$$$
_______________________________________$__$________$__$________$__$
_______________________________________$__$_________$$_________$__$
________________________________________$$__________$$__________$$$
_______________________________________$__$_____$$$$__$$$$_____$__$
_______________________________________$__$____$$$$$$$$$$$$____$__$
________________________________________$$$$____$$$$$$$$$$____$$$$
_________________________________________$__$____$$$$$$$$____$__$
_________________________________________$__$_____$$$$$$_____$__$
__________________________________________$$$$_____$$$$_____$$$$
___________________________________________$__$_____$$_____$__$
___________________________________________$__$$$________$$$__$
____________________________________________$$$__$______$__$$$
______________________________________________$__$$$__$$$__$
________________________________________$$$$$__$$$__$$__$$$_$$$$
_______________________________________$_____$__$__$$__$__$_____$
_______________________________________$______$__$$__$$__$______$
_______________________________________$_______$__$__$__$_______$
_______________________________________$________$_$$$$_$________$
________________________________________$________$____$________$
_______________________________________$_________$____$_________$
_____________________________________$$_$________$____$________$_$$
____________________________________$__$_________$$$$$$_________$__$
____________________________________$__$___$$$$$$_$__$_$$$$$$___$__$
____________________________________$___$_$____$_$$__$$_$____$_$___$
_____________________________________$__$$____$_$_$__$_$_$____$$__$
______________________________________$__$$$$$ $__$__$__$_$$$$$__$
_______________________________________$______$___$__$___$______$
_______________________________________$_____$____$__$____$_____$
________________________________________$___$_____$__$_____$___$
_________________________________________$$$______$$$$______$$  */

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define UpperThreshold 550
#define LowerThreshold 500
#define OLED_Address 0x3C
Adafruit_SSD1306 oled(1);

const int sensor=A3;
const int Buzzer=9;
const int LEDR=6;
const int LEDG=5;
const int LEDB=3;
int x=0;
int y=5;
int inc=1;
int lastx=0;
int lasty=0;
int LastTime=0;
bool BPMTiming=false;
bool BeatComplete=false;
int BPM=0;
int traceY=0;
int oneBeep=0;

 
void setup() 
{
  pinMode(Buzzer,OUTPUT);
  pinMode(LEDR,OUTPUT);
  pinMode(LEDG,OUTPUT);
  pinMode(LEDB,OUTPUT);
  
  oled.begin(SSD1306_SWITCHCAPVCC, OLED_Address);
  
  oled.clearDisplay();
  oled.setTextSize(2);
  oled.setCursor(3,8);
  oled.print("MEGA DAS");
  oled.display();
  delay(2000);
  oled.clearDisplay();
  digitalWrite(Buzzer,LOW);
  digitalWrite(LEDR,LOW);
  digitalWrite(LEDG,LOW);
  digitalWrite(LEDB,LOW);
  int i =0;
  while(i <300)
  {
    oled.writeLine(lastx,lasty,x,5,WHITE);
    oled.display();
    delay(10);
    lasty=y;
    lastx=x;
    x++;
    i++;
    analogWrite(Buzzer,128);
  }
  oled.clearDisplay();
  x=0;
}
 
 
void loop() 
{
  if(x>127)  
  {
    oled.clearDisplay();
    x=0;
    lastx=x;
  }
 
  int value=analogRead(sensor);
  oled.setTextColor(WHITE);
  int y=60-((value+2)/16);
  oled.writeLine(lastx,lasty,x,y,WHITE);
  lasty=y;
  lastx=x;
  
  if(lasty==1 || lasty==0)
  {
    analogWrite(Buzzer,128);
  }
  else
  {
    analogWrite(Buzzer,0);
  }
  // calc bpm
 
  if(value>UpperThreshold)
  {
    if(BeatComplete)
    {
      BPM=millis()-LastTime;
      BPM=int(60/(float(BPM)/1000));
      BPMTiming=false;
      BeatComplete=false;
    }
    if(BPMTiming==false)
    {
      LastTime=millis();
      BPMTiming=true;
    }
  }
  if((value<LowerThreshold)&(BPMTiming))
  {
    BeatComplete=true;
  }
    // display bpm
    oled.writeFillRect(0,18,128,20,BLACK);
    oled.setCursor(0,18);
    oled.print(BPM);
    oled.print(" BPM");
    oled.display();
  if(BPM<90 && BPM>60)
  {
    analogWrite(LEDR,0);
    analogWrite(LEDG,255);
    analogWrite(LEDB,0);
  }
  if(BPM>85)
  {
    analogWrite(LEDR,255);
    analogWrite(LEDG,0);
    analogWrite(LEDB,0);
  }
  if(BPM<63)
  {
    analogWrite(LEDR,255);
    analogWrite(LEDG,255);
    analogWrite(LEDB,0);
  }
  x+=1;
}

Credits

MEGA DAS

MEGA DAS

16 projects • 144 followers
MEGA Development of Automated System is a free community responsible for creating automated systems standing on robotics engineering field
Thanks to JLCPCB.

Comments

Add projectSign up / Login