HM-10 Bluetooth LE

From ArduinoInfo
Jump to navigation Jump to search
print this page

HM-10 Bluetooth Low Energy Module How-To


See Bluetooth Thermometer example [/Temperature%20Reporting%20using%20HM-10%20How-To HERE]!

See Robot Control example [/Robot%20Remote%20Control%20Using%20HM-10 HERE]!


Bluetooth[WikiPedia] is a wireless technology standard for exchanging data over short distances (using short-wavelength UHF radio waves in the ISM band from 2.4 to 2.485 GHz) from fixed and mobile devices, and building personal area networks (PANs). Range is approximately 10 Meters (30 feet).
This module provides "Bluetooth Low Energy”. A new type of Bluetooth that is required for use with all cellphones, including Apple.

Description

HM-10 BLE (Bluetooth Low Energy) Module based on CC2541 chipset. HM-10 module is supplied as pre-soldered on carrier board. The carrier board has headers for easy connection and prototyping needs. This module can be used to create Arduino projects that talk to other devices. This is particularly useful for talking to smartphones. An example project of a Android app that talks to an Arduino over Bluetooth LE to get temperatures can be found [/Temperature%20Reporting%20using%20HM-10%20How-To HERE].


Using the HM-10

The HM-10 communicates with the Arduino over a serial connection. While it can be connected to the serial port pins on the roboRed, it's better to use SoftwareSerial instead. SoftwareSerial creates a virtual serial port in the Arduino software. This is better than the built in serial port because it doesn't interfere with programming the Arduino board, or the serial monitor. When using the HM-10 to talk to another device bytes are written to the serial port the HM-10 is connected to. The HM-10 then passes these on to a paired device. The same is true in reverse for sending data to the Arduino from paired device. For more on how to us the HM-10 to make Bluetooth connected devices, see the tutorial /Temperature Reporting using HM-10 How-To Here.


Setting Up the HM-10

The HM-10 defaults are:

  • Baud Rate: 9600 bps
  • Passkey: 123456
  • Device Name: MLT-BT05

In some cases you may want to inspect or change some of the configuration setup values. To do this AT commands are sent to the HM-10 using the serial monitor. AT commands are also useful to figure out what the configuration values already are. This sketch uses a software serial port to talk to the HM-10 via the serial monitor.

/*
  YourDuino Example: HM-10 Test/Setup
  Description: Uses the Serial Monitor to talk with the HM-10. Launch Serial monitor then use AT commands.
  Start with just "AT", should respond "OK", then "AT+HELP" to get other usable AT comands.
  Note that with HM-10 comands do not use ? or = after comand. i.e. rather than "AT+HELP?" simply use "AT+HELP"
  Make sure Seral Monitor is in CR & NL mode.
  Questions?    noah@yourduino.com


  Wiring:

  HM-10 Pinout
  RX to pin 9 (Sofware TX)
  TX to pin 8 (Sofware RX)
  Vcc to 5 V
  Gnd to Gnd

*/
/*-----( Import Needed Libraries)----*/
#include <SoftwareSerial.h>

/*-----( Create Instances )-----*/
SoftwareSerial BTserial(3, 4); //Create sofware serial instance

/*-----( Declare Variables )-----*/
char c = ' ';
boolean NL = true;

// Initialization
void setup()
{
  Serial.begin(9600);
  Serial.print("Sketch:   ");   Serial.println(__FILE__);
  Serial.print("Uploaded: ");   Serial.println(__DATE__);
  Serial.println(" ");

  BTserial.begin(9600);
  Serial.println("BTserial started at 9600");
}

// Arduino Execution Loop
void loop()
{
  // Read from the Bluetooth module and send to the Arduino Serial Monitor
  if (BTserial.available())
  {
    c = BTserial.read();
    Serial.write(c);
  }

  // Read from the Serial Monitor and send to the Bluetooth module
  if (Serial.available())
  {
    c = Serial.read();
    BTserial.write(c);
    Serial.write(c);
  }
}


AT commands are always of the the format:

  • Always starts with “AT”
  • Then “+” followed by <ParameterName>

Normal AT commands would then need to be ended with a “?” to return the current value of a parameter, or “=” to set a new value, however the HM-10 doesn't need them. Instead a command with no value after it is assumed to be a request for current value, and a command with a value after it sets a new value.
Sending just AT should get back an OK from the HM-10, if not check your wiring. Also make sure that the serial monitor is set to both CR & NL. Next type AT+HELP, this will display all the possible AT commands.


AT Commands

* Command Description
*----------------------------------------------------------------
* AT Check if the command terminal work normally
* AT+DEFAULT Restore factory default
* AT+BAUD Get/Set baud rate
* AT+RESET Software reboot
* AT+ROLE Get/Set current role.
* AT+DISC Disconnect connection
* AT+ADVEN Broadcast switch
* AT+ADVI Broadcast interval
* AT+NINTERVAL Connection interval
* AT+POWE Get/Set RF transmit power
* AT+NAME Get/Set local device name
* AT+LADDR Get local bluetooth address
* AT+VERSION Get firmware, bluetooth, HCI and LMP version
* AT+TYPE Binding and pairing settings
* AT+PIN Get/Set pin code for pairing
* AT+UUID Get/Set system SERVER_UUID .
* AT+CHAR Get/Set system CHAR_UUID .
* AT+INQ Search from device
* AT+RSLV Read the scan list MAC address
* AT+CONN Connected scan list device
* AT+CONA Connection specified MAC
* AT+BAND Binding from device
* AT+CLRBAND Cancel binding
* AT+GETDCN Number of scanned list devices
* AT+SLEEP Sleep mode
* AT+HELP List all the commands
* ---------------------------------------------------------------

Debugging

Problem: AT doesn't return OK
Check: 1. Make sure that the wiring matches the diagram as it's listen in the sketch.
2. Make sure that the serial monitor is set the both Carriage Return and New Line. Down in the bottom of the serial monitor is a drop down menu, it should say NL&CR.
3. Make sure that the light on the HM-10 is blinking. If it's not blinking this means it's connected to a device. AT commands will not work when the HM-10 is connected.

Another useful debug tool for later in a project is a Bluetooth Sniffer. These are apps that allow you to read detailed information about a connected Bluetooth device, including data sent. This can allow you to iron out if an issue is with Arduino code or with a phone app. There are lots of choices from various publishers, including some that can be downloaded at the bottom the article.

Features

  • CC2541 Bluetooth Chip
  • Fully Qualified Bluetooth V4.0 Ble
  • Full Speed Bluetooth Operation with Piconet Support and Scatternet Support
  • Small size with 3.3V or 5V input.
  • RoHS Compliant
  • UART Serial interface with baudrate setup function

Technical Specifications

  • Operating Voltage: 3.6V to 6V
  • I/O Voltage level: 3.3V or 5V
  • Bluetooth Standard: V4.0 BLE (Bluetooth Low Energy)
  • Working frequency: 2.4GHz ISM band
  • Authentication and encryption
  • Size:37.6mm x 16.6mm x 4.2 mm (without headers)
  • Header Pin pitch: Standard 0.1 inch (2.54mm)

Pinout

  • STATE
  • RXD
  • TXD
  • GND
  • VCC
  • EN

Supported OS

  • iPhone 4S/5S/Ipad8
  • Android 4.3 and Above
  • Windows 8


Documents and Downloads

Bluetooth sniffer apps for basic connection to the HM-10:

  • Manufacturer’s Android app called HMBLEComAssistant that can be used as Serial Terminal (no configuration required). The app requires manual installation of .apk file. Make sure you allow “verify apps over USB” in your android phone or tablet under developer options