How PPG Sensors Actually Work
Photoplethysmography (PPG) sensors measure blood volume changes in tissue by shining light (typically red and infrared) into the skin and measuring the reflected or transmitted photons. The underlying physics relies on the Beer-Lambert law: oxygenated hemoglobin (HbO2) and deoxygenated hemoglobin (Hb) absorb red and IR light at different rates. The photodiode detects a baseline absorption (the DC component from skin, bone, and venous blood) superimposed with a pulsatile signal (the AC component from arterial blood pumping with each heartbeat).
On the bench, you are not measuring an analog voltage directly. The sensor's internal transimpedance amplifier (TIA) converts the photodiode's microamp current into a voltage, which an onboard ADC digitizes. When you interface PPG sensors like the ubiquitous MAX30102 or MAX30105 with a microcontroller, you are reading raw digital light-intensity counts over an I2C bus, not an analog waveform.
Wiring and Hardware Setup
Most hobbyists use breakout boards (like the GY-MAX30102 or SparkFun's MAX30105) rather than the bare IC. Breakout boards solve the biggest hardware trap: the raw MAX3010x IC requires a 1.8V logic level, but almost all 3.3V/5V microcontrollers will fry the bare chip's SDA/SCL pins without a level shifter. Breakouts include an onboard LDO and I2C pull-ups to handle this.
| Breakout Pin | ESP32 Pin | Function & Notes |
|---|---|---|
| VIN / VCC | 3V3 or 5V | Supply range: 3.3V to 5.0V (feeds the onboard 1.8V LDO). |
| GND | GND | Common ground. Keep leads short to reduce noise. |
| SDA | GPIO 21 | I2C Data. Breakout usually has 4.7k pull-ups installed. |
| SCL | GPIO 22 | I2C Clock. Max bus speed is 400kHz (Fast Mode). |
| INT | GPIO 4 | Active-low interrupt. Triggers when FIFO has new ADC data. |
0x57 but reads return all zeros or NaN, check your VIN. If you accidentally wired a bare IC to 3.3V logic without a level shifter, you have likely permanently damaged the internal I2C transceiver.
Decoding the Output: Raw ADC to Physical Units
A common beginner mistake is assuming a PPG sensor outputs 'Heart Rate' or 'SpO2' directly. It does not. The output is an 18-bit unsigned integer (ranging from 0 to 262,143) representing raw light intensity hitting the photodiode. Converting these raw counts into physiological metrics requires digital signal processing (DSP) on the microcontroller.
Calculating Heart Rate (BPM)
Heart rate is derived from the time delta between the systolic peaks of the AC waveform. After applying a bandpass filter (typically 0.5 Hz to 3.5 Hz to isolate human heart rates from respiration and high-frequency noise), you detect the local maxima.
BPM = 60 / (t_peak2 - t_peak1)
Where t is measured in seconds. If your sampling rate is 100 Hz, and the distance between two peaks is 85 samples, the time delta is 0.85 seconds. 60 / 0.85 = 70.5 BPM.
Calculating SpO2 (Oxygen Saturation)
SpO2 requires calculating the 'Ratio of Ratios' (R) using both the Red and IR channels. You must isolate the AC amplitude (peak-to-trough) and the DC baseline (average trough value) for both wavelengths.
R = (AC_red / DC_red) / (AC_ir / DC_ir)
Once you have R, you map it to a percentage. Because light scattering in human tissue is highly non-linear, you cannot use pure Beer-Lambert math. Instead, manufacturers use an empirical lookup table. A standard linear approximation for hobbyist code is:
SpO2 = 110 - (25 * R)
110 - 25R formula is a rough approximation for educational projects. Clinical pulse oximeters use multi-point calibration curves derived from human hypoxia studies. Never use a DIY PPG sensor for medical diagnosis or patient monitoring.
Beating Motion Artifacts and Ambient Light
The two primary failure modes for PPG sensors on the bench are motion artifacts (MA) and ambient light injection. If your raw ADC plot looks like a jagged mess rather than a smooth plethysmogram, one of these is the culprit.
Motion Artifacts: When the sensor moves relative to the skin, the optical path length changes, creating massive low-frequency spikes that easily dwarf the actual AC pulse signal. In high-end wearables, this is solved via sensor fusion: an IMU (like the MPU6050) tracks the physical acceleration, and an adaptive filter (like the LMS algorithm) subtracts the motion vector from the PPG signal. For hobbyists, the fix is mechanical: use a tight elastic strap and a foam gasket to press the sensor firmly against the skin, minimizing relative movement.
Ambient Light: Sunlight contains massive IR energy, and indoor LED/fluorescent lights flicker at 50/60 Hz, which aliases directly into your sampling band. The MAX30102 solves this in hardware via the Ambient Light Cancellation (ALC) register. The IC pulses the LEDs, takes a 'dark' sample with the LEDs off, and subtracts the dark current from the illuminated sample. Ensure your library initializes the ALC register, and always 3D-print or buy an opaque silicone shroud to cover the sensor window.
PPG Sensors FAQ
Why do cheap PPG sensors fail on dark skin tones or tattoos?
Melanin and tattoo ink absorb a significant amount of the red and IR light before it can reach the arterial bed and reflect back to the photodiode. This drastically lowers the Signal-to-Noise Ratio (SNR) of the AC component. To compensate, you must increase the LED drive current (e.g., from 4.4mA up to 16mA or higher in the MAX30102 configuration registers) and increase the ADC integration time to capture more photons. Be careful: higher drive currents increase die temperature, which can cause thermal drift or burn the user's skin if left on continuously.
Can I use a PPG sensor to measure blood pressure?
Not directly, and not reliably with a single sensor. Blood pressure estimation via PPG relies on Pulse Transit Time (PTT) or Pulse Arrival Time (PAT), which measures the time delay between the electrical spike of the heart (the R-wave on an ECG) and the arrival of the pulse wave at the peripheral PPG sensor. This requires simultaneous ECG and PPG hardware (like the MAX86150), plus a baseline calibration with a traditional inflatable cuff. Single-sensor PPG blood pressure apps on the market rely on population-based machine learning heuristics and are notoriously inaccurate for individual clinical use.
What is the exact difference between the MAX30102 and MAX30105?
Optically and electrically, they are nearly identical; both use the same I2C registers, FIFO structure, and 18-bit ADC. The difference is in the intended application and internal algorithm support. The MAX30102 is specifically optimized and binned for Pulse Oximetry (SpO2) and Heart Rate, featuring dedicated hardware registers for SpO2 calibration. The MAX30105 is marketed as a 'Particle Sensor' and proximity sensor; it includes an extra green LED (useful for photoplethysmography on the wrist, where green light penetrates shallow capillary beds better than red/IR) but lacks the dedicated SpO2 algorithmic hardware flags. If you are building a fingertip pulse oximeter, buy the MAX30102. If you are building a wrist-worn heart rate monitor or a smoke detector, buy the MAX30105.






