Controlling LED using Bluetooth Module – Arduino

Ever thought of controlling any of your electronic devices with your smart phone? How about a robot or any other device? Wouldn’t it be cool to control them with your smartphone? Here is a simple tutorial for interfacing an Android Smartphone with Arduino via Bluetooth!

Required Materials

arduino bluetooth

Hardware

  1. Bluetooth Module HC 05/06
  2. Arduino& Battery (with cable)
  3. LED
  4. 220 OHM Resistor
  5. Android device

Software

  1. Arduino IDE
  2. Android Studio.

Android studio isn’t really required here since I will provide you with the android application that I made. You can install the given .apk file to use the application. 🙂

How Does it Work?

There are three main parts to this project. An Android smartphone, a Bluetooth transceiver, and an Arduino.

arduino bluetooth

HC 05/06 works on serial communication. The Android app is designed to send serial data to the Arduino Bluetooth module when a button is pressed on the app. The Arduino Bluetooth module at other end receives the data and sends it to the Arduino through the TX pin of the Bluetooth module(connected to RX pin of Arduino). The code uploaded to the Arduino checks the received data and compares it. If the received data is 1, the LED turns ON. The LED turns OFF when the received data is 0. You can open the serial monitor and watch the received data while connecting.

Connecting the Arduino Bluetooth hardware

arduino bluetooth

This circuit is simple and small. There are only four connections to be made between the Arduino and Bluetooth module!!

Arduino Pins Bluetooth Pins

RX (Pin 0) ———> TX

TX (Pin 1) ———> RX

5V ———> VCC

GND ———> GND

Connect a LED positive to pin 13 of the Arduino through a resistance (valued between 220Ω – 1KΩ). Connect its negative to GND, and you’re done with the circuit!

 

arduino bluetooth

Note: Don’t Connect RX to RX and TX to TX on the Bluetooth and Arduino. You will receive no data. Here TX means Transmit and RX means Receive.

Uploading the Sketch to Arduino


char data = 0; //Variable for storing received data
void setup()
{
Serial.begin(9600); //Sets the data rate in bits per second (baud) for serial data transmission
pinMode(13, OUTPUT); //Sets digital pin 13 as output pin
}
void loop()
{
if(Serial.available() > 0) // Send data only when you receive data:
{
data = Serial.read(); //Read the incoming data and store it into variable data
Serial.print(data); //Print Value inside data in Serial monitor
Serial.print("\n"); //New line
if(data == '1') //Checks whether value of data is equal to 1
digitalWrite(13, HIGH); //If value is 1 then LED turns ON
else if(data == '0') //Checks whether value of data is equal to 0
digitalWrite(13, LOW); //If value is 0 then LED turns OFF
}

}

Upload the given sketch to Arduino using the Arduino IDE software, you can also get it from Github.

Installing the Android Application

arduino bluetooth

In this tutorial, I will not cover Android app development. You can download the android application from here and the source code of the entire project.

  • Download the Application from Amazon App Store or Github
  • Pair your device with the HC 05/06 Bluetooth module:
  • 1. Turn ON the HC 05/06 Bluetooth module by powering the Arduino.
  • 2. Scan your smartphone for available devices.
  • 3. Pair your smartphone to the HC 05/06 by entering default password 1234 OR 0000.
  • Install the LED application on your Android device.
  • Open the Application

arduino bluetooth

  • Press paired devices
  • Select your Bluetooth module from the List (HC-05/06)

  • After connecting successfully, press the ON button to turn the LED on and the OFF button to turn the LED off.
  • Disconnect the button to disconnect Bluetooth module.