Bluetooth: Heart Rate Service
The Heart Rate Service sample demonstrates how you can implement the Heart Rate profile using nRF Connect SDK Bare Metal option.
Requirements
The sample supports the following development kits:
The following board variants do not have DFU capabilities:
S115:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice
S145:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice
The following board variants have DFU capabilities:
S115:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s115_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s115_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s115_softdevice/mcuboot
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s115_softdevice/mcuboot
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s115_softdevice/mcuboot
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s115_softdevice/mcuboot
S145:
Hardware platform
PCA
Board target
PCA10156
bm_nrf54l15dk/nrf54l15/cpuapp/s145_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L10)
PCA10156
bm_nrf54l15dk/nrf54l10/cpuapp/s145_softdevice/mcuboot
nRF54L15 DK (emulating nRF54L05)
PCA10156
bm_nrf54l15dk/nrf54l05/cpuapp/s145_softdevice/mcuboot
PCA10184
bm_nrf54lm20dk/nrf54lm20a/cpuapp/s145_softdevice/mcuboot
PCA10214
bm_nrf54ls05dk/nrf54ls05b/cpuapp/s145_softdevice/mcuboot
PCA10188
bm_nrf54lv10dk/nrf54lv10a/cpuapp/s145_softdevice/mcuboot
Overview
When the application starts, three timers are started. These timers control the generation of various parts of the Heart Rate Measurement characteristic value:
Heart Rate
RR Interval
Sensor Contact Detected
A timer for generating battery measurements is also started.
The sensor measurements are simulated the following way:
Heart Rate
RR Interval
Sensor Contact
Battery Level
When notification of Heart Rate Measurement characteristic is enabled, the Heart Rate Measurement, containing the current value for all the components of the Heart Rate Measurement characteristic, is notified each time the Heart Rate measurement timer expires. When notification of Battery Level characteristic is enabled, the Battery Level is notified each time the Battery Level measurement timer expires.
The sample supports bonding with the connected device. The services security configurations are kept open to allow reading the characteristics without bonding with the device.
User interface
- Button 1:
Keep the button pressed while resetting the board to delete bonding information for all peers stored on the device.
- LED 0:
Lit when the device is initialized.
- LED 1:
Lit when a device is connected.
Building and running
This sample can be found under samples/bluetooth/ble_hrs/ in the Bare Metal folder structure.
For details on how to create, configure, and program a sample, see Getting Started with the samples.
Testing
You can test this sample using nRF Connect for Desktop with the Bluetooth Low Energy app and the Serial Terminal app. Make sure that these are installed before starting the testing procedure.
Compile and program the application.
In the Serial Terminal, observe that the
BLE HRS sample initializedmessage is printed.Observe that the
Advertising as nRF_BM_HRSmessage is printed. You can configure the advertising name using theCONFIG_SAMPLE_BLE_DEVICE_NAMEKconfig option. For information on how to do this, see Configuring Kconfig.In nRF Connect for Desktop, scan for advertising devices. If the device is not advertising, reset the board with the Reset Board option in Visual Studio Code or by pressing the reset button on the development kit.
Connect to your device.
The terminal output in Visual Studio Code indicates
Peer connected.After having connected, your computer or mobile phone may attempt to pair or bond with your device in order to encrypt the link.
You may be prompted to enter a passkey as part of the authentication step. If prompted, provide the passkey from the terminal output.
Observe that the services are shown in the connected device and that you can start receiving values for the Heart Rate and the Battery Service by clicking the Play button. Heart Rate notifications are received every second, and Battery Level notifications are received every two seconds.