Arduino Bluetooth LED Control from Android App

Author : Dinesh Kumar Wickramasinghe

Introduction and Images

Hello Friends, Today we are going to build an interesting project. What we are going to do is enable Bluetooth to your arduino. So I will explain you how to use a Bluetooth module with Arduino and control an LED with your Android mobile. Here are some images of the completed project.

Bluetooth Modules
Arduino Bluetooth Modules HC-05 HC-06

If you search for Bluetooth modules for arduino, You will find there are basically two types are available. Those are HC-05 and HC-06. Both the HC-05 and HC-06 Bluetooth modules are easy to use, low price Serial Port Protocol modules. These modules communicate with Arduino via Serial communication. The HC-05 module support both Master and Slave modes (HC-06 supports only slave mode). This module is fully qualified Bluetooth V2.0+EDR (Enhanced Data Rate) 3Mbps Modulation with complete 2.4GHz radio transceiver and baseband. Please note that HC-06 module supports only the slave mode. Both HC-05 and HC-06 modules are physically looks same as on above picture. So when you purchase this module, better to buy HC-05 type. You can follow this tutorial with both HC-06 and HC-05 modules.


Schematic
Arduino Bluetooth Schematic

Connecting your bluetooth module to arduino is very easy. Just connect the VCC and GND pins to Arduino +3.3V and Gnd (This module supports voltage range from 3.6V to 6V. It is safe to use 3.3V) Then connect Rx pin of the Bluetooth module to Arduino Tx and Tx of the Bluetooth module to Arduino Rx. That's all. We will also connect an LED to control via your Android mobile. Please refer the above schematic for more information.

Android App

We will download and install a simple android application from App store for this tutorial. (I will write another tutorial later to show you how to build your own android app for bluetooth applications)

From android app store download and install the below application.

Bluetooth Terminal App (Android)

Arduino Code

The source code is very simple. In the beginning of this article, I mentioned that the Bluetooth module communicates with Arduino via Serial communication. So, what this code does is, in the main loop listening to the serial data coming from the Bluetooth module and read the text. If the text is “ON”, then turn on the LED, if the text is “OFF” then turn on the LED.

String inputString;

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
}

void loop() {
  while(Serial.available()){
    delay(50);
    char c=Serial.read();
    inputString+=c;
  }
  if(inputString.length()>0){
    Serial.println(inputString);
    if (inputString =="ON"){
      digitalWrite(13, HIGH);
    }
    else if (inputString =="OFF"){
      digitalWrite(13, LOW);
    }
    inputString="";
  }
  delay(100);
}
                    

Upload this sketch to your Arduino.

Make the Connection to your Android Mobile

Once you done the device setup (Connect the Bluetooth module to Arduino. Connect the LED, Upload the code and power up the device setup), turn on Bluetooth on your android smartphone. Then open the terminal app (You previously installed).

Note : I took these screenshots using a HC-06 module. Don’t worry, below steps are same for both HC-05 and HC-06 modules.

The application will ask for permissions to control the Bluetooth functions of your phone. Press Yes.

Arduino Bluetooth Android

From App menu, select "Connect a device - Secure"

Arduino Bluetooth Android

The app will show a list of bluetooth devices available. Select the HC-05. (I used HC-06))



Arduino Bluetooth Android

The device will normally ask the password. In most cases it is 1234

Arduino Bluetooth Android

Now your device is connected and ready to test.

Testing the App

Type "ON" and click send. See that the LED turns on. Also type "OFF" and send. The LED will turn off. (Remeber to send the commands in all capital format)

Arduino Bluetooth Android

Yes, you are done with Arduino and Bluetooth.

Conclusion

Hope you enjoyed this simple tutorial and how to control arduino with Bluetooth. Now you can connect more devices and control from your Smartphone. In the next tutorial I will show you how to write your own Android application to control Arduino. If you faced any issues of problems while implementing this project, please mention them on the comments section. I will try my best to answer. Bye for now.


Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : MD.mustkim
Added Date :5/31/2019 3:37:49 PM
Pls sent slide base tutorial classea

 

Similar Projects

Go Top