SparkFun Photodetector (MAX30101) Hookup Guide

Contributors: Santa Claus Impersonator
Favorited Favorite 0

Arduino Examples

☠ Do not rely on our examples for medical diagnosis or any life saving applications

Note: Particle detection, heart rate measurement, and photoplethysmography (for pulse oximetry) are applications of the MAX30101. These applications require a fundamental understanding of the operating principles of the sensor and a conceptual knowledge of the applications. Although, we provide some examples for these applications; they are primarily for demonstration purposes only and are not supported by SparkFun.

Note: Although there is an example, Maxim has since removed the proximity sensing and particle detection as functionalities of this sensor in their datasheet.

Example 1 - Reading Red/IR/Green

Once you've got the library installed, open the Example1 Basic Readings sketch. You can find it under

File > Examples > SparkFun MAX3010x Pulse and Proximity Sensor Library > Examples

Then load it onto your RedBoard or Uno. Open your favorite Serial Terminal to see the printed values.

Screen shot of MAX30101 readings
Data readings for photodetector. (Click to enlarge)

This example outputs the raw values read by the sensor. With the sensor pointing up, use your hand to hover over the sensor. You should see a change in values as your hand reflects different amounts of light. Note that the IR readings will probably change before the Red and Green readings. IR is better at sensing distance changes.

Completely cover the sensor with your finger. Note the very large readings. This is one of the features that sets the MAX30101 from other reflectance sensors. The IC is capable of reading up to 18-bits or values up to 262,144. An extremely small change in light can be detected!

The MAX30101 is easy to use! Calling particleSensor.getGreen() will take a reading and return the reflected amount of green light.

Example 3 - Temperature Sensor

Open the Example3 Temperature Sense sketch, and load it onto your RedBoard or Uno.

Temperature output from MAX30101 sensor
Internal temperature readings. (Click to enlarge)

This example outputs readings from the on-board temperature sensor in both Celsius and Fahrenheit. The temp sensor is accurate to ±1 °C but has an astonishing precision of 0.0625 °C.

The temperature is used internally by the sensor to calibrate its samples but can be useful if you need a sensitive and fast responding temp sensor.

Example 4 - Heart Beat Plotting

Note: The Arduino IDE must be version 1.6.6 or higher. The Serial Plotter is only available in Arduino versions v1.6.6 or later.

For this demo, you'll need a rubber band small enough to go through the mounting holes on the breakout. Make sure to follow the example in the Hardware Assembly section for the best results.

This is where the fun really begins! Hemoglobin reflects IR light really well, and the MAX30101 is capable of detecting such small changes in IR reflectance that it can detect blood flowing through your finger at different rates. Let's graph it! Open the Example4 HeartBeat Plotter sketch, and load it on your Redboard or Uno.


  1. Load code onto Redboard
  2. Attach sensor to your finger with a rubber band
  3. Open Tools->Serial Plotter
  4. Make sure the drop down is set to 115200 baud
  5. Checkout the blips!
  6. Feel the pulse on your neck and watch it mimic the blips
I'll just hold my finger on the sensor instead...

Humans are bad at applying consistent pressure to a thing. Without a rubber band the pressure varies enough to cause the blood in your finger to flow differently which causes the sensor readings to go wonky. It is best to attach the sensor to your finger using a rubber band or other tightening device.

Graph of heart beat
Graph of IR data - That's my pulse!

Now that we have seen the blips, Example 5 will try to calculate the time between blips and show us beats per minute (BPM).

Example 5 - HeartRate

☠ WARNING: Let's have a brief chat about the example code. We're going to try to detect heart-rate optically. This is tricky and prone to give false readings. We really don't want to get anyone hurt, so use this code only as an example of how to process optical data. Build fun stuff with our MAX30101 breakout board, but don't use it for actual medical diagnosis.

Open the Example5 HeartRate sketch, and load it on your Redboard or Uno.

Heart rate output
Heart rate readings. (Click to enlarge)

This example runs a filter called the PBA or Penpheral Beat Amplitude algorithm on the IR data. This algorithm is able to pull out the blips from all the noise and calculate the time between blips to get a heart rate. The output is your instantaneous heart rate and your average heart rate (BPM).

As one might expect the human body isn't as precise as a metronome. The time between pulses can vary quite a bit so this sketch takes a running average of 4 readings to try to smooth out the variance.