HM-10-Bluetooth-HOW-TO+Examples

From ArduinoInfo
Jump to navigation Jump to search

This page will show you how to initially set up and test a HM-10 Bluetooth module. It will also show some practical examples / projects using the HM-10.

See Bluetooth Thermometer example HERE!

See Robot Control example 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 may be used with all cellphones, including Apple.

Description

HM-10 BLE (Bluetooth Low Energy) Module is based on the CC2541 chipset. The HM-10 sub-module is supplied as pre-soldered on a carrier board for easy use without special power regulation etc. 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 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 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. The following Arduino software sketch uses a software serial port to talk to the HM-10 via the serial monitor.

NOTE: EXAMPLE SKETCH MISSING HERE

AT commands are always of this format:

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

Normal AT commands would then need to be combined with a “?” to return the current value of a parameter, or “=” to set a new value. Interestingly, 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 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 command

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 of this article.

Description: 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

Description: Technical Specifications

  • 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)

Description: Pinouts

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

Description: Supported OS

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

Documents and Downloads

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

The Manufacturer of the HM10 has an 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.