Arduino Function: BLEPeripheral.setAdvertisedServiceUuid




Advertise the service’s UUID passed as parameter.




uuid: const char*. UUID to be advertised.




You can call this function multiple times to advertise multiple UUIDs. Due to the advertising packet length there is a limit to the maximum number of UUIDs advertisable. The maximum length of an advertising packet is 62 byte (divided into 31 byte of advertising packet and 31 of scan response packet), thus the maximum number of advertised UUIDs is constricted by this limit and by the other things you may want to advertise (such as device name, appearance and so forth).


/* Copyright (c) Sandeep Mistry. All rights reserved.
  Licensed under the MIT license. See LICENSE file in the project root for full license information.
  Modified by Chiara Ruggeri <>;
  This example shows how to read/write a characteristic to turn a LED on or off
  You can use nRFConnect app to read/write the characteristic
  In this example BLE_LED shows the status of the board. It will blink every 200 ms when the board is advertising.
  It will be on when the board is connected to a central. It will be off when the board is disconnected.

#include <BLEPeripheral.h>

// LED pin

// create peripheral instance
BLEPeripheralRole         blePeripheral     = BLEPeripheralRole();

// create service
BLEService            ledService        = BLEService("19b10000e8f2537e4f6cd104768a1214");

// create switch characteristic
BLECharCharacteristic switchCharacteristic = BLECharCharacteristic("19b10001e8f2537e4f6cd104768a1214", BLERead | BLEWrite);

void setup() {

 //initialize BLE led
 pinMode(BLE_LED, OUTPUT);

 // set LED pin to output mode
 pinMode(LED_PIN, OUTPUT);

 // set advertised local name and service UUID

 // add service and characteristic

 // begin initialization

 Serial.println(F("BLE LED Peripheral"));

void loop() {
 BLECentralPeer central = blePeripheral.central();

 if (central) {

// central connected to peripheral
Serial.print(F("Connected to central: "));

   // turn on BLE_LED when connected
   digitalWrite(BLE_LED, HIGH);

while (central.connected()) {

  // central still connected to peripheral
  if (switchCharacteristic.written()) {

    // central wrote new value to characteristic, update LED
    if (switchCharacteristic.value()) {
      Serial.println(F("LED on"));
      digitalWrite(LED_PIN, HIGH);

    } else {
      Serial.println(F("LED off"));
      digitalWrite(LED_PIN, LOW);

// central disconnected
Serial.print(F("Disconnected from central: "));

 // here we are not connected. This means we are advertising
 digitalWrite(BLE_LED, HIGH);
 digitalWrite(BLE_LED, LOW);

Written by