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

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

Adapt your home automation project from our March 2017 workshop to be controlled through BLE using the Blynk app on your phone.

  • 904 views
  • 3 comments
  • 9 respects

Components and supplies

Ardgen 101
Arduino 101 & Genuino 101
×1
Screen shot 2017 02 16 at 2 iycvi9jlsg
MikroElektronika Arduino UNO Click Shield
Optional for Extension Project - See Hackster Live March 2017 Workshop Tutorial
×1
Screen shot 2017 02 16 at 2 2fejqs9vfo
MikroElektronika RELAY click
Optional for Extension Project - See Hackster Live March 2017 Workshop Tutorial
×1
09590 01
LED (generic)
×2
12002 04
Breadboard (generic)
×1
11026 02
Jumper wires (generic)
×3
08377 02 l
Resistor 330 ohm
×2
Adafruit industries ada62 image 75px
USB-A to B Cable
×1

Apps and online services

About this project

Introduction:

Last month Intel and Mikroelektronika sponsored the Hackster Live meetups and provided the hardware for our home automation project. Due to a delay in shipment of the hardware, many of you will be running the March workshop in April. I’ve put together this short tutorial using the Blynk app as an optional alternative to the voice control in our March workshop.

You may have noticed some disadvantages using web Bluetooth and annyang to control your lights with your voice. Mainly, web Bluetooth currently only works on Mac, Linux and newer versions of Android, and the voice recognition can occasionally be scrambled by background voices. If it worked for you, fantastic!! If it didn’t, you have other options and I’m going to cover one of those options in this tutorial. Last year we played around a little bit with the Blynk app using the ESP8266 Blynk Board. If you haven’t heard about Blynk you can check out more here.

This is a great app for people of all skill levels who really want to do some cool home automation.

What you need for this project:

Android:

  • Version 4.0.3 or higher - can check this by going to "settings" → “about this phone” and look for “Android Version”

Blynk App:

  • Download Android app on Google Play here.

Arduino IDE with Arduino 101 and Blynk Libraries installed:

  • Make sure you have installed the the Arduino 101 board we used in our March project. *Note - you should install version 1.0.7 which is an older version. There were problems with the Bluetooth connections when using the newer version 2.0.2.
  • You can then download the blynk library in your Arduino IDE by going to sketch --> Include Libraries --> Manage Libraries --> Search for Blynk --> Install.

Instructions:

Hardware Setup

  • Connect LED 1 (this matches relay one when using the relay) to pin 6 and LED 2 (this matches relay two when using the relay) to pin 10. Follow the Fritzing diagram and picture below:

*Note, the Fritzing diagram above shows an Arduino UNO. This is NOT the board we are using. You should be using an Arduino/Genuino 101. The UNO does not have BLE capabilities and will not work for this project.

Setting up the Blynk App:

  • Make sure you have enabled Bluetooth on your phone.
  • Open the Blynk app and login or create a new account if this is the first time you are using the app.
  • Create a New Project by pressing the "plus" button.
  • Create a name for your project.
  • Click on the scroll down arrow under choose device and select Arduino 101.
  • Click on the scroll down arrow under connection type and select BLE.
  • Click on the “Create” button and you will receive a notice that an Authorization Token has been sent to your e-mail. This token is now attached to this project. You will add it to your Blynk sketch in a later step to connect your phone and your Arduino 101.

Change the Authorization Code

  • If you want to change the authorization code and send a new code to your e-mail you can access it by going to the project settings (nut icon on top right corner of project main screen).
  • Click project name under “Devices”.
  • Click project name under “My Devices”.
  • You will see “Auth Token” at bottom with the last four digits displayed. Here you can change the code by clicking “refresh” and e-mail the new code by clicking “e-mail”.

Personalize your Project:

  • Go back to the main project page and click on the ‘+’ on the top right corner. This will bring you to the widget box. Here you can choose whatever widget you would like that works with your project components.
  • For my basic project (not the extended version using the relays) I want to turn on two LEDs that are connected to two separate pins on my Arduino 101. I would like to do this by pressing a button, so I am going to click on the button icon and now I have a button!
  • I want two buttons, so I will go back into the widget box and grab another button. Your screen should look like this:

(You can click and drag the buttons around the screen, or remove them by clicking and dragging them to the top menu to “return” them to the widget box).

Set Up Buttons 

  • We can now set our buttons to match our hardware set up.
  • Click a button - you will see a page where you can change the button settings.
  • Click on the ‘output’ box and scroll to which pin on the Arduino you would like your button to control. I have my first LED hooked up to digital pin 6, so I will choose ‘Digital’ in the left column, and ‘D6 pwm’ in the second column and then click ‘continue’.
  • I will also change my ‘mode’ to switch. This will allow me to push the button once to turn the LED on or off. If I leave the mode in ‘push’ then the LED will only light up when I am pressing the button.
  • Go back to the project page and repeat with the second button setting the pin to digital pin 10 (D10).
  • Since we will be using BLE we need a way to search for and connect nearby devices. To do this we need a Bluetooth button. We can go back to the widget box and scroll to the bottom of the page under ‘other’ to find the BLE widget.
  • You’re app is ready to run - now we need to set up our sketch.

Arduino Sketch:

  • Open the Arduino IDE
  • Open the Blynk sketch by clicking ‘File’ → ‘Examples’ → ‘Blynk’ → ‘Boards_Bluetooth’ → ‘Arduino_101_BLE’
  • Go to line 37 of the sketch and replace "YourAuthToken" with the 32 digit authorization code you were e-mailed when you created your project on the Blynk app.
char auth [ ] = "YourAuthToken"
  • Go to line 45 of the sketch and after local device name replace "Blynk" with a unique name no more than 8 characters long.
blePeripheral.setLocalName("Katie"); 
  • Plug your Arduino into your computer.
  • Check that your board is set to Arduino 101 and you have chosen the correct USB port.
  • Go to tools and open the serial monitor.
  • Upload your sketch and you should see the following displayed on your serial monitor.

Connect Bluetooth

  • Now go back to your Blynk app and click the Bluetooth button. Click ‘Connect BLE device’ and you should see a device called Blynk, or whatever you renamed your device. Tap OK and wait for device to connect.
  • You can see on your serial monitor when your device is ready or when it’s disconnected.
  • Go back to the main project page on your app and hit the play button on the top right corner.
  • Now you will see that your buttons are labeled OFF → Click one and it will turn to ON and your LED should light up.

You can now control your lights using BLE through your phone! This can also be used with the extended version using the relay click shield. As with all things relatively new, there can be issues. See some of the troubleshooting suggestions below if you run into problems.

Troubleshooting:

I see my device and can try to connect but it stays on "connecting" in the Blynk app and never connects.

  • Try checking the version of Intel Curie boards that you have installed in your Arduino IDE. You want to use version 1.0.7 and not version 2.0.2. Change this if needed and try again.

I cannot find my device when connecting to BLE.

  • If you have more than one project in the Blynk app using the BLE button, you will not be able to connect to your device - BLE can only be used in one project at a time.

I removed BLE from one of my projects so that it’s only visible in one project but I still cannot find my device.

  • Uninstall the Blynk app and then install it again.

My device keeps disconnecting.

  • Update your phone’s settings to prevent it from falling asleep. When the screen shuts off it will disconnect your device.

Code

Arduino_101_BLE_Blynk.inoArduino
/**************************************************************
 * 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.
 *
 **************************************************************
 *
 * This example shows how to use Arduino 101 CurieBLE
 * to connect your project to Blynk.
 *
 * Note: This requires CurieBLE library
 *   from http://librarymanager/all#CurieBLE
 *
 * NOTE: BLE support is in beta!
 *
 **************************************************************/

//#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();
}

Schematics

Fritzing Schematic
Lend me your ears snip inkrb6veo3

Comments

Similar projects you might like

Hackster Live March 2017 Workshop

Project tutorial by Katie Kristoff

  • 1,455 views
  • 1 comment
  • 12 respects

Smart Garbage Monitoring System Using Arduino 101

Project tutorial by Technovation

  • 22,660 views
  • 7 comments
  • 37 respects

Arduino Temperature Control

Project tutorial by Team pandhoit

  • 18,282 views
  • 10 comments
  • 28 respects

Arduino 101 BLE App

Project in progress by Alexis Santiago Allende

  • 10,795 views
  • 26 comments
  • 51 respects

Eco-Thing #1 "Eco-Smart-Container V1.0"

Project tutorial by Alexis Santiago Allende

  • 5,307 views
  • 4 comments
  • 28 respects
Add projectSign up / Login