LED Bluetooth Control Using NRF Connect

by TechMartian in Circuits > Arduino

5220 Views, 15 Favorites, 0 Comments

LED Bluetooth Control Using NRF Connect

Wwo8JLbBR02dyHe83z+feA_thumb_3c5.jpg
adyAMZP3QUyuFh38zaeOlQ_thumb_3bf.jpg
M8qnSvCYTUyLIKKNqVgDXw_thumb_3c3.jpg

This is the last module on the Arduino 101 Essentials series and marks the beginning of a new Arduino 101 BLE uses series.

This is an introduction on how to use the Bluetooth Low Energy capabilities of the Arduino 101 to control an LED remotely over BLE4.1. Furthermore, this uses an app that is very versatile and flexible for developers and is only compatible with the Arduino 101, called nRF Connect, which is quite different from it's other bluetooth counterparts like Blink. This can be applied to a number of other applications, from reading bluetooth unlocked.


The fact that the Arduino 101 possesses Bluetooth Low Energy (BLE4.1) is what makes it unique and different from all the other Arduino boards. It allows us to connect with our circuits remotely over bluetooth, even from another room!

BoM

NoXeLWH1SlytcNha8JPRpA_thumb_3c4.jpg
ecg+TS3YTdaKjnJLwbwFfA_thumb_3be.jpg
  • Arduino 101 (or any bluetooth capable Arduino boards)
  • LED
  • 100Ω resistor
  • Jumper Wire
  • Breadboard

Wiring

Screen Shot 2017-08-06 at 1.19.56 PM.png
LED Circuit
kO+b54UnS4S568HDaS+wuQ_thumb_3c0.jpg
iWVvfB7pSsihcQvFeVBWKA_thumb_3c1.jpg
  • Connect the anode (positive pin) of the LED to a 100Ω resistor.
  • Then, connect this 100Ω resistor in series to pin 9 on the Arduino.
  • Connect the cathode (negative pin) of the LED to the ground pin of the Arduino 101 labeled as GND.

Coding

Screen Shot 2017-08-06 at 1.18.57 PM.png

The code is vastly different and more complex than any simple blinking an LED demo, since it needs to activate the bluetooth and interface properly. You can also change the name of your board under the command,

blePeripheral.setLocalName("Tech Martian");

This is the name that will show up in the App itself, so name it uniquely.

#include <CurieBLE>h>
BLEPeripheral blePeripheral;  // BLE Peripheral Device (the board you're programming)
BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
//set BLE characteristic
BLEUnsignedCharCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
const int ledPin = 9; // pin to use for the LED
 void setup()
{
 // set LED pin to output mode
  pinMode(ledPin, OUTPUT);
  // set advertised local name and service UUID:
  blePeripheral.setLocalName("Tech Martian");
  blePeripheral.setAdvertisedServiceUuid(ledService.uuid());
  // add service and characteristic:
   blePeripheral.addAttribute(ledService);
   blePeripheral.addAttribute(switchCharacteristic);
   // set the initial value for the characeristic:
    switchCharacteristic.setValue(0);
   // begin advertising BLE service:
   digitalWrite (ledPin, HIGH);
   blePeripheral.begin();
 }
void loop() 
{
  // listen for BLE peripherals to connect:
 BLECentral central = blePeripheral.central();
 // if a central is connected to peripheral:
  if (central)
  {
   // while the central is still connected to peripheral:
    while (central.connected())
    {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written())
      {
          // any value other than 0, turn on the LED
         if (switchCharacteristic.value()) 
         {  
         digitalWrite(ledPin, HIGH);         
         } 
      //else turn the LED off
       else 
      {                              
      digitalWrite(ledPin, LOW);         
      }
      }
     }
    }
  }

Downloads

Using the NRF Connect

Screen Shot 2017-08-06 at 1.20.17 PM.png
Screen Shot 2017-08-06 at 1.20.25 PM.png
Screen Shot 2017-08-06 at 1.20.33 PM.png
zOfpmwWnR0mca+Z9CElRKA_thumb_3c2.jpg
  1. Connect with your device, mine is called "Tech Martian," but yours may change.
  2. Under Unknown Service >> Unknown Characteristic, press the upload button.
  3. Choose Uint 8 on the drop down box and type 0 for OFF and 1 for ON

Done

LED Bluetooth Control

Play with the LED by setting different values on the app! This is just the beginnings of what you can do with bluetooth control. More is coming, stay tuned makers!