SparkFun Photodetector (MAX30101) Hookup Guide

Contributors: Santa Claus Impersonator
Favorited Favorite 0

Arduino Library

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

(*Users can also check out the steps shown in the MAX30105 hookup guide. For the heart beat plotter example, the Arduino IDE must be version 1.6.6 or higher.)

We've written a library to easily get setup and take readings from the SparkFun Photodetector -MAX30101 (Qwiic). However, before we jump into getting data from the sensor, let's take a closer look at the available functions in the library. You can install this library through the Arduino Library Manager. Search for SparkFun MAX3010X Arduino Library and you should be able to install the latest version. If you prefer manually downloading the libraries from the GitHub repository, you can grab them here:

Let's get started by looking at the functions that set up the Qwiic Atmospheric Sensor:


In the global scope, construct your sensor object (such as mySensor) without arguments.

MAX30105 mySensor;

Object Parameters and setup()

Rather that passing a bunch of data to the constructor, configuration is accomplished by setting the values of the MAX30105 type in the setup() function. They are exposed by being public: so use the myName.aVariable = someValue; syntax.

Settable variables of the class MAX30105:

// Status Registers
uint8_t MAX30105_INTSTAT1 =     0x00;
uint8_t MAX30105_INTSTAT2 =     0x01;
uint8_t MAX30105_INTENABLE1 =       0x02;
uint8_t MAX30105_INTENABLE2 =       0x03;

// FIFO Registers
uint8_t MAX30105_FIFOWRITEPTR =     0x04;
uint8_t MAX30105_FIFOOVERFLOW =     0x05;
uint8_t MAX30105_FIFOREADPTR =  0x06;
uint8_t MAX30105_FIFODATA =     0x07;

// Configuration Registers
uint8_t MAX30105_FIFOCONFIG =       0x08;
uint8_t MAX30105_MODECONFIG =       0x09;
uint8_t MAX30105_PARTICLECONFIG =   0x0A;    // Note, sometimes listed as "SPO2" config in datasheet (pg. 11)
uint8_t MAX30105_LED1_PULSEAMP =    0x0C;
uint8_t MAX30105_LED2_PULSEAMP =    0x0D;
uint8_t MAX30105_LED3_PULSEAMP =    0x0E;
uint8_t MAX30105_LED_PROX_AMP =     0x10;
uint8_t MAX30105_MULTILEDCONFIG1 = 0x11;
uint8_t MAX30105_MULTILEDCONFIG2 = 0x12;

// Die Temperature Registers
uint8_t MAX30105_DIETEMPINT =       0x1F;
uint8_t MAX30105_DIETEMPFRAC =  0x20;
uint8_t MAX30105_DIETEMPCONFIG =    0x21;

// Proximity Function Registers
uint8_t MAX30105_PROXINTTHRESH =    0x30;

// Part ID Registers
uint8_t MAX30105_REVISIONID =       0xFE;
uint8_t MAX30105_PARTID =           0xFF;    // Should always be 0x15. Identical to MAX30102.

// MAX30105 Commands
// Interrupt configuration (pg 13, 14)
uint8_t MAX30105_INT_A_FULL_MASK =      (byte)~0b10000000;
uint8_t MAX30105_INT_A_FULL_ENABLE =    0x80;
uint8_t MAX30105_INT_A_FULL_DISABLE =   0x00;

uint8_t MAX30105_INT_DATA_RDY_MASK = (byte)~0b01000000;
uint8_t MAX30105_INT_DATA_RDY_ENABLE =  0x40;
uint8_t MAX30105_INT_DATA_RDY_DISABLE = 0x00;

uint8_t MAX30105_INT_ALC_OVF_MASK = (byte)~0b00100000;
uint8_t MAX30105_INT_ALC_OVF_ENABLE =   0x20;
uint8_t MAX30105_INT_ALC_OVF_DISABLE = 0x00;

uint8_t MAX30105_INT_PROX_INT_MASK = (byte)~0b00010000;
uint8_t MAX30105_INT_PROX_INT_ENABLE = 0x10;
uint8_t MAX30105_INT_PROX_INT_DISABLE = 0x00;

uint8_t MAX30105_INT_DIE_TEMP_RDY_MASK = (byte)~0b00000010;
uint8_t MAX30105_INT_DIE_TEMP_RDY_ENABLE = 0x02;
uint8_t MAX30105_INT_DIE_TEMP_RDY_DISABLE = 0x00;

uint8_t MAX30105_SAMPLEAVG_MASK =   (byte)~0b11100000;
uint8_t MAX30105_SAMPLEAVG_1 =  0x00;
uint8_t MAX30105_SAMPLEAVG_2 =  0x20;
uint8_t MAX30105_SAMPLEAVG_4 =  0x40;
uint8_t MAX30105_SAMPLEAVG_8 =  0x60;
uint8_t MAX30105_SAMPLEAVG_16 =     0x80;
uint8_t MAX30105_SAMPLEAVG_32 =     0xA0;

uint8_t MAX30105_ROLLOVER_MASK =    0xEF;
uint8_t MAX30105_ROLLOVER_ENABLE = 0x10;
uint8_t MAX30105_ROLLOVER_DISABLE = 0x00;

uint8_t MAX30105_A_FULL_MASK =  0xF0;

// Mode configuration commands (page 19)
uint8_t MAX30105_SHUTDOWN_MASK =    0x7F;
uint8_t MAX30105_SHUTDOWN =         0x80;
uint8_t MAX30105_WAKEUP =           0x00;

uint8_t MAX30105_RESET_MASK =       0xBF;
uint8_t MAX30105_RESET =            0x40;

uint8_t MAX30105_MODE_MASK =        0xF8;
uint8_t MAX30105_MODE_REDONLY =     0x02;
uint8_t MAX30105_MODE_REDIRONLY =   0x03;
uint8_t MAX30105_MODE_MULTILED =    0x07;

// Particle sensing configuration commands (pgs 19-20)
uint8_t MAX30105_ADCRANGE_MASK =    0x9F;
uint8_t MAX30105_ADCRANGE_2048 =    0x00;
uint8_t MAX30105_ADCRANGE_4096 =    0x20;
uint8_t MAX30105_ADCRANGE_8192 =    0x40;
uint8_t MAX30105_ADCRANGE_16384 =   0x60;

uint8_t MAX30105_SAMPLERATE_MASK = 0xE3;
uint8_t MAX30105_SAMPLERATE_50 =    0x00;
uint8_t MAX30105_SAMPLERATE_100 =   0x04;
uint8_t MAX30105_SAMPLERATE_200 =   0x08;
uint8_t MAX30105_SAMPLERATE_400 =   0x0C;
uint8_t MAX30105_SAMPLERATE_800 =   0x10;
uint8_t MAX30105_SAMPLERATE_1000 = 0x14;
uint8_t MAX30105_SAMPLERATE_1600 = 0x18;
uint8_t MAX30105_SAMPLERATE_3200 = 0x1C;

uint8_t MAX30105_PULSEWIDTH_MASK = 0xFC;
uint8_t MAX30105_PULSEWIDTH_69 =    0x00;
uint8_t MAX30105_PULSEWIDTH_118 =   0x01;
uint8_t MAX30105_PULSEWIDTH_215 =   0x02;
uint8_t MAX30105_PULSEWIDTH_411 =   0x03;

//Multi-LED Mode configuration (pg 22)
uint8_t MAX30105_SLOT1_MASK =       0xF8;
uint8_t MAX30105_SLOT2_MASK =       0x8F;
uint8_t MAX30105_SLOT3_MASK =       0xF8;
uint8_t MAX30105_SLOT4_MASK =       0x8F;

uint8_t SLOT_NONE =                 0x00;
uint8_t SLOT_RED_LED =          0x01;
uint8_t SLOT_IR_LED =               0x02;
uint8_t SLOT_GREEN_LED =            0x03;
uint8_t SLOT_NONE_PILOT =           0x04;
uint8_t SLOT_RED_PILOT =            0x05;
uint8_t SLOT_IR_PILOT =             0x06;
uint8_t SLOT_GREEN_PILOT =      0x07;

uint8_t MAX_30105_EXPECTEDPARTID = 0x15;


The MAX30101 is highly configurable, and there are a large number of functions exposed in the library to the user. Checkout the MAX30105.h file for all the functions, but here are the major ones. Read the MAX30101 datasheet for more information.

The library supports the following functions:

  • .begin(wirePort, i2cSpeed) - If you have a platform with multiple I2C ports, pass the port object when you call begin. You can increase the I2C speed to 400kHz by including I2C_SPEED_FAST when you call .begin() as well.
  • .setup() - Initializes the sensor with various settings. See the Example 2 from the MAX30105 hookup guide for a good explanation of the options.
  • .getRed() - Returns the immediate red value
  • .getIR() - Returns the immediate IR value
  • .getGreen() - Returns the immediate Green value
  • .available() - Returns how many new samples are available
  • .readTemperature() - Returns the temperature of the IC in C
  • .readTemperatureF() - Returns the temperature of the IC in F
  • .softReset() - Resets everything including data and configuration
  • .shutDown() - Powers down the IC but retains all configuration
  • .wakeUp() - Opposite of shutDown
  • .setLEDMode(mode) - Configure the sensor to use 1 (Red only), 2 (Red + IR), or 3 (Red + IR + Green) LEDs
  • .setADCRange(adcRange) - Set ADC to be at 2048, 4096, 8192, or 16384
  • .setSampleRate(sampleRate) - Configure the sample rate: 50, 100, 200, 400, 800, 1000, 1600, 3200
  • .getINT1() - Returns the main interrupt group
  • .getINT2() - Returns the temp ready interrupt
  • Enable/disable individual interrupts. See page 13 and 14 of the datasheet for an explanation of each interrupt:
    • .enableAFULL()
    • .disableAFULL()
    • .enableDATARDY()
    • .disableDATARDY()
    • .enableALCOVF()
    • .disableALCOVF()
    • .enablePROXINT()
    • .disablePROXINT()
    • .enableDIETEMPRDY()
    • .disableDIETEMPRDY()

The MAX30101 has a 32 byte FIFO (first-in first-out) buffer. This allows us do other things on our microcontroller while the sensor is taking measurements.

  • .check() - Call regularly to pull data in from sensor
  • .nextSample() - Advances the FIFO
  • .getFIFORed() - Returns the FIFO sample pointed to by tail
  • .getFIFOIR() - Returns the FIFO sample pointed to by tail
  • .getFIFOGreen() - Returns the FIFO sample pointed to by tail