Introduction: Build Android Bluetooth App for Arduino

Picture of Build Android Bluetooth App for Arduino

Hi, today i am going to make a android app for arduino Bluetooth module HC-06.Through this app you can control a light or led form your android phone.Lets do it..........

Step 1: Go to Android Editor

Picture of Go to Android Editor

Go to MIT App Inventor

Link: http://appinventor.mit.edu/explore/

In the menu bar click on “Create App!”

Login using your gmail account.

If you don't have gmail account or Google Account.Then create an account.

Step 2: Start Creating Android App

Picture of Start Creating Android App

In the menu bar go to “Projects”.Click on it.You will see a drop down menu.In that drop down menu click on the “Start new project”.Then a page will came and want a project name.Give a project name.I give the project name "Bluetooth_Remot".Remember in this online editor you are not allow to give space in the name.So, i use this "_" .

Step 3: Designer Page(Step-1)

Picture of Designer Page(Step-1)

Now, you are in design page.In this page you will drag and draw the outer look of the app.

Step 4: Designer Page(Step-2)

Picture of Designer Page(Step-2)

From "Palette" in "User Interface" bar drag the "ListPicker" and drop it into the screen.

Step 5: Designer Page(Step-3)

Picture of Designer Page(Step-3)

In the "Properties" bar change the name of this "ListPicker1" to "Connect".

Step 6: Designer Page(Step-4)

Picture of Designer Page(Step-4)

Like before from "Palette" in "User Interface" bar drag two "Button" and drop it into the screen.And from "Properties" bar change the name of that two Button "Text for Button1" and "Text for Button2" into "ON" and "OFF".

Step 7: Designer Page(Step-5)

Picture of Designer Page(Step-5)

Now, from "Palette" in "Connectivity" bar "BluetoothClient" and drop it into the screen.

Step 8: Designer Page(Step-6)

Picture of Designer Page(Step-6)

From "Palette" in "Sensors" bar "Clock" and drop it into the screen.

Step 9: Shift Designer Page to Blocks

Picture of Shift Designer Page to Blocks

On the top click on the "Blocks" and you will get a new page like shown in the picture.

Step 10: Blocks(Step-1)

Picture of Blocks(Step-1)

From "Blocks" to "Screen1" to "ListPicker1" click it and you will get boxes like the picture.Now Drag "When ListPicker1 .BeforePicking do" and drop into "Viewer".Again from that list drag "set ListPicker1 . Elements to" and drop it into "When ListPicker1 .BeforePicking do".That will looks like the picture.

Step 11: Blocks(Step-2)

Picture of Blocks(Step-2)

From "Blocks" to "Screen1" to "BluetoothClient1" click it and you will get boxes like the picture.Drag "BluetoothClient1 . AddressesAndNames" into "set ListPicker1 . Elements to".

Step 12: Blocks(Step-3)

Picture of Blocks(Step-3)

Like Blocks(Step-1) and Blocks(Step-2) drag and drop like picture.

Step 13: Blocks(Step-4)

Picture of Blocks(Step-4)

Like before from "Blocks" to "Screen1" to "Button1" drag "when Button1 . Click do" into "Viewer" .

Step 14: Blocks(Step-5)

Picture of Blocks(Step-5)

From "Blocks" to "Screen1" to "BluetoothClient1" drag "call BluetoothClient1 . SendText text " into "Viewer" .

Step 15: Blocks(Step-6)

Picture of Blocks(Step-6)

From "Blocks" to "Screen1" to "Text" drag " " " " into "Viewer".

Step 16: Blocks(Step-7)

Picture of Blocks(Step-7)

Now in the text box in " " write "ON".

Step 17: Blocks(Step-8)

Picture of Blocks(Step-8)

Flow the same steps for "Button2" shown in pictures.Only change is write "OFF" in the box.

Step 18: Download Your App

Picture of Download Your App

Congratulation !!!!!!!!!!!!!!!! You just build your Bluetooth app.Now to download it go to top click on "Build" and then click on "App(save .apk to my computer)".

Step 19: Arduino Program for This App

Picture of Arduino Program for This App

Now you have your remote to control arduino led light in pin 13.By using this remote you can ON or OFF any thing that you want.Here the simple code for arduino to control pin 13 led.

Code:

String a;

int led = 13;// add the pin number that you want to control.

void setup()

{

Serial.begin(9600);

pinMode(led,OUTPUT);

}

void loop() {

while(Serial.available()){

a=Serial.read();

Serial.println(a);

if(a=="ON")

{

digitalWrite(led,HIGH);

}

if(a=="OFF")

{

digitalWrite(led,LOW);

}

}

}

Comments

DeepakC63 (author)2017-10-14

thanks...

YodiS made it! (author)2016-04-29

there's some error in the arduino code, "b is not declared in this scope" and the Serial.read not read the string. After 1 hour, I found the solution, it works! here's my code

String b;

int led = 13;

void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

pinMode(led,OUTPUT);

}

void loop() {

// put your main code here, to run repeatedly:

while(Serial.available()){

b=Serial.readString();

Serial.println(b);

if(b=="ON") {

digitalWrite(led,HIGH);

}

if(b=="OFF")

{

digitalWrite(led,LOW);

}

}

}

DeepakC63 (author)YodiS2017-10-14

thanks...

YodiS (author)YodiS2016-04-29

btw thanks for the clear tutorial Abdullah, good luck.

NicoleP128 (author)2017-09-07

Hello,

Do you know if it is possible to use App inventor to control two seperate bluetooth devices? For example I would like to turn one light on with one button, and another light on (with another bluetooth receiver) with a separate button. Thanks!

tytower (author)2017-02-05

This is the first clear instructable I have been able to follow Abdullah so thanks

JoshuaH171 (author)2017-07-06

i have spent months on ionic trying to do this. only to haveing done it in two minutes. thankyou so much youve help push my project along thankyou.

it's my pleasure !!!!!

PhongP10 (author)2016-08-30

I didn't know we can have a string in our sketch, and also suprised to see we can make a comparision between the strings.

Can some one please explain, because if i remember correctly we can't do that in C programming, or is it the differences between coding in arduino IDE vs with C IDE.

Thank you.

tytower (author)PhongP102017-02-05

Investigate the " String" class in arduino or C

PhongP10 (author)tytower2017-06-16

Although it's almost a year since my question. I've learned a lot in this year about electronics and programming ... enough to answer this question myself now XD

Anyway, thank you for your reply! Appreciated

ArchibaldD (author)2017-03-18

Why do we need a clock?

tytower (author)2017-02-05

I was able to get a result by sending numbers 0 and 1

The arduino code got 0 or 0/0/128 and I don't know why

See the screenshot for the adjusted arduino code that worked

tytower (author)2017-02-05

I notice Listpicker1.selection does not shhow on some of the pics . I found that confusing .

I am using the latest app inventor and android 5.1 and the serial output is

ON button sends out " 0 then 128 "

OFF button sends out "0"

I can't get it to send the text "ON" and "OFF"

For those finding it difficult to follow here is the ".aia" file you can import into app inventor to start you off . If you fix the above problem please post back.

_abdullahsaqib_ (author)2016-12-28

how to make an app like this for flying a drone?

vandenbrande (author)2015-11-08

Thanks will add to favorites

diy_bloke (author)2015-12-29

instructive. I was always under the impression that Serial.Read would just read a byte, not a string. So I learned evenmorethan i thought :-)

About This Instructable

12,041views

52favorites

License:

More by Abdullah_Al_Mamun_EEE_EWU_Bangladesh:Serial communication process in Arduino Create Internal Interrupt In ArduinoHow to Simulate Arduino in Proteus
Add instructable to: