How to Use HM-10 BLE Module With Arduino and Control a LED With It
by Utsource in Circuits > Arduino
763 Views, 0 Favorites, 0 Comments
How to Use HM-10 BLE Module With Arduino and Control a LED With It
Things You Need
For this instructables we will need following things :
Arduino UNO
HM10 Bluetooth Module
Resistors(1 kΩ, 470 Ω)
Jumper Wires
LED
BREADBOARD
Schmatics
Code
Please copy the following code and upload it to the arduino Board :
#include "SoftwareSerial.h"
SoftwareSerial HM10(2, 3); // RX = 2, TX = 3
char appData;
String inData = "";
void setup()
{
Serial.begin(9600);
Serial.println("HM10 serial started at 9600");
HM10.begin(9600); // set HM10 serial at 9600 baud rate
pinMode(13, OUTPUT); // onboard LED
digitalWrite(13, LOW); // switch OFF LED
}
void loop()
{
HM10.listen(); // listen the HM10 port
while (HM10.available() > 0) { // if HM10 sends something then read
appData = HM10.read();
inData = String(appData); // save the data in string format
Serial.write(appData);
}
if (Serial.available()) { // Read user input if available.
delay(10);
HM10.write(Serial.read());
}
if ( inData == "F") {
Serial.println("LED OFF");
digitalWrite(13, LOW); // switch OFF LED
}
if ( inData == "N") {
Serial.println("LED ON");
digitalWrite(13, HIGH); // switch ON LED
}
}
App Setup
Download the app from Google Play Store. :
App name : Arduino Bluetooth Controller (HM-10 Module)
The Home page of the app will look like below where you can find features like, connect Device, Search Icon, Delete Icon, Device Status, Send Text, Add Template etc. Start with searching the Device either by clicking on Search Icon or by clicking to three dots on the upper right corner and choose connect Device.
All available devices will be shown in the screen. Choose the correct HM-10 Module.
Now the HM-10 will be successfully connected and you will be able to see the status of HM-10 in the Top of Screen.
Now either you can directly send a text or String by writing on the text section and hit arrow to send or you can create a custom template.
To create a custom template to save time. Click on the “+” icon on upper right corner and fill the details. The “Name” is button name, the “Text” field is for texts or string which will be sent to HM-10 and “Description” is just the button description that how the button will function.
Firstly, create a button for turn LED ON and give it a Green Color. The Button will send “N” letter to HM-10 which will turn on the LED connected to Arduino. Similarly create a button for LED OFF and give it a Red Color. . The Button will send “F” letter to HM-10 which will turn off the LED connected to Arduino.
Now you can see the two buttons created just below the Text Field. Now if you want to control LED then just click on the Buttons.
This finishes the setting up android app to control the HM-10 module. Now we will start with the programming Arduino Uno to get the characters from Android App.