In this exercise, we will be using the Bluetooth: Peripheral LBS sample, running on your Nordic board, to establish a Bluetooth LE connection between the board and your smartphone. The Peripheral LBS sample makes the Nordic board act as a Bluetooth LE peripheral, advertising its presence to your smartphone, which will act as the central.
When connected, the Nordic board will act as a GATT Server, exposing the LED Button Service (LBS) to your smartphone, the GATT Client. LBS has two characteristics, Button and LED. The GATT Client, in our case a smartphone, can write and read to these characteristics to control the LEDs and read the status of the button on the Nordic board. The Nordic board acts as the GATT server here.
For all exercises in this course, when building the sample application, you can use any of the boards listed under Hardware Requirements on the course page and their corresponding build targets.
This course builds on the nRF Connect SDK Fundamentals course and focuses on Bluetooth Low Energy. You need to read Lesson 1 in the nRF Connect SDK Fundamentals to learn how to install nRF Connect SDK on your machine and build applications. Furthermore, completing the nRF Connect SDK Fundamentals course is strongly advised as it provides a comprehensive understanding of the nRF Connect SDK.
The exercises in this course assume you have a basic understanding of the nRF Connect SDK.
1. Build and flash the Peripheral LBS sample.
1.1 In Visual Studio Code, in the WELCOME panel, select “Browse samples” and search for “Bluetooth LE LED Button service”.
Select this sample, and it will appear under the APPLICATIONS panel.
1.2 Add a build configuration and select whichever board you are using.
1.3 Build and flash the application to your device.
If this was successful, you should notice LED1 (LED0 on nRF54 DKs) blinking on your device.
2. Use your smartphone to test the application
2.1 Download nRF Connect for Mobile from your app store, and launch it on your smartphone.
2.2 Turn on Bluetooth and Location services on your smartphone.
3. (optional) Open a terminal to view the log output from the application
The UART peripheral is gated through the SEGGER debugger/programmer chip (i.e interface MCU) to a USB-CDC virtual serial port that you can connect directly to your PC.
Connect to the COM port of your DK in VS Code by expanding your device under Connected Devices and selecting the COM port for the device. The number for the COM port may differ on your PC.
When using the nRF5340 DK, you will have two COM ports, one for the application core and one for the network core. We want to view the output from the application core.
Use the default settings 115200 8n1 rtscrs:off
. Then reset the device to see the full log message.
If the advertising was successful, your log output should look like this
*** Booting nRF Connect SDK 2.6.1-3758bcbfa5cd ***
Starting Bluetooth Peripheral LBS example
I: 2 Sectors of 4096 bytes
I: alloc wra: 0, f58
I: data wra: 0, 140
Bluetooth initialized
Advertising successfully started
TerminalLED1 (LED0 on nRF54 DKs) should also be blinking, indicating that the device is advertising.
On the nRF54 DKs (Ex: nRF54L15 DK), the board’s LEDs and Buttons are labeled with PCB labels (PCB silkscreen) that start with 0 (LED0-LED3) and (BUTTON0-BUTTON3). In previous-generation development kits, the indexing starts with 1 (LED1-LED4) and (BUTTON1-BUTTON4).
4. Establish a connection to your Nordic board.
4.1 From the nRF Connect for Mobile app, press the SCAN button. Your smartphone will now act as a central device, scanning for any Bluetooth LE devices that are advertising in its presence.
4.2 Several Bluetooth-enabled devices surrounding you will start appearing.
Choose the one called Nordic_LBS
and press CONNECT.
4.3 Press Connect again if prompted with this view.
In rare cases with some Android phones, you might need to first press the 3 dots at the top right corner, then press “Bond”, before connecting to the NORDIC_LBS device.
4.4 You will know a connection has been established when LED2 (LED1 on nRF54 DKs) on your device is on.
5. Observe the interface on the app.
6. Read the status of button 1 using the “Button” Characteristic.
Now, you should be able to see the status of button 1 (button 0 on nRF54 DKs) as released.
7. Observe the status of button 1 (button 0 on nRF54 DKs).
7.1 Press button 1 on your Nordic board
7.2 Observe the value shown below changes to “Button pressed”.
8. Toggle LED 3 (LED2 on nRF54 DKs).
8.1 Press the up arrow icon next to the LED characteristic.
8.2 Write a value to the LED characteristic to turn it on
Select ON and then SEND to turn the LED on.
8.3 Observe that LED3 is turned on.
8.4 Turn off the LED by selecting OFF.
4.1 From the nRF Connect for Mobile app, press the Play icon, in the upper right-hand corner. Your smartphone will now act as a central device, scanning for any Bluetooth LE devices that are advertising in its presence.
4.2 Several Bluetooth-enabled devices surrounding you will start appearing.
Choose the one called Nordic_LBS
and press Connect.
4.3 You will know a connection has been established when LED2 (LED1 on nRF54 DKs) on your device is on.
5. Observe the interface on the app.
Go to the second window, called Client. In newer versions of the app, the Client window is represented by this icon
6. Read the status of button 1 using the “Button” Characteristic.
Now, you should be able to see the status of button 1 (button 0 on nRF54 DKs) as released.
7. Observe the status of button 1.
7.1 Press button 1 (button 0 on nRF54 DKs) on your Nordic board
7.2 Observe the value shown below changes to “Button pressed”.
8. Toggle LED3 (LED2 on nRF54 Series devices) .
8.1 Press the up arrow icon next to the LED characteristic.
8.2 Write a value to the LED characteristic to turn it on
Select Bool, then switch the value to True and then select Write to send the value.
8.3 Observe that LED3 (LED2 on nRF54 Series devices) is turned on.
8.4 Turn off the LED by selecting OFF.