Menu Close

Controlling LED with BLE Module HM 10

This tutorial explains how to control LED with Android app using BLE Module HM10. 

1. Introduction:

In this tutorial we explains, how to send and receive data from Arduino to the Android app without using Serial monitor.

For this, we have taken a simple example of LED. We will send command to get LED on and off.

1.1 Default Setting of BT Module:

The default setting of HM10 are:

Name- MLT-BT05

Password- 123456789

Baud Rate- 9600

All the modules have the same baud rate by default. Make sure to set Baud Rate to 9600 in your code. If you want to change the baud rate in your code, then you also need to change the baud rate of device by using AT Commands.

2. Hardware required

S.No.ItemQuantity
1.Arduino 1
2.Breadboard 1
3.BT Module HM10 1
4.LED 1
5.Resistor 1K 1
6.Male to Female Jumper Wires 4
7Male to Male Jumper Wires 2

 3. Building Circuit

4. Programming:

Once the circuit part is done, Arduino is needed to be programmed.

You may download this code (Arduino Sketch) from here.

//Robo India tutorial on Controlling LED with Android
//Hardware Required: BLE HM10 & Arduino
//https://www.roboindia.com/tutorials/

byte LED = 2;                // device to control
char BT_input=' ';           // to store input character received via BT.

void setup() 
{
    Serial.begin(9600);     // default baud rate of module
    pinMode(LED, OUTPUT);   // device to control
    while (!Serial)
    {
      
    }
 
}
 
void loop()
{
 if (Serial.available())
 {
  BT_input = Serial.read();
  if ( BT_input== 48)       //ascii code for 0 is dec 48
   {
    digitalWrite(LED, LOW);
    Serial.println(BT_input);
    Serial.println("LED is OFF"); 
   }
  if ( BT_input== 49) 
   { 
   digitalWrite(LED, HIGH); 
   Serial.println(BT_input);
   Serial.println("LED is ON");  //ascii code for 1 is dec 49 
   }
 }
}

Before uploading the code, remove the RX and TX wires from Arduino’s TX and RX pins. After uploading the code, connect them again and plug out the USB cable and supply external power using adaptor.

5. Mobile app

You may download the Android control App on Playstore from here.

Connecting the Android device to the HM10 creates a serial communication channel very similar to the serial monitor in the Arduino IDE. This means we need a Bluetooth version of the serial monitor.

1. Download this Application.

2. Pair your phone with HM10. for doing this go to Settings->Bluetooth->Scan device->select MLT-BT05 and pair it. Pass code to pair is ‘123456789’.

3. Now, open the app and connect the HM10 module.

After Connection, the blinking LED on the MODULE will remain ON.

6. Output:

Press on the button “LED ON” to turn on the connected LED.

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com

Leave a Reply