Instructables

How to control arduino board using an android phone and a bluetooth module

Picture of How to control arduino board using an android phone and a bluetooth module
In this tutorial you'll learn how to use a bluetooth module and MIT's app inventor to create a wireless serial link between an android phone and an arduino board.

Here is a short video showing an example app I created. I'll describe how to do the wiring, write an arduino sketch that can accept basic commands and send them and how to write the app itself. I asume you're already familiar with some of the basics, you made a few arduino projects and are familiar with the arduino IDE. If you have attempted serial communication with the arduino board everything should be fully comprehensible. If you have any problems or questions feel free to ask them in the comments section.




...and here is an example of receiving the data from the arduino board on the mobile. The temperature sensor connected to the arduino board is a ds18b20 sensor. Just to show how awesome app inventor is I added text to speech functionality - the app says the temperature every 15 seconds. The arduino code and the app is described in more detail in steps 4,5 and 6.
 
Remove these adsRemove these ads by Signing Up

Step 1: Wiring & part list

Picture of Wiring & part list
BTserialModule.JPG
The circuit is as simple as it gets so you probably already have most of them.



You will need:
- arduino board
- bluetooth serial module (I used a btm222 module on a breakout board with an inbuilt regulator )
- an LED
- resistor (100ohm)
- wires
- breadboard


The only problematic part here is the bluetooth module. There are different modules all over the internet so be sure you check the pinout in the datasheet of the one you get as it can differ.


Also notice that there are two general classes of bluetooth modules:
Class 1 has range of about 100 meter (300 feet)
Class 2 has range of about 10meter (30 feet)
In case you're wondering they are entirely compatible and you can only get 100 meter range if both of the devices (ie the mobile and the serial module) are class one. If one of it is class 1 the maximum range is lower.


The bluetooth serial module I got has the following pins from left to right (ground, RX, TX, not connected, VCC). Obviously ground and VCC goes respectively to ground and +5V pin on the arduino board. Since we will be receiveing the data through the module and then in turn sending it to the arduino board we only need to use the TX pin on the module. Run a wire from that pin to the RX pin on the arduino board. The Led is controlled through PIN 2 on the arduino.

1-40 of 154Next »
flagtrax2 days ago
@kerimil Thank you for the response regarding the issue of App inventor classic vs. App inventor 2.I worked around that. But there is however a glitch in the App Inventor compiler regarding the block to "evaluate and ignor results". The reply I got from the forum was that "MIT was aware of the problem and would correct it in the next release." I used a block that was insignificant to the end result as a substitute just to test and it worked. I'm just posting this to alert all newbies like myself to be aware of the issue. Thanks to all who share their knowledge.
archy5877 days ago

Im doin the same project but building the app from the BluetoothChat example in Eclipse. I can get messages back and forth but I dont know how to get the 'delimiter byte' correct. my formatted lines sent from arduino are broken up into different strings in android, so I cant figure out how to parse them properly. I would like to see how your app strings all the incomming data together. does appInventor produce java files you could add to google drive so i could see how its working?

thanks!

kerimil (author)  archy5877 days ago

Well then just write arduino code that sends everything as one string and then your android app divides the strings into substrings that contain data you want. It's actually more of a problem of operation on string than arduino or android problem.

yea, i wanted to see how your app is dividing the strings into substring. Im not very good with java. i did come up with a solution that works only if the arduino outputs a string of an exact length. I guess thats a first step...now just gotta clean it up a bit. anyway....thanks for the post and the reply!

JohnN32 months ago

kerimil, Thank you for sharing your experiences and knowledge. After retiring from a 30 year career in electronics the arduino platform has excited me again. I've build many discrete circuits, but building module to module is a whole new experience. I enjoyed this exercise however I am confused about a couple things (probably due to my inexperience). I've completed the led part and the on/off buttons work great. The voice command for on and off worked but blink didn't. I have just started playing with app inventor and wanted to load your build as you suggested in your narrative, to see what was happening but when I got to the page that was linked to I found a bunch of files and didn't know which one I was to download. If you could help me choose the correct one, you'd make an old man happy, then do I manually rebuild in the app inventor, or is there a way to upload it? Thanks again!

ed.darby JohnN31 month ago

Hi JohnN3

I too had the same problem, I did some digging and it appears that the original app was built in App Inventor Version 1 which isn't compatible with the version 2 that is available now.

If you download the zip file listed in the article "bluetoothforarduino_app" from https://drive.google.com/folderview?id=0B_PfPoEotO... - you can go to - http://appinventor.mit.edu/explore/classic.html and import the zip file into "Classic" app inventor by going to "My Projects" then "More Actions" then "upload source" - The source being the zip file you d/lded above

Hope this helps :)

Ed

kerimil (author)  ed.darby7 days ago

That's right. The thing is that I wrote it before app inventor 2 was released. I need to get some spare time to rewrite it in it as roughly 70% of messages concern this problem. Hopefully will have some time around christmas.

JohnN3 ed.darby1 month ago

Thanks ed, I'll see if I can move ahead with your info thanks for sharing!

Very useful .. faced a little challenge since MIT has come up with AI2 and the code can't be converted to eclipse or Android Studio but was worth the effort.

nero77710 months ago

Thanks , this post was very useful for me :) I managed to send data to the LCD screen by developing an app using your source code thanks alot.

I just have one question , now I'm trying to receive the data from the arduino and display it in a label so for example I want to print hello from this command in arduino Serial.print("Hello"); in a label . But the receive text function in the MIT software only sets it as bits not characters so I'm not able to receive it .

here is my work

I would be gratefull if you can hep me with this

Screenshot 2014-02-18 17.14.36.png

brah!! help me through my project .My arduino UNO is responding to my app invented on mit2. i have used UTF-8 and delimiter byte 0.

kerimil (author)  nero7779 months ago

You have to specify number of bytes to receive in bluetoothclient.receivetext

Put there 0 (zero) and it will work just fine. Just remember to send a message with a delimiter byte.

Appinventor has help dialogs built in. If you keep you mouse pointer on any block or even part of it, a message will pop up saying what it does and how to use it. Try this out with the bluetoothclient.receivetext block and number of bytes ;-) you'll see why

Other apps from play store are working right (rx led is not blinking with this apps(ardudroid)) but my arduino is not responding to my app and rx led still not glowing

Hey i have invented an app on mit2. while using, the app is showing connections and is connecting to hc-05(i'm using) but while sending data over the bluetooth arduino is not responding. This my minor project . I have to submit it by Nov- 22 .plz someone help me.

Hey i have invented an app on mit2. while using, the app is showing connections and is connecting to hc-05(i'm using) but while sending data over the bluetooth arduino is not responding. This my minor project . I have to submit it by Nov- 22 .plz someone help me.

ShubhamM229 days ago

which file is useful from that G-Drive

FrankV229 days ago

Kerimil,

The files you are sharing on Google Drive are all apk files. App inventor 2 only runs aia. I am hoping you can upload the aia file to Google Drive so I can view the program in app inventor.

Thank You

magorwilly1 month ago

Hi.

I love this app. I would like to do some adjustments but the app inventor 2 doesnt allowe me to import zip only aia. Any chance you could send me a link to aia rather than zip. Please

jaydippatel1 month ago

http://www.instructables.com/id/Android-Voice-Tv-Box/

jaydippatel1 month ago

http://www.instructables.com/id/Android-Voice-Tv-Box/

_Hokusai1 month ago

pomohlo

flagtrax1 month ago
Thanks again ed for the steering :) interestingly, I was able to edit the app in the app inventor classic, download it and it worked (WOOT WOOT!)
How ever when I rewrote it using app inventor 2, I could edit it fine, it ran well using the app companion linked to my phone, but when I downloaded it, it crashed at the point where the bluetooth device is selected. It simply returns to the screen it was launched from. I'm wondering if anyone else has had issues like this with app inventor?
It also seems you can only download to your pc and not directly to the phone when using app inventor 2, unless I'm missing something.
CarloDoylo1 month ago

Hi, my name is Carla, from Barcelona. I'm studying Gamification and I need information about an app that let me control the arduino, and if its possible making a "menu" with the same app with six simply buttons.

I need to control something like this with the arduino (6 variables, 1. off the music of the piano (lights still work), off the lights of the piano (sound still work), on the lights (sound does not work), on the sound (light does not work), off all the system and on all the system at the same time.

https://www.youtube.com/watch?v=2lXh2n0aPyw

TimothyB22 months ago

can you control a relay insted of a led?

Yes, but be careful how you drive the relay, keeping in mind the load considerations on the arduino board you are using. There are many opto-isolated relay modules out there fairly inexpensive you can use safely. (I've found many on EBAY). The ones I have sort of work in reverse, with VCC being active and the input (control) lead being active low, meaning your digital write would be low to activate the relay. In this way VCC can be external to your arduino board, and the I/O pin is simply providing a low (Ground path) for the opto-isolator. To me this is the safest way to drive the relay. If you drive it direct you could exceed the current limits of the arduino I/O.

zs21 month ago

i have try this project using hc-06 but i cant get any data..i can connected to bluetooth but no data has been send to my android..and here my android block..can anybody here help me??

1.png2.png
jkurarin4 months ago

can you post the App Inventor blocks for the Text-to-Speech function? pls pls pls :)

Hi jkurarin

I hope this helps.

Blocks.jpg

Hi I'm trying to do something similar but in my project I have to monitor 4 temperature sensors and turn ON/OFF 4 LEDs. How could I do this? Would it overload the serial communication between the arduino and the android? Please help me I just can't find an answer :(

redrocket111 month ago

First off all I would like to say that this is a great instructable, congratulations. I would like to ask you if it is possible to bypass the bluetooth module and connect the android phone directly via usb with the arduino. What I would like to do is to use the android phone as a shield for the arduino in order to use gps, wifi, and 3G sensors of my phone.I would like to be able to connect arduino to the internet throught the android phones wifi or 3g and control the arduino through internet

Bhanu Kishan made it!2 months ago

I used a BC 417 Bluetooth module. It worked when the baudrate is set 9600. Also leave the Rx (pin 0) unconnected while uploading the sketch to Arduino UNO. Thanks for this DIY. Good learning exercise.

DSC_7076.jpgDSC_7078.jpg
assyty3 months ago

Hello ... i've tried the receiving data,, at the first that file .apk can connect with bluetooth module ,, but why cant the data appeared yet?
i spent days to solved this problem :(

bbogdanmircea3 months ago

Do you think that I can use your setup for RX TX communication for a tank robot ?

I want to move the tank from my phone, by programming some buttons for left right on off for each track.

But I also want the tank to send some data to phone, like for example what is the value of pwm used for the motors, maybe also link a sonar sensor in order to check for obstacles.

Do you think it is possible to extend the setup you used for Bi-Directional communication, or do I need to use another application for Android for making custom buttons ?

bbogdanmircea3 months ago

Do you think that I can use your setup for RX TX communication for a tank robot ?

I want to move the tank from my phone, by programming some buttons for left right on off for each track.

But I also want the tank to send some data to phone, like for example what is the value of pwm used for the motors, maybe also link a sonar sensor in order to check for obstacles.

Do you think it is possible to extend the setup you used for Bi-Directional communication, or do I need to use another application for Android for making custom buttons ?

what if I'm using Bluetooth shield? How do I send characters from android app to arduino? I already know how to receive characters from app to arduino , but not how to send them.

agangwani4 months ago

can i use

HC05 Bluetooth Module Breakout Board

also please can someone list all the Bluetooth Module (like 222) which i can use? i couldn't get btm222 here at my place

Thanks :-)

This is great - An App Inventor 2 or Eclipse version would be good, too!

ovi08195 months ago

Hi! First sorry for my english.

Well i am using HC-07 BT module, i did all the steps, link the mobile with the board but when i press "Led On" nothing happens, but when i press "Led on" or "led off" el TX on the board, blinks.
Btw i changed the led

amyymoo5 months ago

well i have a question i'm working on a similar project but i need to control a temperature sensor using the same controlling app for the arduino , if you know anything about this topic , please give me an advice :)

drmpf6 months ago

If you don't want to do any Android programming, check out pfoDesigner http://www.forward.com.au/pfod/pfodDesigner/index....

This free Android app lets you design your own Android menus and then generate the Arduino sketch that serves the menu, via pfodApp, and handles the users button presses. You only need to add the action code for each button command.

Here is an example menu designed by pfodDesigner. You can change the number of buttons, the text, the colours, the font size and style.

No Android programming required.

finalDesignSmall.png
1-40 of 154Next »