Questions about Arduino Bluetooth.

Asked 2 years ago, Updated 2 years ago, 92 views

Hi, everyone. I am a student studying Bluetooth.

I want to do BLE communication between Arduino and Android.

BLE communication is being conducted using Android GATT.

When the two devices are connected, Arduino will try to generate any event regardless of whether the LED is turned on.

In my short opinion, if Android succeeds in connecting to Arduino and BLE, Android will see the data

It's to turn on the LED of my arduino. However, if the connection is disconnected, the LED should be turned off, like this

In order to do that, the only way for Android to continue to thread and send the data.

Rather than this method, if a device with a successful Bluetooth connection appears on Arduino's side, the LED will be turned on

I think it would be better to turn off the LED if this connection is disconnected.

So, on Arduino, we are currently using the BLEPeripheral.h library, and on Arduino, we are using BLEEPeripheral

Lutus turns on the LED knowing that a connection is made with a device, and if the connection is disconnected

Is there any way to turn off the cotton LED...?

Thank you for reading this long comment!

arduino android bluetooth

2022-09-22 15:27

1 Answers

Looking at the BLEPipheral Library, we provide an API to receive events when the connection is made and when it is terminated.

Use the sample code below to turn the LED on and off in each callback function.

void setup() {
    ...

    // // assign event handlers for connected, disconnected to peripheral
    blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
    blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

    ...
}

void blePeripheralConnectHandler(BLECentral& central) {
  // Implement to turn on the LED when connected
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  // Implement to turn off the LED when the connection is lost
}

Please refer to the link below for the relevant sample code.


2022-09-22 15:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.