SparkFun Pulse Oximeter and Heart Rate Monitor Hookup Guide

Pages
Contributors: Elias The Sparkiest
Favorited Favorite 7

Example 1: Config BPM Mode 1

In this first example, we'll read the heart rate and and blood oxygen level of the person we're monitoring. We'll also look at two other important values that the SparkFun Pulse Oximeter and Heart Rate Monitor provides so that you can ascertain whether the heart rate is accurate and whether a finger is being detected. Open the example up by heading to File > Examples > SparkFun Bio Sensor Hub Library > Example1_config_BPM_Mode1.ino .

Let's start at the top of Example 1: Config BPM Mode 1. Of note here, is that when we create an instance of the library called bioHub, we provide the SparkFun Pulse Oximeter's address but also the pin numbers used on the Arduino that the the RESET and MFIO are attached to: pin 4 and 5 respectively. These pins are necessary for the board's function, so make sure they're included here and also put in the correct order: RESET then MFIO pin.

language:c
#include <SparkFun_Bio_Sensor_Hub_Library.h>
#include <Wire.h>

// No other Address options.
#define DEF_ADDR 0x55

// Reset pin, MFIO pin
const int resPin = 4;
const int mfioPin = 5;

// Takes address, reset pin, and MFIO pin.
SparkFun_Bio_Sensor_Hub bioHub(resPin, mfioPin); 

bioData body;  

Just above you'll see this funky type called bioData. This is a type that is unique to the SparkFun Pulse Oximeter and Heart Rate Monitor and it holds all the Biometric data of the sensor: Heart rate, confidence, blood oxygen levels, finger detection, led data, etc. I've provided a table just above that describes all the available information that it holds (see Reference Tables and Sensor Settings). Later in the example, we'll see how it's used.

Next let's look at the setup. There are two functions to point out. First, the bioHub.begin() function call makes sure that we can communicate with the sensor. Secondly and equally as important bioHub.configBPM(MODE_ONE), configures the SparkFun Pulse Oximeter's settings and enables all of the necessary algorithms within the sensor to begin collecting data. Which data is collected depends on how the sensor is configured. You'll get biometric data with bioHub.configBPM(), you can just get LED data with bioHub.configSensor(), or you can get all the data with bioHub.configSensorBPM(). As soon as this is called, the sensor will begin collecting data. However, the sensor lags a couple of seconds behind when it begins sensing the data and when it actually gives that data to the user. I've put a four second delay at the end of setup to give some time for the data to catch up.

language:c
void setup(){

  Serial.begin(115200);

  Wire.begin();
  int result = bioHub.begin();
  if (!result)
    Serial.println("Sensor started!");
  else
    Serial.println("Could not communicate with the sensor!!!");

  Serial.println("Configuring Sensor...."); 
  int error = bioHub.configBpm(MODE_ONE); // Configuring just the BPM settings. 
  if(!error){
    Serial.println("Sensor configured.");
  }
  else {
    Serial.println("Error configuring sensor.");
    Serial.print("Error: "); 
    Serial.println(error); 
  }
  // Data lags a bit behind the sensor, if you're finger is on the sensor when
  // it's being configured this delay will give some time for the data to catch
  // up. 
  delay(4000); 

}

In the main loop, the biometric data is collected from the SparkFun Pulse Oximeter and Heart Rate Monitor with the function bioHub.readBpm(), and it's saved to body. Now to get at that information, we call body.heartrate, body.oxygen, etc. Easy!

language:c
void loop(){

    // Information from the readBpm function will be saved to our "body"
    // variable.  
    body = bioHub.readBpm();
    Serial.print("Heartrate: ");
    Serial.println(body.heartRate); 
    Serial.print("Confidence: ");
    Serial.println(body.confidence); 
    Serial.print("Oxygen: ");
    Serial.println(body.oxygen); 
    Serial.print("Status: ");
    Serial.println(body.status); 
    delay(250); // Slowing it down, we don't need to break our necks here.
}

A note on body.confidence and body.status. The confidence level is the sensor's confidence in the heart rate that was reported. The status is whether or not the sensor has detected a finger. See the table above for the four possible status numbers and what they mean.