Example Code for Arduino-Display Heart Rate and ECG on LCD12864

This example demonstrates how to display heart rate values and ECG waveforms on an LCD12864 shield using the Heart Rate Sensor in digital mode.

Hardware Preparation

Software Preparation

Wiring Diagram

SEN0203 Heart Rate Monitor Sensor for Arduino Connection Diagram
  • Attach this sensor to Arduino A1
  • Set the sensor mode switch as D (digital)
  • Connect the LCD12864 shield to Arduino

Other Preparation Work

  1. Please download and install the library for LCD12846.
  2. Once you opened the box, you can find a black belt inside of the package. Thread it through the holes of the sensor as indicted in the photo. And then you could attach it on your finger (suggested), wrist or any other places where exposes blood vessels. Do not attach the belt too tight or too loose to your finger or the reading might be not stable. During the test, you should steady your finger and do not move too much, or the readings might be unstable.

1.Thread the belt through the holes

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

2.Wrap on finger

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

3.Wrap on wrist

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

4.Wrap on the back of wrist

SEN0203 Heart Rate Monitor Sensor for Arduino Before start

Sample Code



/*!
* @file HeartrateDisplay
* @brief  Waves of blood oxygen saturation and heart rate value is displayed on the LCD
*
* @brief  Waves of blood oxygen saturation and heart rate value is displayed on the LCD
*
* @author linfeng([email protected])
* @version  V1.1
* @date  2016-8-16
* @version  V1.0
* @date  2015-12-24
*/

#define heartratePin A1
#include "Heartrate.h"
#include "Lcd12864Shield.h"

uint16_t heartrateValue=0,heartrateValueLast=0;
uint8_t count;

Lcd12864Shield lcddisplay(10,9,8,13,11);
Heartrate heartrate(DIGITAL_MODE); ///< ANALOG_MODE or DIGITAL_MODE

char wordDisplay[]=  ///< word
{
0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,
0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,
0x00,0x00,0xC0,0xE0,0xE0,0xE0,0xC0,0x80,
0xC0,0xE0,0xE0,0xE0,0xC0,0x00,0x00,0x00,///< ♥
};
char letterDisplay[]= ///< character
{

0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,///< 0
0x00,0x10,0x10,0xF8,0x00,0x00,0x00,0x00,
0x00,0x20,0x20,0x3F,0x20,0x20,0x00,0x00,///< 1
0x00,0x70,0x08,0x08,0x08,0x88,0x70,0x00,
0x00,0x30,0x28,0x24,0x22,0x21,0x30,0x00,///< 2
0x00,0x30,0x08,0x88,0x88,0x48,0x30,0x00,
0x00,0x18,0x20,0x20,0x20,0x11,0x0E,0x00,///< 3
0x00,0x00,0xC0,0x20,0x10,0xF8,0x00,0x00,
0x00,0x07,0x04,0x24,0x24,0x3F,0x24,0x00,///< 4
0x00,0xF8,0x08,0x88,0x88,0x08,0x08,0x00,
0x00,0x19,0x21,0x20,0x20,0x11,0x0E,0x00,///< 5
0x00,0xE0,0x10,0x88,0x88,0x18,0x00,0x00,
0x00,0x0F,0x11,0x20,0x20,0x11,0x0E,0x00,///< 6
0x00,0x38,0x08,0x08,0xC8,0x38,0x08,0x00,
0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00,///< 7
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,///< 8
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,///< 9
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00,
0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00,///< =
};



void lcdBegin(void)
{
  lcddisplay.initialLcd(); ///< Enable LCD
  lcddisplay.clearScreen(); ///< Clear LCD
  lcddisplay.drawXLine(48); ///< Draw a horizontal line
  lcddisplay.drawYLine(7); ///< Draw a vertical line
  lcddisplay.drawWord(7,10,0,wordDisplay); ///< Displays a word
  lcddisplay.drawLetter(7,30,10,letterDisplay); ///< Displays a character
}

void setup() {
  Serial.begin(115200);
  lcdBegin();
}

void loop() {
  unsigned char rateValue;
  heartrateValueLast = heartrateValue;
  heartrateValue = heartrate.getValue(heartratePin);  ///< A1 foot sampled values
  count = heartrate.getCnt();
  if(count)
  {
    lcddisplay.drawYLine(count+8,heartrateValue/24,heartrateValueLast/24); ///< Draw a vertical line,Step 24
  }
  else
  {
    lcddisplay.drawYLine(count+8,heartrateValue/24,heartrateValueLast/24);
  }

  rateValue = heartrate.getRate(); ///< Get heart rate value
  if(rateValue)
  {
    lcddisplay.drawLetter(7,50,3,rateValue,letterDisplay);  ///< Display values
    Serial.println(rateValue);
  }
  delay(20);
}

Result

After uploading the code, the LCD12864 screen displays the ECG waveform and heart rate value in real time.
A stable waveform and continuously updated heart rate readings indicate that the sensor is working correctly.

The switch is used to select the working mode of the module, setting the output signal to either Digital or Analog.
The switch setting must match both the code and the wiring. For example, if the switch is set to Analog (A) but the code uses digitalRead() or the module is connected to a digital pin on the Arduino, no valid readings will be obtained. The same issue applies in the opposite configuration.

Was this article helpful?

TOP