Using Android to control Arduino via Bluetooth (HC-05/06 Module)

Image

Recently, I’ve noticed many projects incorporating Android-Arduino communication. One of the easiest (and cheapest) ways of achieving this is to use a HC-05/06 Bluetooth module. You can pick one up from amazon.ca for ~$15.

For this project, i used a Galaxy S3 to independently control 4 LED’s. You will need to download the app ‘Arduino Bluetooth Terminal’, which is available for free on the Play Store.

To hookup the bluetooth module, connect the 5v and GND to their corresponding arduino headers of the same name. For the TX/RX pins, use digital pins 10(TX) and 11(RX)

Image

You’re indicator led on the HC-05/06 should now start blinking.

To pair your android to the module, use the passcode “1234”. Try “0000” if that does not work. Once paired, the indicator led should now be constant ON.

To set-up the simple LED cct, please refer to the the picture below. Note the GREEN, BLUE, RED, and WHITE led’s are powered by digital pins 4, 5, 6, and 7, respectively.

Image

Almost finished!

Upload this sketch to your board:

#include <SoftwareSerial.h>;

SoftwareSerial bluetooth(10, 11); // RX, TX
int ledGRN = 4;
int ledBLU = 5;
int ledRED = 6;
int ledWHI = 7;
int BluetoothData;

void setup()
{
 bluetooth.begin(9600);
 pinMode(ledGRN,OUTPUT);
 pinMode(ledBLU,OUTPUT);
 pinMode(ledRED,OUTPUT);
 pinMode(ledWHI,OUTPUT);
}

void loop()
{
 if (bluetooth.available())
 {
 BluetoothData=bluetooth.read();

 if(BluetoothData=='1')
 {
 digitalWrite(ledGRN,1);
 bluetooth.println("GREEN ON");
 }

 if(BluetoothData=='2')
 {
 digitalWrite(ledBLU,1);
 bluetooth.println("BLUE ON");
 }

 if(BluetoothData=='3')
 {
 digitalWrite(ledRED,1);
 bluetooth.println("RED ON");
 }

 if(BluetoothData=='4')
 {
 digitalWrite(ledWHI,1);
 bluetooth.println("WHITE ON");
 }

 if (BluetoothData=='0')
 {
 digitalWrite(ledGRN,0);
 digitalWrite(ledBLU,0);
 digitalWrite(ledRED,0);
 digitalWrite(ledWHI,0);
 bluetooth.println("LED'S OFF");
 }

 }
 delay(100);
}

Now you should be able to turn on the 4 LED’S by entering the numbers ‘1 2 3 4’, and turn them off by pressing ‘0’.

Image

Think of all the possibilities that are now open to you! For example, you could control any 120V cct. by simply adding a relay, instead of powering a led. Remember, creativity is limitless!

Leave your questions & comments below.

22 comments on “Using Android to control Arduino via Bluetooth (HC-05/06 Module)

  1. Pingback: DIY Home Automation with Android | King's Tech Garage

  2. Hi there, This is a nice project..
    may i have the code for the android side so that i can tweak with that…
    Thank u ….

    Like

  3. Hello Dolphy, I like your post, but I am confused I just bought a generic BT dongle based on HC-05, mine is quite similar to the one on your pics, even it uses only 4 pins, but I could not establish communication with the Arduino, the dongle just don’t stop blinking, I am sending the AT commands and nothing, I heard that some of this products might not work at all, have you faced something similar ? If so how did you fixed ?

    Like

  4. Pingback: Manual control of an Arduino based robot using Android | King's Tech Garage

  5. Pingback: DIY Home Automation with Android | King's Tech Garage

Leave a reply to flavio Cancel reply