Skip to content

Pulse Oximetry Wireling Tutorial

TinyCircuits Pulse Oximetry Sensor Wireling product photo

This Wireling lets you measure your heartbeat, saturated oxygen level, cardiogram data, and even temperature via the MAX30101 pulse sensor. The sensor features internal LEDs, photodetectors, optical elements, and low-noise electronics.

Technical Details

MAX30101 Specs

  • Heart-Rate Monitor and Pulse Oximeter Sensor in LED Reflective Solution
  • Integrated cover glass for optimal, robust performance
  • Programmable sample rate and LED Current for power savings
  • Fast Data output capability: high sample rates
  • Robust motion artifact resilience: high SNR

    TinyDuino Power Requirements

    • Voltage: 3.0V - 5.5V 
    • Power: < mW (Low-Power Mode)
    • Current: 0.7uA, typ (Ultra-Low Shutdown Current)

    Pins Used

    • A5/SCL - I²C Serial Clock line
    • A4/SDA - I²C Serial Data line 

    Dimensions

    • 10mm x 10mm (.39 inches x .39 inches)
    • Max Height (from the lower bottom of Wireling to upper top of pulse sensor) 5.11mm (0.20 inches)
    • Weight: 1 gram (.04 ounces)

    Materials

    Processor Adapter
    *TinyDuino and USB TinyShield Wireling Adapter TinyShield
    *TinyZero Wireling Adapter TinyShield
    *TinyScreen+ Wireling Adapter TinyShield
    WirelingZero N/A
    *RobotZero N/A
    Arduino Wireling Arduino Shield
    Raspberry Pi Wireling Pi Hat

    * These processors have a 32-pin connector and can have multiple Wireling Adapter TinyShields stacked to increase the number of Wireling ports up to a maximum of 32 total Wireling ports.

    In order to interface with Wirelings, you'll need the appropriate number of Wireling Cables and the Wireling.h Library (You can download this from GitHub as linked, or from the Library Manager in the Arduino IDE).

    You will also need the Pulse Sensor Wireling and the included example Arduino Library with examples:

    Wireling Code
    Port 0 Pulse Oximetry Wireling Library & Example Sketch

    Hardware Assembly

    Depending on the development system you choose, you will need to put together a TinyDuino stack using the 32-pin tan connectors, or you will just need to plug in your Wireling into Port 0 using a Wireling Cable. (You can change this port in the included Arduino Sketch using the Wireling.selectPort() function)

    NOTE: Be mindful when inserting Wireling Cables - the connector pins inside the 5-pin connectors on Wirelings can be bent when cables are inserted at an angle.


    Software Setup

    To install the MAX30101 Arduino library, check out our Library Installation Page. Once downloaded, you can navigate to the examples folder and open the MAX30101BasicExample.ino sketch in the Arduino IDE.

    Make the correct Tools selections for your development board. If unsure, you can double check the Help page that mentions the Tools selections needed for any TinyCircuits processor.


    Upload Program

    Upload the program and open the Serial Monitor to view the output data.

    Code
    /*************************************************************************
      MAX30101 Wireling Basic Example
    
      This example prints sensor temperature, BPM, saturated oxygen level, and
      cardiogram output to the Serial Monitor.
    
      BPM and pulse oxygen output is not for medical use!
    
      Original MAX30100 code by Raivis Strogonovs:
      https://morf.lv/implementing-pulse-oximeter-using-max30100
    
      Updated: 4/19/2019 by Ben Rose for TinyCircuits
     *************************************************************************/
    
    #include <Wire.h>
    #include <Wireling.h>
    
    #if defined (ARDUINO_ARCH_AVR)
    #define SerialMonitorInterface Serial
    #elif defined(ARDUINO_ARCH_SAMD)
    #define SerialMonitorInterface SerialUSB
    #endif
    
    #include <MAX30101.h>
    
    MAX30101 pulseSensor = MAX30101();
    int pulseSensorPort = 0;
    
    void setup() {
      SerialMonitorInterface.begin(9600);
      Wire.begin();
      Wireling.begin();
      delay(200);
    
      while (!SerialMonitorInterface && millis() < 5000); //This will block until the Serial Monitor is opened on TinyScreen+/TinyZero platform!
    
      Wireling.selectPort(pulseSensorPort);
      if (pulseSensor.begin()) {
        while (true) {
          SerialMonitorInterface.println("MAX30101 Wireling not detected!");
          delay(1000);
        }
      }
    }
    
    void loop() {
      Wireling.selectPort(pulseSensorPort);
      if (pulseSensor.update()) {
        if (pulseSensor.pulseValid()) {
          SerialMonitorInterface.print(pulseSensor.temperature());
          SerialMonitorInterface.print("\t");
          SerialMonitorInterface.print(pulseSensor.BPM());
          SerialMonitorInterface.print("\t");
          SerialMonitorInterface.print(pulseSensor.oxygen());
          SerialMonitorInterface.print("\t");
          SerialMonitorInterface.println(pulseSensor.cardiogram() * 10.0);
        } else {
          SerialMonitorInterface.print(pulseSensor.temperature());
          SerialMonitorInterface.print("\t");
          SerialMonitorInterface.println("-\t-\t-");
        }
      }
      delay(20);//Polling the sensor too often can cause extra noise. The sensor can buffer about 300ms of data with the default settings.
    }
    

    The Pulse Oximetry basic example will print out four numbers from left to right: temperature in degrees Celsius, BPM, saturated oxygen level, and cardiogram output.

    When first uploaded, the only number printed will be the temperature and then dashes where the other three values should be. To start measuring your BPM, place a finger pad on the sensor where the red LED is shining. The oximetry sensor is very sensitive - so it will take some time and practice to get a proper reading from the sensor. The best method is to hold the sensor steady by securing the Wireling cable with one hand, and then laying a finger from the opposite hand onto the sensor. There is no need to push down on the sensor (too much pressure can lead to bad or no readings!), adding a small amount of pressure so that the finger is fully on the sensor is all that is needed.

    Serial monitor displaying pulse sensor values
    Example Serial Monitor Output

    Once you feel comfortable with your setup and how to get valid pulse sensor readings, you can close the Serial Monitor and open the Serial Plotter. Using the Serial Plotter is especially useful for seeing the cardiogram data:

    Serial plotter displaying pulse sensor values
    Example Serial Plotter Output

    Program Notes

    • TinyDuino, Arduino UNO and other ATmega328P processors have a slower I2C update rate - so data will not be read as quickly as it can from a SAMD21 processor like the WirelingZero, TinyZero, TinyScreen+, and RobotZero
    • The MAX30101 Sensor is very sensitive, so you have to be very still when trying to measure your BPM, saturated oxygen level, or cardiogram output
    • This sensor is not meant for medical use, it is intended to be used for educational purposes and hobbyist projects

    OLED Display Example

    For a wireless pulse-reading project, you can use any of the OLED Display Wirelings and print out the sensor data and cardiogram graph. The below example is included in the MAX30101 examples folder as MAX30101_OLED.ino and can be used with the 0.42" OLED Display Wireling. Follow the port numbers for plugging in the Wirelings:

    Wireling Code
    Port 0 Pulse Oximetry Wireling OLED Display Sketch
    Port 1 0.42" OLED Wireling or 0.96" OLED Wireling

    The program included in the table will work well when displayed on the 0.42" and 0.96" Screen. For using with a 0.69" Wireling Screen, you would need to modify the pixel placements in the program for best results.


    Downloads


    Contact Us

    If you have any questions or feedback, feel free to email us or make a post on our forum. Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it.

    Thanks for making with us!