Project tutorial
Arduino101 Bluetooth Interfacing

Arduino101 Bluetooth Interfacing © GPL3+

Use the Arduino101 Bluetooth wireless interface with the Blynk GUI Library for control of things directly from your phone or tablet!

  • 1,985 views
  • 0 comments
  • 13 respects

Components and supplies

Apps and online services

About this project

The Arduino101 features the Intel Curie Processor with a Bluetooth Low Energy Radio, Inertial Measurement Unit and sensors, in an Arduino Uno format.

Today we'll be learning about the Bluetooth Low Energy Radio and a simple method to get access to sensors and peripherals on your phone or tablet using the Blynk GUI Library to make our user interface.

Important

The following project was tested using a few specific versions of libraries and applications - as the most recent versions have some bugs in them.

If you experience problems, first make sure you are using these tested versions:

  • Arduino IDE Version 1.8.1
  • Intel Curie Board File Version 1.0.7
  • Blynk Version 0.4.6

Bluetooth Low Energy support in Blynk is still in BETA test status, so this is pretty new code that is being actively developed. Bluetooth security is also low. Be warned, there may be bugs and dragons here, as you are on the bleeding edge now...

Installation

On your laptop or computer, please install :

  • Install the Arduino_101_BLE_Relays.ino sketch from below.

On your smartphone or tablet, please install :

Start the Blynk Application on Android or iPhone

  • After installing the Blynk application, start it up
  • While Blynk is free, they do charge for using many "widgets" (it's how they stay in business...) for complicated GUI displays, this basic example should fit within a "free" account. You can add "Energy" in the store, usually start with a small amount (< $20), that will last for a number of different Blynk projects.
  • Blynk can "clone" a user interface project using a QRcode image - shine your camera at the image below :

Now your smartphone screen should look like :

Email the Blynk Authorization Code to Yourself

Press the "Setup" icon (the Nut Icon on the top right), and you'll get the setup menu like this :

Press the "Email All" button, and it Blynk will email you a unique authorization code for your device. You will need to enter that Auth Code String into your Arduino sketch (program) and then download it to your hardware in order to pair your device with your smartphone.

Plug in your Arduino101

The first time you plug in your Arduino101 board, it may take several minutes to identify and load drivers. Don't worry if you get an error the first time, the USB serial port can get disabled during Arduino101 reset, and can sometimes fail before the drivers get loaded. Note which serial port get assigned (i.e. COM7, etc.)

Program your Arduino101 Bootloader

  • Start the Arduino IDE
  • Under "Tools->Board Manager" select the Arduino/Genuino101 board
  • Under "Tools->Board Manager" select the correct serial port (i.e. COM7)
  • Under "Tools->Board Manager" select Programmer: Arduino/Genuino101 Firmware Update
  • Under "Tools->Board Manager" select "Burn Bootloader"

This will insure that your boards file and bootloader version match. If you have problems uploading, try burning the bootloader again.

Program your Arduino101

  • Cut the Blynk Auth Code from your Email and paste it into the Arduino Sketch in place of the "XXXX''s"
  • From the Arduino IDE select "Sketch->Upload", and your project will compile and get loaded into flash memory.
  • The default Device name under Bluetooth is "hack01", you can change this in the sketch if you wish to uniquely identify your board.

Install your Adapter board and Relays

If not already installed, unplug the Arduino101 and add the boards as shown:

Now your smartphone screen should look like:

The first thing we need to do is to connect to the Arduino101 Bluetooth - so press the little "Bluetooth" icon on the display:

Now press the "Connect BLE device" button:

Select your device from the list, in the workshop they should have different names for each team's device. "hack02" is shown here...

The internal gears will spin a bit, and then you should get a connected message:

Use the <- back arrow to return to the Relayer setup screen

Now make sure to press the "play" arrow in the upper right hand corner of the screen to change from "setup" mode to "live" mode. If you press the buttons in "setup" mode (which has the dotted background screen), you can change the button settings. In "live" mode, the four buttons operate the four (4) relays, turning them on and off.

How does it work?

In a Blynk enabled sketch, you can either call out physical device pins to manipulate, or use virtual device pins. I prefer virtual device pins for flexibility in porting a project to different boards and/or devices. Virtual pins also allow for arbitrary data types to be passed back and forth across a connection - making it easy to use Wi-Fi, or Bluetooth radios with little or no code changes.

Virtual Pins

Virtual pins are named V0 thru Vxx and use a simple access method:

BLYNK_WRITE(V1) { 
 int pinData = param.asInt(); 
 digitalWrite(relay1_pin, pinData); 
} 

V1 controls Relay1, V2 controls Relay2, V3, controls Relay3, etc.

Under the Widget settings for buttons, slider, etc is a pin select menu, just pick an unused virtual pin number to add a new function, either read or write or both.

The widget above will display a value sent from the device on VIrtual Pin V5 with a range of 0-1023 and update frequency of 1 second. Simple widgets, like the button, have less parameters to set. Use "Delete" to remove unwanted widget and to restore your "Energy Points" for making other projects.

Don't Flood the Server...

Free accounts are limited to the amount of data they can upload to the server, typically 10 pins per second, which is plenty for most applications. The easiest way to do that is to use a SimpleTimer set to interrupt once per second and update the pins. Another trick I use is to only send data change updates, not the raw data; and if your input data is noisy, then filter it first. See this ESP32/Blynk project for a more advanced example using timers data change flags and filters.

Okay, I got it, what's next?

Now that we have simple control of pins working from the Bluetooth Low Energy radio, in the next project we'll read the Inertial Measurement Unit and transmit the sensor data back to the smartphone. The Arduino101 has both a 3D Gyro and a 3-D Accelerator that we'll wire up in the next installment...

Code

Arduino_101_BLE_RelayerC/C++
Uses the Arduino 101 Bluetooth wireless interface to control four output pins, connected to four (4) mechanical relay units capable of switching over an amp of current each.
/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Social networks:            http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************
  Note: This requires CurieBLE library
    from http://librarymanager/all#CurieBLE

  Warning: Bluetooth support is in BETA!
 *************************************************************/
/* This sketch uses four (4) Blynk virtaul pins to 
   control four (4) mechanical relay units.
*/
//#define BLYNK_USE_DIRECT_CONNECT

/* Comment this out to disable prints and save space */
#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[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

BLEPeripheral  blePeripheral;

int relay1_pin = 6;
int relay2_pin = 10;
int relay3_pin = 5;
int relay4_pin = 9;

BLYNK_WRITE(V1) {
  int pinData = param.asInt();
  digitalWrite(relay1_pin, pinData);
}

BLYNK_WRITE(V2) {
  int pinData = param.asInt();
  digitalWrite(relay2_pin, pinData);
}

BLYNK_WRITE(V3) {
  int pinData = param.asInt();
  digitalWrite(relay3_pin, pinData);
}

BLYNK_WRITE(V4) {
  int pinData = param.asInt();
  digitalWrite(relay4_pin, pinData);
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB
  }

  pinMode(relay1_pin, OUTPUT);
  pinMode(relay2_pin, OUTPUT);
  pinMode(relay3_pin, OUTPUT);
  pinMode(relay4_pin, OUTPUT);
  digitalWrite(relay1_pin, 0);
  digitalWrite(relay2_pin, 0);
  digitalWrite(relay3_pin, 0);
  digitalWrite(relay4_pin, 0);
  
  blePeripheral.setLocalName("hack01");
  blePeripheral.setDeviceName("hack01");
  blePeripheral.setAppearance(384);

  Blynk.begin(blePeripheral, auth);

  blePeripheral.begin();

  Serial.println("Waiting for BTLE connection...");
  
}

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

Schematics

Arduino_101_BLE_Relayer Presentation
Workshop Slides and Presentation
Arduino101 BLE Workshop Presentation
Presenters Slides and Notes

Comments

Similar projects you might like

Arduino101 Bluetooth Intertial Measurement Unit (IMU)

Project tutorial by Tom Moxon

  • 1,378 views
  • 0 comments
  • 5 respects

Hackster Live April 2017 Workshop - Optional - Easy Add-on

Project tutorial by Katie Kristoff

  • 883 views
  • 3 comments
  • 7 respects

Arduino101 / tinyTILE BLE: Match-Making Sunglasses

Project tutorial by Kitty Yeung

  • 11,335 views
  • 2 comments
  • 35 respects

Home Automation With Arduino 101 Using Bluetooth Low Energy

Project tutorial by naveen manwani

  • 1,768 views
  • 0 comments
  • 4 respects
Add projectSign up / Login