1
#include <ArduinoBLE.h>

const char *serviceUUID = "12345678-1234-5678-1234-56789abcdef0";  // UUID of the service
const char *characteristicUUID = "23456789-2345-6789-2345-6789abcdef0";  // UUID of the characteristic

BLEService customService(serviceUUID);  // Create a custom service
BLECharacteristic customCharacteristic(characteristicUUID, BLERead | BLEWrite, 20);  // Characteristic to communicate with

void setup() {
  // Start serial communication
  Serial.begin(9600);
  while (!Serial);

  // Initialize BLE
  if (!BLE.begin()) {
    Serial.println("BLE initialization failed!");
    while (1);
  }

  // Set the local name of the device
  BLE.setDeviceName("BLE_Sense_33");
  BLE.setLocalName("BLE_Sense_33");

  // Add the characteristic to the service
  customService.addCharacteristic(customCharacteristic);

  // Add the service to BLE
  BLE.addService(customService);

  // Start advertising
  BLE.advertise();

  Serial.println("BLE Advertise Started");
}

void loop() {
  // Wait for a BLE client to connect
  BLEDevice central = BLE.central();

  if (central) {
    // We have a client connected
    Serial.print("Connected to central: ");
    Serial.println(central.address());

    while (central.connected()) {
      // Handle the communication here if needed
      delay(1000);
    }

    // Client disconnected
    Serial.print("Disconnected from central: ");
    Serial.println(central.address());
  }

  delay(1000);
}

For immediate assistance, please email our customer support: [email protected]

Download RAW File