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.
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.
- 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.
- 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”.
- 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.
- 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.
- 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.
Comments