Hello,

In this next part of the communication series we are going to discuss BLE(Bluetooth low energy). BLE is similar to Bluetooth because it runs on the same underlying principles but it sacrifices the data rate to be able to run on much lower power. This makes it ideal for wirelessly controlling battery powered devices. Another advantage of BLE is that it works with iOS as well(unlike Bluetooth Classic).

Introduction

BLE, like Bluetooth, has now proliferated all our mobile devices. It is available on Android devices running Android 4.3 or above and iOS devices starting from the iPhone 4. BLE also uses the same 2.4GHz frequency allowing devices to share the same antenna with Classic Bluetooth and WiFi. BLE has a low data rate of around 1Mbit/s. However this data rate is usually enough for normal serial communication which is usually enough for most wireless control.

For this post, I will be using this module which I picked up for around ~$10.

Things Needed

  • An Arduino
  • An LED or any device that can show output from an Arduino
  • A Serial BLE module
  • A computer or smartphone with BLE

Wiring It Up

Wiring for this is very easy, the module has only 4 pins. We need to connect the VCC and GND pins to 5V and GND on the Arduino. We can then use any 2 digital pins on the Arduino as Software Serial pins and connect those to the RX and TX pins of the Module. The schematic should look something like this:

My setup looks like this:

Code

The code for the Arduino to communicate with the BLE module is pretty straightforward, it is just serial communication. To make this even easier I have created an Arduino library called BLE Serial which can be downloaded from Github or directly from the Arduino library manager. After using the library, I will use the SimpleSerial example from the library. The code looks like this:

#include "BLESerial.h"
#include <SoftwareSerial.h>

BLESerial ble(10, 11);

void setup() {  
  ble.begin();
  ble.setName("5PBLE");
  ble.getName();
  ble.setBaud(BAUD_9600);
}

void loop() {  
  char dat;
  if (ble.available()) {
    dat = ble.read();
    Serial.print(dat);
  }

  if (Serial.available()) {
    dat = Serial.read();
    ble.write(dat);
  }
}

This code is just initializing the library with the module and outputting any incoming Serial data to the Serial Console of the Arduino, and any inputs to the Serial console are transmitted over BLE.

Usage

To use this data you will need a device with BLE and a serial monitor. You can use an Android Smartphone with the HMBLE Terminal or an iOS device with HM10 Bluetooth Serial apps installed.

Once you have the apps, you can just connect to the your device, and open up the Arduino Serial Monitor and start receiving and transmitting data. Thats it! You now have wireless communication over BLE.

Conclusion

You can use this and define a protocol to do any sort of BLE control or Data reporting from your Arduino to other BLE devices. This is the starting point for many smartphone controlled Arduino projects.