Example Code for Raspberry Pi-Get Heart Rate and Blood Oxygen Data
Last revision 2025/12/17
The article provides a comprehensive guide to setting up a Raspberry Pi with a heart rate and oximeter sensor, detailing hardware and software preparation, connection setup, and Python coding to extract heart rate and blood oxygen data effectively.
Hardware Preparation
- Raspberry Pi 4B (or similar) x1
- Heart Rate and Oximeter Sensor V2 module (compatible with Raspberry Pi) x1
- Wires
Software Preparation
Wiring Diagram
- Connect the module to Raspberry Pi according to the connection diagram. The default I2C address is 0x68.

Other Preparation Work
Step 1. 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.
Step 2. 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
Step 3. 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?
