Website Logo. Upload to /source/logo.png ; disable in /source/_includes/logo.html

Chris Meier

Software Developer and Co-founder of FoodChain

NodeHeart Part 1: Setting Up the Heart Monitor

In this series, we will be building a prototype smart heart monitor. The first part will be setting up the heart monitor with an Arduino.

The Internet of Things is exploding right now when it comes to home automation. However, these are not its limits. I’m fascinated with the Internet of Medical Things and the power that it can bring to healthcare. To further explore this field, I decided to build a smart heart monitor. In this first part I will be building the actual heart monitor. In the second we will look at how to hook it up to the internet and make it a more powerful tool.

For this first part, we will need a few things:

  1. Arduino Uno
  2. USB A-to-B cable to power the Arduino Uno
  3. Heart Monitor Shield from Sparkfun
  4. Four female header pins to connect the heart monitor to the Arduino
  5. Jumper Wires
  6. Heart leads and pads

You can follow the full hookup guide here and get all the code from the heart monitor’s Github. I am putting the must-know sections of each here for ease of reference. The hookup table and lead placement photo is taken from the full guide while the sketches are taken from the heart monitor’s Github.

First, attach the header pins to the heart rate monitor. I used female pins. The Arduino also has female pins, so it will be easy to connect the two with jumper wires.

Second, we will attach the heart monitor to the Arduino Uno accordingly:

Board Label Pin Function Arduino Connection
GND Ground GND
3.3v 3.3v Power Supply 3.3v
OUTPUT Output Signal A0
LO- Leads-off Detect – 11
LO+ Leads-off Detect + 10
SDN Shutdown Not used

Once that is complete, plug the USB cable into the Arduino and then your PC. You can read Sparkfun’s install guide if this is your first time.

images

Place the leads onto your body then plug it into the heart rate monitor. Make sure to attach the pads to the leads prior to putting them on your body:

Upload the sketch to the Arduino:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/******************************************************************************
Heart_Rate_Display.ino
Demo Program for AD8232 Heart Rate sensor.
Casey Kuhns @ SparkFun Electronics
6/27/2014
https://github.com/sparkfun/AD8232_Heart_Rate_Monitor
******************************************************************************/
void setup() {
  // initialize the serial communication:
  Serial.begin(9600);
  pinMode(10, INPUT); // Setup for leads off detection LO +
  pinMode(11, INPUT); // Setup for leads off detection LO -

}

void loop() {

  if((digitalRead(10) == 1)||(digitalRead(11) == 1)){
    Serial.println('!');
  }
  else{
    // send the value of analog input 0:
      Serial.println(analogRead(A0));
  }
  //Wait for a bit to keep serial data from saturating
  delay(1);
}

Here, we are setting the communication to a baud rate of 9600. Data coming from LO- and LO+ is used for detecting “lead-off” signal. This is when an electrode is making poor electrical contact. Since this is not valid data (for our purposes), it can be discarded. We will use a “!” to mark invalid data. Lead-off signal can actually be used to detect respiration rates, but we won’t be doing that here. We will consider anything coming from Analog In Pin A0 as valid data.

We then write a sketch in Processing, which will allow us to read and interpret the data from the heart rate monitor. It is important that Processing 2.2.1 is used. If Processing 3 is used, the map function will return NaN (Not a Number) error and it won’t work. This has to do with loss of back-compatibility, so Processing 2 sketches won’t work and the sketch provided is for Processing 2. You can download it here.

Here is the Processing sketch:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/******************************************************************************
Heart_Rate_Display.ino
Demo Program for AD8232 Heart Rate sensor.
Casey Kuhns @ SparkFun Electronics
6/27/2014
https://github.com/sparkfun/AD8232_Heart_Rate_Monitor
******************************************************************************/
import processing.serial.*;

Serial myPort;        // The serial port
int xPos = 1;         // horizontal position of the graph
float height_old = 0;
float height_new = 0;
float inByte = 0;


void setup () {
  // set the window size:
  size(1000, 400);

  // List all the available serial ports
  println(Serial.list());
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  // set inital background:
  background(0xff);
}


void draw () {
  // everything happens in the serialEvent()
}


void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);

    // If leads off detection is true notify with blue line
    if (inString.equals("!")) {
      stroke(0, 0, 0xff); //Set stroke to blue ( R, G, B)
      inByte = 512;  // middle of the ADC range (Flat Line)
    }
    // If the data is good let it through
    else {
      stroke(0xff, 0, 0); //Set stroke to red ( R, G, B)
      inByte = float(inString);
     }

     //Map and draw the line for new data point
     inByte = map(inByte, 0, 1023, 0, height);
     height_new = height - inByte;
     line(xPos - 1, height_old, xPos, height_new);
     height_old = height_new;

      // at the edge of the screen, go back to the beginning:
      if (xPos >= width) {
        xPos = 0;
        background(0xff);
      }
      else {
        // increment the horizontal position:
        xPos++;
      }

  }
}

Upload the sketch to the Arduino and then run the Processing sketch. A graph should pop up displaying your heart rate. Pretty cool!

images

If you are getting a flat blue line, that means no valid data is coming through. You may have to mess with the lead connection going into the heart monitor to start getting valid data in.

If you are having any more problems, you can head over to the tutorial discussion for more troubleshooting advice.

Next up we will explore hooking the heart rate monitor up to Node.js.