# AmebaD BLE Demo with nRF Toolbox and Arduino IDE

**URL:** <https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214>\
**Category:** BT\
**Tags:** share\
**Created:** [February 7, 2021, 1:55pm UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214 "2021-02-07T13:55:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salmanfarisvp](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/salmanfarisvp/32/2555_2.png) [@Salmanfarisvp](https://forum.amebaiot.com/u/Salmanfarisvp)\
**Post date:** [February 7, 2021, 1:55pm UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214/1 "2021-02-07T13:55:35Z")

</div>

Here I’m showcasing simple GPIO/LED control with nRF Toolbox and Arduino IDE, The Arduino sketch is a modified from BLE UART Example.

Tools Used:

- Ameba RTL8722DM Board (AMB 21)
- Nordic nRF Toolbox
- Arduino IDE
- Android Phone

[![](https://us1.discourse-cdn.com/flex016/uploads/ameba/original/2X/d/ded11178484bfdfebd7e2090c6b6279516c3e745.jpeg "AmebaD BLE Demo with nRF Toolbox and Arduino IDE") ](https://www.youtube.com/watch?v=Ou9RpysShQY)

```auto
#include "BLEDevice.h"

#define UART_SERVICE_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_RX "6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARACTERISTIC_UUID_TX "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

#define STRING_BUF_SIZE 100

#define led 13

BLEService UartService(UART_SERVICE_UUID);
BLECharacteristic Rx(CHARACTERISTIC_UUID_RX);
BLECharacteristic Tx(CHARACTERISTIC_UUID_TX);
BLEAdvertData advdata;
BLEAdvertData scndata;
bool notify = false;

void readCB (BLECharacteristic* chr, uint8_t connID) {
    printf("Characteristic %s read by connection %d \n", chr->getUUID().str(), connID);
}

void writeCB (BLECharacteristic* chr, uint8_t connID) {
    printf("Characteristic %s write by connection %d :\n", chr->getUUID().str(), connID);
    if (chr->getDataLen() > 0) {
        Serial.print("Received string: ");
        Serial.print(chr->readString());
        if(chr->readString() == "1")
        {
          digitalWrite(led,HIGH);
        }
        else if(chr->readString() == "0")
        {
          digitalWrite(led,LOW);
        }
        
        Serial.println();
    }
}

void notifCB (BLECharacteristic* chr, uint8_t connID, uint16_t cccd) {
    if (cccd & GATT_CLIENT_CHAR_CONFIG_NOTIFY) {
        printf("Notifications enabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
        notify = true;
    } else {
        printf("Notifications disabled on Characteristic %s for connection %d \n", chr->getUUID().str(), connID);
        notify = false;
    }
}

void setup() {
    Serial.begin(115200);

    advdata.addFlags(GAP_ADTYPE_FLAGS_LIMITED | GAP_ADTYPE_FLAGS_BREDR_NOT_SUPPORTED);
    advdata.addCompleteName("AMEBA_BLE_DEV");
    scndata.addCompleteServices(BLEUUID(UART_SERVICE_UUID));

    Rx.setWriteProperty(true);
    Rx.setWriteCallback(writeCB);
    Rx.setBufferLen(STRING_BUF_SIZE);
    Tx.setReadProperty(true);
    Tx.setReadCallback(readCB);
    Tx.setNotifyProperty(true);
    Tx.setCCCDCallback(notifCB);
    Tx.setBufferLen(STRING_BUF_SIZE);

    UartService.addCharacteristic(Rx);
    UartService.addCharacteristic(Tx);

    BLE.init();
    BLE.configAdvert()->setAdvData(advdata);
    BLE.configAdvert()->setScanRspData(scndata);
    BLE.configServer(1);
    BLE.addService(UartService);

    BLE.beginPeripheral();

    pinMode(led,OUTPUT);
}

void loop() {
    if (Serial.available()) {
        Tx.writeString(Serial.readString());
        if (BLE.connected(0) && notify) {
            Tx.notify(0);
        }
    }
    delay(100);
}

```

Thanks 🙂👍.

---

<div class="post-metadata">

**Author:** ![SamWells](https://avatars.discourse-cdn.com/v4/letter/s/9fc348/32.png) [@SamWells](https://forum.amebaiot.com/u/SamWells)\
**Post date:** [February 9, 2021, 2:45am UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214/2 "2021-02-09T02:45:42Z")

</div>

Very cool~

---

<div class="post-metadata">

**Author:** ![brcisna](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@brcisna](https://forum.amebaiot.com/u/brcisna)\
**Post date:** [August 9, 2021, 3:49am UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214/3 "2021-08-09T03:49:34Z")

</div>

Hi Salmanfarisvp

How could a person going about using this same concept,other than having a light, light,it would send signal to a buzzer (loud) .  
This is for locating a lost drone?

Thanks

---

<div class="post-metadata">

**Author:** ![Salmanfarisvp](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/salmanfarisvp/32/2555_2.png) [@Salmanfarisvp](https://forum.amebaiot.com/u/Salmanfarisvp)\
**Post date:** [August 9, 2021, 4:22am UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214/4 "2021-08-09T04:22:49Z")

</div>

Hi @brcisna ,

You can do the same with the buzzer too, since buzzer just need to turn on to make sound you can apply the same circuit we used with led.

---

<div class="post-metadata">

**Author:** ![dakamaster](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.amebaiot.com/dakamaster/32/1744_2.png) [@dakamaster](https://forum.amebaiot.com/u/dakamaster)\
**Post date:** [August 11, 2021, 3:29am UTC](https://forum.amebaiot.com/t/amebad-ble-demo-with-nrf-toolbox-and-arduino-ide/214/5 "2021-08-11T03:29:59Z")

</div>

Great job, Salman. 👍
