Trouble Triggering LED ON/OFF with BLE Example

I am trying for a long time to turn my LED on or off using the BLE example:


//#define BLYNK_USE_DIRECT_CONNECT

#define BLYNK_PRINT Serial

#include `<BlynkSimpleCurieBLE.h>`
#include `<CurieBLE.h>`

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";
BLEPeripheral  blePeripheral;

void setup() {
  Serial.begin(9600);
  delay(1000);

  blePeripheral.setLocalName("Blynk");
  blePeripheral.setDeviceName("Blynk");
  blePeripheral.setAppearance(384);

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

  Serial.println("Waiting for connections...");
}

void loop() {
  Blynk.run();
  blePeripheral.poll();
}

It stops at “Waiting for connections…”

should I change anything in the code other than writing the AUTH?

Hello. I have moved your issue into its own topic as it may be a different issue then the topic you tacked it onto.

I have also formatted you code so that it is properly visible. You can look back at your post (in edit mode) to see how to do that yourself in the future.

As for your issue, have you paired the BLE device on the phone, added the BLE widget to the project, in the app, and connected it to the BLE device?

hallo and thank you for telling me how to make my code probaly visible.

I have Galaxy S3 and I have tested the BLE with an Intel “nRF Connect” application, it works well by controlling the LED at pin D13.
With the Blynk App. I have created a simple App. with a Button and BLE and also choosed the BLE as type of connection at the begin of creating the project. I am using the Genuino 101 and I chosed the pin D13 to be controlled by my button. The connection between phone and device has been done (CONNECT BLE device)–>(Connected to Blynk) and its connected but without any notify on the Serial monitor for Arduino IDE, and now by pressing on the button at the screen of handy it changed from OFF to ON but the LED at pin D13 don’t light!!

should the LED pin be defined in the Arduino code or it is enough to choose the D13 by the settings of the button in the project?

Yes… But did you also add the BLE Widget to your project and then set it up to connect to your hardware? This must also be done.

Also, be aware that there may? still be some issues with the latest core libraries (in Arduino IDE) on the Arduino 101 as pertains to BLE:

there is no problem by connecting the project(App) to the hardware using the BLE, and the Widget is included. It is connected and I can receive the name of my project (for example: Blynk)
But the Problem is controling the LED, I mean turning it ON or OFF using the Button in my project.

I have tried it also using iOS but still the same.

when should the serial monitor receive the notify “READY”? after connecting the Hardware and Project?or just after running the IDE?

Oh, sorry… I must have misinterpreted you … so you are connected, that is good.

EDIT - Please read vhymanskyy’s post below, before wasting time with my suggestions ;)…

Right after connecting it should say something like this (at least it does on my Arduino UNO)

[10240] Ready (ping: 0ms).
Waiting for connections...

Having a button set to pin13 “should” work on a normal Arduino, but I don’t know enough about the 101 to say for sure. You could try changing the button to something like V0 and adding this function to your code:

Add…

pinMode(13, OUTPUT);

…into your setup, then place this function in-between the void setup() and the main void loop()…

BLYNK_WRITE(V0)  // LED in Pin13 toggled by Button Widget on V0, set as switch or button.
{
  int val = param.asInt(); // Get Button Status
  if (val == 1) {  // If button is ON
    digitalWrite(13, HIGH); // Turn ON LED
  } else {  // Assume Button is OFF
    digitalWrite(13, LOW);  // Turn OFF LED
  } // END else
Serial.println(val);  // This should show 1 or 0 in the IDE serial monitor as you toggle the button in the App
} // END Blynk Function

But I don’t know how well the 101 BLE is working with Blynk right now… @vshymanskyy, it is probably way too soon since you filed the issue, but any further update or advice for @huhu?

Arduino 101 BLE won’t work until Intel fixes the bug (it’s confirmed by Intel).

1 Like

Thanks both of you for the advices and the friendly answers

That is done and I am using now the version “Intel Curie Board 1.0.7”

I can connect to my device “Aeduino/Genuino101” using BLE
The Projekt is online

I would like just to turn my LED ON and OFF using a Button and BLE Widget not more!!!

Here is the code I’m using:

#define BLYNK_PRINT Serial


#include <BlynkSimpleCurieBLE.h>
#include <CurieBLE.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "536db4ede501472888c698984a0f3aa4";

BLEPeripheral  blePeripheral;

void setup()
{
  pinMode (13, OUTPUT);
  // Debug console
  Serial.begin(9600);

  delay(1000);

  blePeripheral.setLocalName("Blynk");
  blePeripheral.setDeviceName("Blynk");
  blePeripheral.setAppearance(384);

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

  Serial.println("Waiting for connections...");
}

BLYNK_WRITE(V0)  // LED in Pin13 toggled by Button Widget on V0, set as switch or button.
{
  int val = param.asInt(); // Get Button Status
  if (val == 1) {  // If button is ON
    digitalWrite(13, HIGH); // Turn ON LED
  } else {  // Assume Button is OFF
    digitalWrite(13, LOW);  // Turn OFF LED
  } // END else
Serial.println(val);  // This should show 1 or 0 in the IDE serial monitor as you toggle the button in the App
} // END Blynk Function

void loop()
{
  blePeripheral.poll();
  Blynk.run();
}

In the Serial monitor I become Waiting for Connections…

can anyone please help me to know why it can’t turn the LED on pin D7 ON and OFF using the Button included in my Blynk Projekt.

Assuming your button widget is properly set for V0 then I don’t see why it wouldn’t work?

it is working now :+1: