MAX30102 Pulse Oximeter Heart Rate Sensor Module Documentation
The MAX30102 is a pulse oximeter and heart rate sensor module that integrates a photoplethysmography (PPG) sensor and a low-noise analog-to-digital converter (ADC) to measure heart rate and oxygen saturation (SpO2) levels. This module is commonly used in wearable devices, medical equipment, and IoT projects.
The MAX30102 module has the following pinout:
VCC: Power supply (3.3V or 5V)
GND: Ground
SCL: I2C clock
SDA: I2C data
INT: Interrupt output
The MAX30102 communicates through the I2C protocol.
Configuration and Initialization
Before using the MAX30102, it is necessary to configure and initialize the module. This involves setting the mode, sample rate, and LED currents.
### Example 1: Arduino Sketch for Heart Rate Monitoring
This example demonstrates how to use the MAX30102 to measure heart rate and display it on the serial monitor using an Arduino board.
```c
#include <Wire.h>
#define MAX30102_ADDRESS 0x57
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize MAX30102
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x00); // Mode register
Wire.write(0x03); // Enable heart rate mode
Wire.endTransmission();
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x04); // Sample rate register
Wire.write(0x01); // Set sample rate to 100 Hz
Wire.endTransmission();
}
void loop() {
int heartRate;
// Read heart rate data
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x05); // Heart rate register
Wire.endTransmission();
Wire.requestFrom(MAX30102_ADDRESS, 2);
heartRate = Wire.read() << 8 | Wire.read();
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.println(" bpm");
delay(1000);
}
```
### Example 2: Raspberry Pi Python Script for SpO2 Measurement
This example demonstrates how to use the MAX30102 to measure SpO2 levels and display them on the console using a Raspberry Pi.
```python
import smbus
import time
# Initialize I2C bus
bus = smbus.SMBus(1)
# MAX30102 address
address = 0x57
# Initialize MAX30102
bus.write_byte_data(address, 0x00, 0x03) # Enable SpO2 mode
bus.write_byte_data(address, 0x04, 0x01) # Set sample rate to 100 Hz
while True:
# Read SpO2 data
bus.write_byte(address, 0x06) # SpO2 register
data = bus.read_i2c_block_data(address, 0x06, 2)
Spo2 = (data[0] << 8 | data[1]) & 0x03FF
print("SpO2: {:.2f}%".format(Spo2 / 100.0))
time.sleep(1)
```
### Example 3: ESP32 Code for Real-Time Heart Rate and SpO2 Monitoring
This example demonstrates how to use the MAX30102 to measure heart rate and SpO2 levels in real-time using an ESP32 board.
```c
#include <WiFi.h>
#include <Wire.h>
#define MAX30102_ADDRESS 0x57
void setup() {
Serial.begin(115200);
Wire.begin();
// Initialize MAX30102
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x00); // Mode register
Wire.write(0x03); // Enable heart rate and SpO2 mode
Wire.endTransmission();
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x04); // Sample rate register
Wire.write(0x01); // Set sample rate to 100 Hz
Wire.endTransmission();
}
void loop() {
int heartRate;
int SpO2;
// Read heart rate data
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x05); // Heart rate register
Wire.endTransmission();
Wire.requestFrom(MAX30102_ADDRESS, 2);
heartRate = Wire.read() << 8 | Wire.read();
// Read SpO2 data
Wire.beginTransmission(MAX30102_ADDRESS);
Wire.write(0x06); // SpO2 register
Wire.endTransmission();
Wire.requestFrom(MAX30102_ADDRESS, 2);
SpO2 = Wire.read() << 8 | Wire.read();
Serial.print("Heart Rate: ");
Serial.print(heartRate);
Serial.print(" bpm, SpO2: ");
Serial.print(SpO2);
Serial.println(" %");
delay(1000);
}
```
Note: These examples are for illustrative purposes only and may require modifications to work with your specific hardware setup. Ensure you consult the MAX30102 datasheet and relevant documentation for your microcontroller or development board for more information on using this module.