loading
I've seen a lot of Kickstarter projects featuring the new Bluetooth 4.0 Low Energy standard and a number of Bluetooth LE (BLE) enabled Arduino clones coming to market, but many of these projects still seem to be somewhere in the production process and I couldn't find a lot of practical information about how to get BLE connected with Android.

This is my proof-of-concept attempt at working with Bluetooth LE, Android and Arduino. For my project I'm using an inexpensive module based upon TI's CC 2540 chip called the HM-10. It is only the second time I've tried to put together an Android app, so improvements and collaboration are very welcome!

You might be thinking "Bluetooth?!? But that's been around forever, what's the big deal?" The new standard attempts to address some of the short-comings of Bluetooth by simplifying the pairing process and reducing power drain, aiming to replace an array of proprietary radios and protocols with something more standardized. Popular applications have included fitness trackers (Fitbit, Nike+, etc) and in-store notification beacons (see Apple's iBeacon) but now BLE is starting to make its way into all kinds of consumer devices.

You can find all the necessary code here.


What you need

1 x Bluetooth LE / 4.0 module

HM-10 modules can be purchased for $6-7, including breakout board $10-15

Make your own breakout board
via AliExpress
via eBay

Red Bear Lab sells an Arduino shield and mini BLE module based upon the same TI CC2540 chip. They have some neat examples  for iOS and Android. The Android program I've included should work with their shield with a few minor adjustments.

1 x Arduino (or similar) microcontroller

RGB LED Strip

This tutorial uses Adafruit Neopixel / WS2811 RGB LED strip, but you could adapt it for other types of strip, or even a regular RGB LEDs without an IC.

Android device with BLE support, running 4.4 KitKat or later

Support for Bluetooth 4 was added to Android as of version 4.3. So far as I can tell, at this point only a limited number of Android devices support BLE. Among them are the Nexus 4 and 5, Galaxy S4. I tested this with a LG Nexus 4 running Android 4.4.2, it may work with other devices and pre 4.4.2 versions of Android but I don't have any handy! (I would love to know if it indeed does)

Arduino photo CC-BY Creative Tools / Jota Cartas

Step 1: Assemble, Test, Configure Your Bluetooth LE Module

We're using the BT module to transparently send/receive data and shouldn't need to change much from the factory default settings. I do find it helpful to set a unique name and confirm that your module is working properly. To do this you'll need a FTDI cable or an Arduino board.

Important: The HM-10 runs at 3.3V, many Arduinos are 5V. If you connect your BLE module to something 5V without a logic level converter and voltage regulator you will likely damage it.

If you bought a HM-10 module that includes a breakout board, fantastic, you're set to go. If you need to build a breakout board head over to this tutorial. If you want to work out something on your own, you can find the pins arrangement on this datasheet.

Using a serial/FTDI cable

Connect
HM-10 TX - FTDI RX
HM-10 RX - FTDI TX
HM-10 GND - FTDI GND
HM-10 VCC - FTDI VCC

Then connect to the FTDI cable via the console or your favorite serial terminal. Some that work well:

Linux/Mac - CuteCom
Linux/Windows/Mac - CoolTerm
Windows - RealTerm

Settings: 9600, N, 8, 1;

If you're using an Arduino

Open the Arduino software, then upload Examples -> SoftwareSerial -> SoftwareSerialExample to your device

Connect
HM-10 TX - Arduino Pin 10 softRX
HM-10 RX - Arduino Pin 11 softTX
HM-10 GND - Arduino GND
HM-10 VCC - Arduino 3.3V

Open the serial monitor at 9600 baud.

Commands
The BLE module uses AT Commands to read and write system information, they do not need to be followed by a line break. If you don't get a response when you enter a command something may not be connected properly and you'll need to troubleshoot your module.

When you're connected type:
AT - it should respond with OK

You can find your firmware version:
AT+VERS? - firmware version

And set your device's name:
AT+NAME? - get current name
AT+NAMEyourname - set the name (12 chars max)

A full set of AT commands in the datasheet

If everything appears to be working it's time to move on to installation of the Android and Arduino apps!

Step 2: Install the Arduino Sketch

If you're using WS2811/WS2812 Strip

Copy and install the Arduino sketch. You can find the code here.

If you're using RGB LEDs without an IC

You can use this sample code instead.

Step 3: Connect Your Bluetooth Module and LEDs to Your Arduino

Connecting HM-10 to Arduino

Connect Bluetooth RX and TX pins to your microcontroller. In my case I'm not going to use the Arduino's USB so I'm utilizing the built-in serial port on digital pins 0 and 1. If you need USB functions of your microcontroller try using software serial.

HM-10 RX - Arduino TX (D1)
HM-10 TX - Arduino RX (D0)

Connecting RGB LED strip

For the WS2812 lights you only need 3 pins: Data to digital pin 6, 5V and GND. If you are using a different strip you might have 4 pins and will need to include relevant code for driving those lights.

If you're using RGB strip or LEDs without some kind of IC you can follow this Arduino example.

Connect power source to your Arduino

I'm using a USB Power pack, but you could use a wall wart or a USB connection to your computer.


Step 4: Install the Android Application

Install the app

The application is still at a 'proof of concept' stage, so it's not quite ready for the Play Store. If you want to download it you'll need to side-load it. I was hoping I could use App Inventor or PhoneGap to create a quick app with BLE support, but this functionality is so new it's not supported yet, so I tried my hand at the Android SDK!

First enable apps from Unknown Sources by checking:
Settings -> Security ->Unknown Sources

Download the APK either directly to your phone or copy it over USB and use a file browser to run the file.

What this app does and how to modify it

The app is extremely basic, after you connect to the BT module, it looks for a serial service and then takes values from 3 sliders and sends them as a string to the Arduino where they are translated into LED values. It's based on Android sample code.

Bluetooth LE uses something called the Generic Attribute Profile (GATT) model which defines Services and Characteristics, these are identified by a value called UUID. The HM-10 has a Service that allows you to pass-through data, I found the UUID to be 0000ffe0-0000-1000-8000-00805f9b34fb. The Characteristic that you use to send and receive data has a UUID of 0000ffe1-0000-1000-8000-00805f9b34fb

Please feel welcome to modify and improve the source. it's incredibly helpful to first install the Android SDK Bundle

The main files you work with live here
BluetoothLeService.java - Bluetooth LE functions
DeviceControlActivity.java - What happens when you connect to a device
DeviceScanActivity.java - Routines for scanning for BLE devices
SampleGattAttributes.java - Defines recognized Services and Characteristics

nRF Master Control Panel was very useful for sniffing Services and Characteristics and learning more about BLE devices

Step 5: Put It All Together

1. Plug in your Arduino.

2. Open the Blue Light Android app. If everything is working correctly you should see your BLE module within range. Select it!

3. If the connection is successful, the second screen should show 'State: Connected' and if the serial Service is found 'Yes, serial :-)'

4. Adjust the sliders and your lights should change color

5. Hack, celebrate, modify, play and enjoy!

Future Improvements

* More versatile Android app (Support for patterns, color picker, etc)

Future BLE Projects

* Replace Arduino with an ATTiny
* Utilize the GPIO pins on the HM-10
* iBeacon (supported as of newest HM-10 firmware)
* Attempt to flash HM-10 with open source Biscuit firmware from Red Bear Lab

Step 6: Make Something Beautiful

What you need

* a cardboard tube
* tape
* a power or USB extension cord
* a paper lantern

Place the Arduino and Bluetooth module inside the cardboard tube, cover the bottom with another piece of cardboard so they don't fall out. Wrap your LED strip around the outside of the tube and tape in place.

Attach the power or USB extension cord to your Arduino.

You can hang your lantern via a hook in the ceiling or run some monofilament (fishing line) across your room.

Place the cardboard tube inside your lantern, you can poke holes in the top and hang it by string or wire. Now, you have an Android & Bluetooth LE controlled RGB lamp :-)
<p>I wanted to leave a tip about pairing. If pairing is required in your application, send AT+TYPE3 to your HM-10. Default pin code is 000000. Change that by using AT+PINxxxxxx, where xxxxxx is a number between 000000 and 999999.</p><p>NOTE1: AT+TYPE3 was added in firmware v524. (Check firmware version by AT+VERS?)</p><p>NOTE2: Use AT+TYPE0 to go back to default where no pairing required.</p>
<p>When I try to use AT+TYPE3, I can't control RGB Lights. After entering a PIN code, status become Connected, but there's missing &quot;Yes, serial! :)&quot; message.</p><p>Firmware is v540.</p><p>Does anyone have any idea?</p>
<p>Notice that it is actually AT+PASSxxxxxx instead of AT+PINxxxxxx</p>
<p>I need help!!</p><p>When I typed AT at 9600 baud.. I got this message as a reply. Help. </p><p>Goodnight moon! &yuml;</p>
<p>I have the same problem! Did you ever figure out what was wrong?</p>
<p>Check out this android app:</p><p>https://play.google.com/store/apps/details?id=com.optimist.bleCentral&amp;hl=en</p>
<p>Blue light.apk do not work .pl attached correct file . do not scan any <br>Bluetooth device how to control without app pl help me as soon as <br>possible.</p>
<p>Is there a way to control HM 10 module to operate in advertising mode only after pressing the switch/button so that power consumption is less. On pressing the switch, the device will operate in advertising mode and will again move to connectable mode. When the device is in adevrtising mode, it will be visible to master devices (mobile application) and on triggering the connect from the mobile device, blutetooth connection will get established. On subsequent reboots, device will be in connectable mode unless switch is pressed. Since device is in connectable mode, mobile app can directly connect to the device by selecting the connect option for bluetooth device.</p>
<p>sir can you please send me a modification of this apk? instead of controlling rgb leds, can you send me one that can control 2 servo motors? thanks! </p>
<p><br> <a href="https://www.instructables.com/member/stvmac11" rel="nofollow">stvmac11</a><br> <br> <br> <br> <br> <br></p><p><br> 2 years ago<br> </p><p>I wanted to leave a tip about <br>pairing. If pairing is required in your application, send AT+TYPE3 to <br>your HM-10. Default pin code is 000000. Change that by using <br>AT+PINxxxxxx, where xxxxxx is a number between 000000 and 999999.</p><p>NOTE1: AT+TYPE3 was added in firmware v524. (Check firmware version by AT+VERS?)</p><p>NOTE2: Use AT+TYPE0 to go back to default where no pairing required.</p><p>===================================</p><p>I SEARCH FOR THIS INFO ONE WEEK, MANY THANKS :) </p><p>FOR FIRST <br>TIME THE BLUETOOTH ASKING FOR PIN CODE BUT STILL MY TELEPHONE CAN'T <br>PAIRING WITH IT &quot;UNABLE TO PAIR WITH XXXXX, MAKE SURE XXXXX IS READY TO <br>PAIR. </p><p>ANY SUGGEST PLEASSSE ?</p>
<p>Nice tutorial can you code for ios . i want to do that thing ios please help me</p><p>my mail id : gupta.sunkari@gmail.com</p>
<p>For anyone that might be interested. I just published free iOS and Android app, that lets you control Arduino with gamepad style interface. The app is compatible with the most popular HM-10 BLE to Serial module.</p><p>More info:</p><p>https://www.instructables.com/id/Controlling-Arduino-Robot-With-IOS-IPhone-IPad-or-/</p>
<p>Does it remember the last used settings after power off or disconnecting BT?</p><p>Many thanks :)</p>
<p>I have tried sending some value per 100 ms delay from arduino.</p><p>How come the the &quot;data&quot; field shows &quot;no data&quot; until you press on the slider? how can you just get the data from a button press? </p><p>I know it gets read with displayData(intent.getStringExtra(mBluetoothLeService.EXTRA_DATA)); but how can I invoke this and get a value?</p><p>Thanks</p>
<p>Hi, great project! I am working on a Bluetooth project of my own and used your guide to get me up and running. Many thanks! </p><p>How did you build your Android app, was it App Inventor or something else? Would you be willing to share your Android app code?</p><p>Would you be willing to share your app code? </p>
<p>danasf,</p><p>Thanks for posting! Has anyone attempted to talk to HM-10 BLE device from IOS/iPhone? I have your sketch loaded, and adapted to my NeoPixel strip and SoftwareSerial pins. I'm started using LightBlue as my IOS Central node. I can send data from LightBlue to the HM-10 and the sketch sees some data, but when I print the values of 'red,' 'green,' and 'blue' to the serial monitor in the Arduino IDE, the values are always zero. After switching to a utility called &quot;Bluetooth BLE Utility&quot; (by Xin Shi), I was able to talk to the sketch and light the NeoPixel. </p><p>also enabled a servo driver in the circuit...</p>
<p>I am facing a strange issue<br> where the App operation doesn't trigger the Bluetooth chip(the App control doesn't change the RGB values) , if I run the board from the 9V battery. </p><p>But it works fluidly from the FTDI cable from Laptop.<br> I have checked the terminal voltages for the BLE module, it is 3.45 V in both cases.<br> I am not even getting a clue of whats wrong please comment if you think there is any related problem if you can think of...<br>Thanks in Advance</p>
<p>hello guys,</p><p>my project is communication between 2 point via wireless,</p><p>i wanna to work with this module (XM-10B BLE);but i dont know about this anything!! :(</p><p>i have a CC Debugger (Ti),</p><p>how i can program this module ?</p><p>is a sample of program?</p>
<p>You mention that the UUID to pass through data is 0000ffe0-0000-1000-8000-00805f9b34fb, which mine is set to. How do I change this to 0000ffe1-0000-1000-8000-00805f9b34fb in order to send and receive data.</p><p>I've found your app is one of the only ones I can connect with, but would like to try using other SPP apps but none will connect and stay connected.</p><p>Thanks for the great tutorial!</p>
<p>I'm really quite new to android and arduino development, but want to be able to modify the android app so that it serves for my own purposes. I have no idea how to do this at the moment and any help would be massively appreciated! I saw you based it off the google example, but I didn't understand any of that :(</p><p>Thanks very much for the great tutorial,</p><p>Hugh</p>
<p>Hi there!</p><p>Just a quick question. How would one go about this using a &quot;IC-less&quot; CA or CC RGB strip? I have one HM-10 connecting correctly but it's not taking RGB values from the app. This is using SoftwareSerial. </p>
<p>The Android program isn't work on Android 4.1.1 .</p><p>Can you help me?</p>
<p>This is just what I was looking for. I have hooked up a ws2812b 30 led stip connected to Arduino pro mini via USB - UART and I change colors via arduino console right now. I wanted to do it wirelessly independent of my desktop.</p><p>Although I would be using the cheaper HC-05 to do it but then your instructable as made it a lot easier for me to do it.</p>
<p>I finally made it. Video @ https://youtu.be/TbICCFW7LYw</p>
<p>it's great tutorial !. thanks for share it.</p><p>I have a final project to build android app using BLE, this tutorial is very helpful for me. but I have some problem... in my final project I use 2 bluettoth that communicate with an android device, when search on web I find this called PICONET, but there is no exemple project that use this metode, I'm an newbi in android , my question is,,, is it possible to build this projret ?... and do you have some tutorials about this ? thanks.</p>
<p><strong>&quot;Future BLE Projects</strong> <br> * Attempt to flash HM-10 with open source <a href="https://github.com/RedBearLab/Biscuit" rel="nofollow">Biscuit firmware</a> from <a href="http://redbearlab.com/blemini/" rel="nofollow">Red Bear Lab&quot; </a></p><p>Did you manage to do that? I am trying to interface my iPhone over the HM-10 with the arduino, but the RedBearLab App isn't compatible. I am hoping that with the Biscuit firmware it could work. </p>
<p>I created aa walkthrough for iOS apps that'll connect to the HM-10/11.</p><p>http://letsmakerobots.com/content/connect-arduino-your-iphone</p>
<p>Has anyone done this with a BlueDuino and Neopixel ring yet?</p>
<p>Thank you very much. This is awesome. My question for you:</p><p>How were you able to figure out what the Services and Characteristics were for sending data? I've been trying to figure out &quot;serial&quot; on this BLE device for the past month. Any insight would be great. Thanks again!</p>
<p>From my notes, Service is:</p><p>0000ffe0-0000-1000-8000-00805f9b34fb</p><p>and Characteristic:</p><p>0000ffe1-0000-1000-8000-00805f9b34fb</p><p>I used the nRF Master Control Panel (BLE) Android app to figure this out. Best of luck!</p>
<p>Very helpfull! thanks so much!</p>
<p>Im doing this once i get my stuff, waiting on HM-10 and the RGB that is mentioned above. i have a question about this ( Utilize the GPIO pins on the HM-10 ), im new to this so )))) does this means you can use the HM-10 to control RGB without arduino or a microcontroller? Im looking the way to have just power+ble=power+rgb, is that possible ? Thanks for the help</p>
<p>I haven't done much with the GPIOs yet but I've thought about using with transistors or optoisolators to drive relays or non-addressable RGB LED strip. </p><p>You couldn't toggle the pins quickly enough over BT to meet the requirement of WS2811's data protocol (driving these may be possible via the TI CC2540 on this board, but that would require reprogramming firmware). </p><p>If you want to use those addressable lights a cheap and easy solution you could interface is ATTiny85. That Neopixel library works great with these, they cost less than $1 (see my other Instructable)!</p><p>My primary computer failed and I only received my replacement today so look for more updates and Instructables soon :-)</p>
<p>thanks bud, ill definitely will wait on updates! </p><p>never heard of optoisolators ))) still newbie, but this stuff is very interesting to me. gonna check that other instructable out, RGB should come tomorrow, so ill try to hook it up to my HC-06, HM-10 is still on the way ((</p>
<p>Could you explain the process of creating android app in detail?</p><p>From using master control panel to final app?</p><p>I cannot find any understandable tutorial on how to create app from scratch.</p>
<p>I'm still very new at Android development myself so I may not be the best instructor at this point. I will try to follow up when I can offer more advice and detail! I started with the example code provided here: </p><p>https://developer.android.com/guide/topics/connectivity/bluetooth-le.html</p>
Hello, I'am from Morelia Mexico and I'm surprised with the Android software to connect to BLE HM-10 module. I would like to read data from the module and the example only sends data. It would be possible to help me to receive data?<br><br>In advance thank you very much.
Hello, I'm still learning but I made a minor update to the code -- defined <em>characteristicRX</em> and <em>setNotification</em> for this to <strong>true</strong>. Now incoming data should appear next to <strong>Data</strong> on the LED control screen. Good luck with your application and I welcome improvements to the Android app.
Big favourite for changing the default licence. Great guide, looking forward to trying it out. <br>As an aside: What make is your espresso machine? Looks similar to my La Pavoni Europiccola.
Thanks! It's a Gaggia Factory, largely the same as the Europiccola with a few cosmetic differences found it on closeout :-)<br> <br> BTW I like your LED jar write up, I've built similar as gifts, though I have yet to do a write up: https://lh5.googleusercontent.com/-g3rX-B2U1TE/UnWDVCZXHlI/AAAAAAAAAss/2IBo9w2_awg/s426/IMG_20131023_205151.jpg

About This Instructable

190,166views

162favorites

License:

Bio: Sharing knowledge and ideas. Constantly learning!
More by danasf:Intel Edison and Addressable LEDs Internet of Ducks Lighting In A Bottle 
Add instructable to: