AndroidArduino projects

Arduino HM-10 Bluetooth control LED Android App

Bluetooth is one of the most popular and easy to use wireless technologies. Over the years, the Bluetooth standard has undergone many upgrades to keep pace with the current technological changes and future technologies and to meet the needs of users. From Bluetooth version 1.0 to Bluetooth version 5.0, there are many changes, including higher data rates, low current consumption that can be used for IoT, improved security, etc. To learn Bluetooth communication, there are many modules that can be used, which can be connected with a microcontroller. One of the Bluetooth modules is HM10, which is based on Bluetooth 4.0.

What is the HM10 BLE 4.0 module?

The HM10 is a serial BLE module (Bluetooth Low Energy) designed for low power applications that can last a long time even with a coin-sized battery. The HM10 is a Bluetooth 4.0 module based on the Texas Instruments CC2540 or CC2541 BLE System SoC (System on Chip). The firmware and design of this module is made and managed by Jinan Huamao Technology. The module comes with a serial/UART layer that enables the device to interface with different microcontrollers. The HM10 is ideal for creating simple connections and using with or as an iBeacon.

Arduino HM-10 Bluetooth control LED Android App

The HM10 has become a very popular Bluetooth 4.0 BLE module. The HM10 is a Bluetooth 4.0 based module only, so it will not connect to Bluetooth 2 / 2.1 modules such as the HC-05, HC-06 and other Bluetooth modules. The HM10 is controlled via AT commands sent over a serial UART connection.

The difference between HM10 and other Bluetooth modules

The main difference of HM10 is the Bluetooth version. HM10 is a Bluetooth 4.0 module, so it has all Bluetooth version 4.0 features like speed, throughput, and range. HM10 offers data rates up to 24 Mbps and low energy/low power consumption. In addition to that, HM10 offers a range of 100 meters in open space. When compared to other Bluetooth modules like the HC-05, which is a Bluetooth 2.0 based module, HM10 does perform better than the HC-05. The HC-05 can only offer 3 Mbps speeds compared to the HM10.

Bluetooth modules HC-05 and HC-06 are still very popular among makers and hobbyists because they are cheap and easy to connect. We have also made many projects using HC-05/06 and connected them with many other microcontrollers:

●    Use HC-05 Bluetooth module to control Arduino development board

●    Getting started with HC05 Bluetooth module on Arduino development board

Today we will connect the HM-10 BLE module to the Arduino Uno development board to control the LED wirelessly using the Bluetooth protocol. The on/off command will be sent by the smartphone.

Required Components

● Arduino UNO development board

● HM10 Bluetooth module

● Resistors (1kΩ, 470Ω)

● Jumper

● Arduino IDE

● Arduino Bluetooth Controller (HM-10 Module) Android App

● Android smartphones

Circuit Schematic

The circuit diagram for interfacing Arduino with HM-10 Bluetooth module is very simple as shown below.

 

Arduino HM-10 Bluetooth control LED Android App

Arduino HM-10 Bluetooth control LED Android App

Before starting the project, make sure that your HM-10 module is an authentic HM-10 module. There are many cloned versions of HM-10 modules available in the market. To identify the difference between the original and cloned HM-10 module, just look for the 32KHz crystal on the HM-10 board. If there is a crystal, then it is an original HM-10 module and you do not need to change the firmware. On the contrary, if you do not see the crystal, then it is a cloned HM10 module and you need to change the firmware of the cloned HM-10 module. Without changing the firmware of the HM-10, neither you can access the HM-10 module using AT commands nor pair it with a smartphone. Here we are also using a cloned module, so we flashed its firmware before connecting it with Ardruino.

Arduino Bluetooth Controller (HM-10 Module) Android App

Arduino Bluetooth Controller (HM-10 Module) is an Android app that is available for free download on the Google Play Store. This app features an easy to use interface for the HM-10 BLE module. When testing it, it was able to quickly find the HM-10 and connect with it right away. The app has some cool features like you can create a button and customize it with a custom name and function. Here we will go over how to create two buttons in this Bluetooth controller app to turn on and off an LED connected to the Arduino.

Here are the steps on how to setup an Arduino Bluetooth Controller (HM-10 Module) Android App:

◾ Download the app from the Google Play Store .

◾ The homepage of the app is shown below, where you can find many features like connect device, search icon, delete icon, device status, send text, add template, etc. First search for a device by clicking on the search icon or by clicking on the three dots on the top right corner and then select connect device.

Arduino HM-10 Bluetooth control LED Android App

 

◾ All available devices will be displayed on this interface. Select the correct HM-10 module.

◾ Now the HM-10 will be connected successfully and you will be able to see the status of the HM-10 at the top of the interface.

◾ Now you can write what you want to send in the text section and tap the arrow to send, send text or string directly, or you can create a custom template.

◾ Save time by creating custom templates. Click the “+” icon in the upper right corner and fill in the details. ” Name ” is the button name, the ” Text ” field is for the text or string sent to the HM-10, and ” Description ” is simply a description of what the button does.

◾ First, create a button for turning the LED on and assign it a green color. The button will send the letter “N” to the HM-10, which will light up the LED connected to the Arduino. Similarly create a button for the LED off and assign it a red color. The button will send the letter “F” to the HM-10, which will turn off the LED connected to the Arduino.

◾ Now, you can see two buttons created just below the text field. Now, if you want to control the LED then just click on the buttons.

This completes the setup of android app to control HM-10 module. Now we start programming Arduino Uno board to get the characters from Android application.

Programming Arduino UNO to control LED using HM-10 Bluetooth module

The complete code is given at the end of this article. Programming Arduino UNO for this project does not require much effort nor any library. You can use both Hardware Serial and Software Serial libraries. If you are using Software Serial, then just include Software Serial library, otherwise go ahead with Hardware Serial. In this article, we are using SoftwareSerial. First include Software Serial library. Pins Rx and Tx are connected on pins 2 and 3 of Arduino.

  1. #include <SoftwareSerial.h>
  2. SoftwareSerial HM10(2, 3); // RX = 2, TX = 3

Copy code

Define two variables to store the data received from HM10 and Android app.

  1. char appData;  
  2. String inData = “”;

Copy code

Start the hardware and software serial ports at 9600 baud and print some debug statements. The LED pin is set as an output and the initial state is set to OFF.

  1. Serial.begin(9600);
  2.   Serial.println(“HM10 serial started at 9600”);
  3.   HM10.begin(9600); // set HM10 serial at 9600 baud rate
  4.   pinMode(13, OUTPUT); // onboard LED
  5.   digitalWrite(13, LOW); // switch OFF LED

Copy code

Start listening to the HM10 port and reading strings until the HM10 is available and sends data. Save the data in a string.

  1.   HM10.listen(); // listen the HM10 port
  2.   while (HM10.available() > 0) { // if HM10 sends something then read
  3.     appData = HM10.read();
  4.     inData = String(appData); // save the data in string format
  5.     Serial.write(appData);
  6.   }

Copy code

To debug the HM10 using AT commands, just write the following line of code which sends a string to the HM10.

  1. if (Serial.available()) { // Read user input if available.
  2.     delay(10);
  3.     HM10.write(Serial.read());
  4.   }

Copy code

If the received string is “F”, then print the message on the serial monitor and then turn off the LED; if the received string is “N”, then print the message on the serial monitor and blink the LED at an interval of 500ms.

  1. if ( inData == “F”) {
  2.     Serial.println(“LED OFF”);
  3.     digitalWrite(13, LOW); // switch OFF LED
  4.     delay(500);
  5.   }
  6.   if ( inData == “N”) {
  7.     Serial.println(“LED ON”);
  8.     digitalWrite(13, HIGH); // switch OFF LED
  9.     delay(500);
  10.     digitalWrite(13, LOW); // switch OFF LED
  11.     delay(500);
  12.   }

Copy code

This completes the complete post on how to control LED using Arduino and BLE HM10 Blutooth 4.0 module. Again remember if you have an original HM10 module then you don’t need to re-flash the firmware and can use it immediately. But if you are using a cloned HM-10 module then flash the firmware on the cloned HM10 BLE module. If you have any questions or suggestions then please reply below this post.

Code

Here is the complete code used in this article:  main (1)

Back to top button