• Worldwide Shipping

  • 24/7 Customer Support

  • FAQ
  • Worldwide Shipping

  • 24/7 Customer Support

  • FAQ

HUM: BLUETOOTH MODULE HM-10

You are a beginner with Croduino. Or electronics? A specific module caught your eye, but you do not know how to use it? Do not worry, HUM is here for you! How to Use Module (HUM) is a blog tutorials series by e-radionica where you will find all you need in order to begin working with your favorite module. Tutorials include: technical characteristics, work principle, instructions on how to connect the module with Croduino and the basic code. Everything else is left to your imagination.

Introduction

The Bluetooth module HM-10 enables Bluetooth 4.0 (BLE 4.0) communication between your project and another Bluetooth device; e.g. a cell phone. The connection with Croduino is really simple, through serial communication, and the module works at a standard voltage of 3.3V and 5V. This module will function with iOS6 and larger systems, and with Android 4.3 and larger.

Characteristics:
• Bluetooth standard: 4.0
• functions with iOS6 and larger, and Android 4.3 and larger systems
• Voltage: 3V - 6V
• Current: 60uA - 400uA
• Antenna: on the printed circuit board
• Dimensions: 43mm x 16mm

How does it work?

The Bluetooth module HM - 10 is quite versatile, it has several versions and can be used in various combinations such as HM - 10 and Mobile device, HM - 10 and HM - 10, HM - 10 and PC, etc. This version is assembled on a breakout board that exposes the power supply and UART connections for pins that are suitable for work. The breakout board includes a 3.3V power controller that makes them 5V compatible. You should keep in mind that the RX pin is still 3.3V and when using Croduino's 5V, you should convert Croduino 5v TX to 3.3v for the HM - 10 RX.

Pin description
STATE - Connection state
LOW - when it is not connected. HIGH when it is connected.
VCC - Power supply 3.6v to 6v
GND - Ground
TXD - Serial UART transmit
RXD - Serial UART receive
BRK - Break pin. When the connection is active, setting the BRK pin to LOW disrupts the connection. When there is no connection, setting the BRK pin to HIGH or LOW has no effect, whatsoever.

LED on the HM – 10 module
On the module board, there is a LED that signals the connection. When the LED blinks, the connection is waiting, it is turned on for half a second and turned off for half a second. The LED remains turned on when the connection is established and blinks again when there is no connection. It basically shows the connection to another device and thus turns the LED on to show the connection status. After the pairing is complete, the connection closes and the LED turns off.

The behavior of the LED can be changed using the PIO1 command.
“AT + PIO10 ″ - Default setting. When it is not connected, the LED blinks for 500 ms. When it is connected, the LED is turned on.
“AT + PIO11 ″ - When it is not connected, the LED is turned off. When it is connected, the LED is turned on.

Bluetooth 4 BLE
BLE is not an upgrade to Bluetooth Classic, it's a different system with different uses. BLE works in a different way than earlier Bluetooth. BLE is designed for applications with low energy levels and it achieves this by using rare small data packages. This is not actually designed for continuous connections and large amounts of data. For something like this, Bluetooth Classic is a much better choice. Basically, BLE achieves its low energy consumption by not connecting it often, unlike Bluetooth Classic, which maintains a permanent connection.

There are 2 ways for BLE devices to communicate with each other; Broadcaster + Observer and Central + Peripheral. HM-10 can use both methods.
Broadcaster + Observer does not have a standard connection, the emitter, which is usually some kind of sensor, sends the periodic signals (advertising packages) that the Observer listens to. The emitter usually does not know if it has "listened" to something or not.
The Central + Peripheral scenario is more (but not the same) like the classic connection. When the central (main) device finds a peripheral (slave) device to which it wants to connect, it initiates a connection and takes the lead in managing the connection and timing.

HM-10 characteristics and services
The BLE is all about services and characteristics and just like all BLE devices, HM-10 has a set of services and each service has a set of related characteristics. Characteristics are located where the values are, some are READ, some are WRITE and some are both READ and WRITE.

All HM-10 services are pre-defined, except for one. This is a customized service that has one custom characteristics. Pre-defined services and characteristics are those in which UUID and name are determined by Bluetooth controllers. For example, the 0x2A00 characteristic is the device name and when the device has this characteristic, it should always be the name of the device.

The complete list of pre-defined characteristics can be found HERE, and the characteristics list HERE.

The HM-10 uses a custom characteristic to send and receive data received through the serial UART interface. It works by setting the value of the custom data value characteristic that is to be transferred. Then it sends the notification to the remote device and says that new data is available.
When you order HM-10 to transmit "HELLO", first it sets the value of the custom characteristic to "HELLO" and then sends a notification that tells the remote device "Hey, I have some new data, come and take it". The remote device scans notifications and when it receives a notification, it knows that a new value exists, so it reads the data, and then sends back the message "Thank you, I have it".
The custom characteristic can contain up to 20 characters, which means sending a string no longer than 20 characters, and the HM-10 divides data into 20 character segments and sends them one at a time until there are none left.

 

SERVICE 1
UUID: 00001800-0000-1000-8000-00805F9B34FB
GENERIC ACCESS
• UUID: 00002A00-0000-1000-8000-00805F9B34FB
• DEVICE NAME
• READ

• UUID: 00002A01-0000-1000-8000-00805F9B34FB
• APPEARANCE
• READ

• UUID: 00002A02-0000-1000-8000-00805F9B34FB
• PERIPHERAL PRIVACY FLAG
• READ/WRITE

• UUID: 00002A03-0000-1000-8000-00805F9B34FB
• RECONNECTION ADDRESS
• READ/WRITE

• UUID: 00002A04-0000-1000-8000-00805F9B34FB
• PERIPHERAL PREFERRED CONNECTION PARAMETERS
• READ

SERVICE 2
UUID: 00001801-0000-1000-8000-00805F9B34FB
GENERIC ATTRIBUTE
• UUID: 00002A05-0000-1000-8000-00805F9B34FB
• SERVICE CHANGED
• INDICATE

SERVICE 3
UUID: 0000FFE0-0000-1000-8000-00805F9B34FB
CUSTOM SERVICE
• UUID: 0000FFE1-0000-1000-8000-00805F9B34FB
• CUSTOM CHARACTERISTIC
• READ/WRITE/NOTIFY

The main part of the user UUID service (FFE0) and the main part of the custom characteristic can be changed using the AT commands. You can also add another characteristic.

How to connect it?

Now, we will demonstrate a very simple Croduino and HM - 10 switch that will turn the LED diode on or off via cell phone. For this switch, we will need Bluetooth HM - 10, Croduino, LED diode, few wires for connecting and of course, the cell phone.

VCC HM – 10 is connected to 5v or 3.3v of the Croduino, GND to GND, RXD is connected to Croduino's digital pin 11, and TXD to digital pin 10.

In order to be able to control the switch, we will need a device that we will use to control it, e.g. a cell phone. We will need an application for controlling the Bluetooth device via cell phone, in this example, we will use the Serial Bluetooth Terminal application that can be downloaded via google play store for Android.

If you have successfully connected and copied the code, when you connect to your mobile device, you should receive the message "Bluetooth connection is on" at the terminal of the application.
With the "on" command, you will illuminate the LED diode built on Croduino and the breadboard, and receive a message "It is on!", and with the "off" command you will turn them off to get the message "It's off!".

Arduino library and the code

For this code, you will need the SoftwareSerial library, which can be downloaded HERE.

// Using the Software Serial library
#define softserial
// LED diode initialization
const int LED = 13;
const int LED_ext = A0;
#ifdef softserial
#include „SoftwareSerial.h“ //in case the code does not work, instead of quotation marks
//insert arrows
const int BTRX = 10;
const int BTTX = 11;
SoftwareSerial SerialBT(BTRX, BTTX);
#else
HardwareSerial SerialBT = Serial1;
#endif
// Sending the message
String msg;
// Setup for connection establishment with the HM - 10
void setup() {
SerialBT.begin(9600);
SerialBT.println("Bluetooth connection is on");
pinMode(LED, OUTPUT);
}
//Loop
//Wait for the message in each iteration
//Analyze the message,
//turn on, and then turn off the LED
void loop() {
if (SerialBT.available()){ // the data is in:
msg = SerialBT.readString(); // Read the message
if (msg == "on") {
digitalWrite(LED, HIGH);
digitalWrite(LED_ext, HIGH);
SerialBT.print("LED on the Pin ");
SerialBT.print(LED);
SerialBT.println("Turned on!");
}
else
if (msg == "off") {
digitalWrite(LED, LOW);
digitalWrite(LED_ext, LOW);
SerialBT.print("LED on the Pin ");
SerialBT.print(LED);
SerialBT.println("Turned off!");
}
else {
SerialBT.print("Command unknown command");
}
}
}
Leave a Reply