Example Code for Raspberry Pi - Get Heart Rate and Blood Oxygen Data
Last revision 2026/01/21
Get the Heart Rate and Blood Oxygen Data (gain_heartbeat_SPO2.py)
Hardware Preparation
- Raspberry Pi 4B (or similar) x1
- Heart Rate and Oximeter Sensor V2 module (compatible with Raspberry Pi) x1
- M-M/F-M/F-F Jumper wires
Software Preparation
Wiring Diagram
- Connect the module to Raspberry Pi according to the connection diagram. The default I2C address is 0x68.

Driver Installation
-
Enable the I2C interface of Raspberry Pi, if enabled, skip this step. Open terminal, type the following command, and press Enter:
pi@raspberrypi:~ $ sudo raspi-config
Select "5 Interfacing Options" and press Enter. Select "P5 I2C" and press Enter to confirm "YES". Restart the Raspberry Pi master control. -
Install Python dependencies with git, and Raspberry Pi needs to be connected to the Internet. If done, skip this step. In the terminal, type the following commands and press Enter:
pi@raspberrypi:~ $ sudo apt-get update pi@raspberrypi:~ $ sudo apt-get install build-essential python-dev python-smbus git -
Download the BloodOxygen driver libraries. In the terminal, type the following commands and press Enter:
pi@raspberrypi:~ $ cd Desktop/
pi@raspberrypi:~/Desktop $ git clonehttps://github.com/DFRobot/DFRobot_BloodOxygen_S
Sample Code
In the terminal, type the following command and press Enter to run the sample code:
pi@raspberrypi:~/Desktop $ cd DFRobot_BloodOxygen_S/python/raspberry/example/gain_heartbeat_SPO2/ pi@raspberrypi:~/Desktop/DFRobot_BloodOxygen_S/python/raspberry/example/gain_heartbeat_SPO2/ $ python gain_heartbeat_SPO2.py
Result

Was this article helpful?
