Introduction: LED Bluetooth Control Using NRF Connect

Picture of LED Bluetooth Control Using NRF Connect

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!

Step 1: BoM

Picture of BoM
  • Arduino 101 (or any bluetooth capable Arduino boards)
  • LED
  • 100Ω resistor
  • Jumper Wire
  • Breadboard

Step 2: Wiring

Picture of Wiring
  • 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.

Step 3: Coding

Picture of Coding

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);         
      }
      }
     }
    }
  }

Step 4: Using the NRF Connect

Picture of Using the NRF Connect
  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

Step 5: Done

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!

Comments

About This Instructable

563views

14favorites

License:

Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: