nRF52 BLE Heart Rate Monitor
This tutorial will show you how to connect PulseSensor to an nRF52 Bluetooth radio module that will set up the BLE Heart Rate Monitor Service.
This project is fully fleshed out in Chapter 13 of our new book,
Heartbeat Sensor Projects with PulseSensor: Prototyping Biofeedback Devices with PulseSensor!
Pick up your copy today on Amazon, or at Springer.
Here's a list of materials we used for this project
- nRF52840 BLE radio module
- We will use the Adafruit Feather nRF52840 Express for this example
- USB Cable for programming and power
- One LED
- One Resistor
- 1K value is a good place to start
- Phone to view the BPM data
The hardware setup is simple. First, connect the PulseSensor Red wire to +V and the Black wire to GND, then connect the Purple wire to analog pin A0. The LED is connected to digital pin 12.
If you have not already installed the PulseSensor Playground library, follow this tutorial to make sure you have the latest and greatest.
You will also need to install the Adafruit board files. Open the Settings pane in Arduino IDE. For Windows, click File > Preferences. For Mac, click Arduino_IDE > Settings. Then click the button to add a board URL.
Paste the following link into the text window
https://adafruit.github.io/arduino-board-index/package_adafruit_index.json
Make sure that you press OK when you close the Preferences window when you are done. This will tell Arduino to look for the Adafruit board files. The next step is to download those files. Click on the Board icon at the left, and do a search for Adafruit nRF52.
Install the latest version, and then click the Board icon to exit. Now, make sure that you select the right board for the code. Click on Tools > Board > Adafruit nRF52 > Adafruit Feather nRF52840 Express.
When you have the circuit built and the Arduino files downloaded, connect to your computer with USB, then open the Arduino IDE, and navigate to File > Examples > PulseSensor Playground > PulseSensor_BLE_Heartrate_Monitor_Service.
This code example will set up the nRF52 to provide BLE Heartrate Monitor Service, which is a standard in the Bluetooth Low Energy specification. Any phone app that is set up to receive Heartrate Monitor Service will be able to get BPM data from PulseSensor!
In order to test and make sure that all of the parts of the code and circuit are working, We'll use a simple app from Nordic, the makers of the nRF52. If it works with their app, we know it is working! The app is free and available for iOS and Android. Go to your app store and search for nRF Toolbox.
Install the app and open it. You will see a screen with options for many BLE Services.
Select Heart Rate from the list, and the app will start scanning for BLE Devices. The code we uploaded in Arduino sets the advertising name to PulseSensor. Click on the device named PulseSensor, and the app will open a connection and start receiving the Heart Rate data.
This is a great way to visualize your BPM over Bluetooth, and verify that all of the parts are working. Try a different Heart Rate Monitor app to see your BPM data there too!