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 119Next »
ovi081921 days 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

amyymoo24 days 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 :)

drmpf1 month 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
ruganattramn2 months ago

And, is it possible to add an alarm code? For example when temperature reaches at 39 degree the cell phone will give an alert

ruganattramn2 months ago

Hi, I can't open your videos. Could you please give me another link for videos? ( "Unable to resolve the server's DNS address" writing on the video)

adster6662 months ago

Hi I got it working perfectly when Arduino is hooked up via USB lead to the computer but when I connect the 9V battery pack it doesnt seem to power the module. Why is that and how can I untether my arduino/HC-06 combo from my computer, please?

Mr Arduino2 months ago

Can you use the above steps to turn the voltage current from the power source off?

mikeyaworski3 months ago

Can you please send me links to where I can order your btm222 module and ds18b20 sensor?

alacosta4 months ago

hi just to say I have found this project very useful and say thank you. My problem I would like to change / edit the source code for the temperature project. However I given several possibilities of files to down load / import, what ever I try I get error on

MIT's app inventor not an .aia file. please advise how I get this file to edit

Thank you

J

hi

you are using the AI2 and this project was built under AI Classic....

so...either you switch back to AI Classic ..or ..re-build the code under AI2

kodagames3 months ago

Hello,

Im new to app inventor. Can you share the .aia file? For turning on and off the LED I tried to figure out how to download the files from the link you provided but dont know what to do with the .blk or .scm files.

Also Im extremely grateful that you have provided this tutorial and greatly appreciate you taking the time to put this together! Thank You!

Nilanj3 months ago

thanks for this

its not working on my HC-6

ted is not turning on or off.

ivver3 months ago

Thank you! And just to say, for controlling some motor or car, you have one great finished application on Market (google play): Bluetooth RC Controller

titi314 months ago

hi Kerimil, i already download your app about bluetooth for arduino..
i want to ask about the bluetooth from the android app, what kind of bluetooth can connect to the android? just bluetooth from arduino or other bluetooth from handphone and PC? thankyuu Kerimil..

OlawaleJegede4 months ago

Thank you Kerimil, the arduino code and app works perfectly for me. I am using the DHT22 sensor connected to digital pin 2. Thank you for sharing your work.

nero7775 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
kerimil (author)  nero7774 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

OlawaleJegede4 months ago

Hi Kerimil. I am using the HC-06 serial bluetooth module. I was able to connect the app to the module and I succesfully uploaded the arduino code. I connected the ledPin to pin 7 on the arduino uno, yet the LED did no come on. Please where could the problem be? And if it has to do with the bluetooth module where can I purchase the bluetooth module you used online? Thank you.

Hi Kerimil, I got the LED working now. I upgraded the android from the 4.3.0 it was to 4.4.2 and the app works perfectly turning the LED ON and OFF, The voice commands also works well. Thank you.

Nirav0085 months ago

can I use HC-05 Bluetooth module for this project.

calou15 months ago

j'ai un problème, j'utilise un récepteur bt avec une vitesse de 9600 et la led ne s'allume pas, faut-il du 115200?

takkan5 months ago

hello, I am new to the Arduino circle and picking up things as I go along. recently I combined a sketch of the push button and the push button stop watch to make me a counter (sensor-relay switch counter) and a push button stop watch. All I want to do now is have a customized screen to display the results of this. so far I have tried PLX-DAQ and Gobetweno to do the same(both lacking the refinement and the flexibility). My question to you is, is it possible to have an app which is efficient enough to not only display this information in a legible format but also is able to import information from my network neighborhood to ingrate into the app.

I will be highly obliged if you could guide me in the best direction as I have no more resources left to refer to neither do I have any more ideas streaming in my mind

jblakes346 months ago

Can I use this Bluetooth connection to stream video from a device similar to the Parrot A.R. Drone, or would I need a Wi-Fi or ethernet connection for that? Any suggestions on how to do that? Thanks for the help.

jb

kerimil (author)  jblakes346 months ago

If I were you I'd use wifi to get images from the device. If the device acts as an IP cam and supports jpg mode it can be done. Check this - it might be helpful ->

https://groups.google.com/forum/embed/?parenturl=http://appinventor.mit.edu/explore/forums.html&showsearch=true&fragments=true#!topic/appinventor/Z30eETu0B1s

bjamose9 months ago
i wont to do this project using the wifi
the change is just in the bluetooth module or i need other
things
choconog bjamose6 months ago

use ethernet shield

bjamose bjamose9 months ago
please help me
kerimil (author)  bjamose9 months ago
Obviously you need other things. check my video 'arduino temperature monitor' - you could combine that method and an example arduino sketch 'wifidatastreamDownload' that comes with a xively library. Xively was formerly known as Cosm but it's essentially the same - you'll have to change some URLs in the example app.
sam_12346 months ago

Dear Kerimil

First of all I would like to thank-you for explaining in such easy words that a lay-man with little knowledge of networking and Programming know how might be able to grasp this project easily .I am with a technical background and a hobbyist I want to kick start my Arduino projects this week the simpler ones first and then move to this one which is my main goal ,so friend in this project I wish to ask if it was possible to connect a Relay module which is readily available on ebay these days instead of a LED as my Aim is to control 3-4 home appliances by virtue of this project.Hope to hear from you soon.

Regards & best wishes

Sachin

kerimil (author)  sam_12346 months ago

sure not a problem - just use a relay module istead of an LED

sam_1234 kerimil6 months ago

Thankyou Kerimil

I am all set but before taking a big step I will be doing the miniatures like interfacing LCD etc :D then learn a bit of C programming did that 7 years back now need to get into the groove and final decent would be this cool project Thanykou for the speedy reply I would be looking forward to your guidance if stuck which I am sure I will as always :D Cheers

villadsen110 months ago
So im trying to use your program just to turn on and off the LED on the arduino mega 2560.. The one connected to pin 13. So i changed the ledPin to 13 but then i get this error: avrdude: stk500v2_ReceiveMessage(): timeout
what is going on, can you help me?
Tnx very much
i started my first arudino project because i saw your app.
I had the same problem.....
Here is a link to the fix, After I unplugged the RX pin the sketch uploaded flawlessly... then I plugged it back in and it works great.

http://www.parkansky.com/arduino-error.htm
kerimil (author)  glennballen6 months ago

When there's anything attached to TX/RX pins you can't use usb to communicate with the board - disconnect the module, upload code and then wire it again

sankha877 months ago
I,m using HC 06 bluetooth module.baud rate selected as 9600.
app installed in sonyericsson xperia ray. led on and off doesnt work. only blutooth pair and connected together.

after connecting Bluetooth, when I press the voice commands button in app it gives error.
"connection problem"
yellow color circle with triangle sign mark.
I would be much grateful if you help me.
pls explain the problem
kerimil (author)  sankha877 months ago
Hc06 modules can either be slave or master and you can't change it. Normally they are sold as slave devices. Since the app (phone) is set as the client it won't work.
kerimil (author)  kerimil7 months ago
client meaning slave
sankha877 months ago
after connecting Bluetooth, when I press the voice commands button in app it gives error.
"connection problem"
yellow color circle with triangle sign mark.
I would be much grateful if you help me.
pls explain the problem
kosidinma7 months ago
Hi, please how can i write a code block that receives more than one value from the arduino and display both on the phone; for example, if i want to receive temperature and battery voltage and display both on the phone at the same time? thank you.
kerimil (author)  kosidinma7 months ago
simple
arduino code:
Serial.print(xValue);
Serial.print(",");
Serial.println(yValue);

Create an app that looks for a coma "," and splits the string received from arduino into two - the first part is value x the other value y. Everything you need is in text blocks - when you move the cursor over blocks you'll see what they do
1-40 of 119Next »