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.

Step 1: Wiring & part list

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.

Step 2: Arduino code

Below is an arduino code I used. Feel free to modify it.

The important aspect here is the baud rate - make sure it matches the baud rate of your module - check the datasheet or use AT commands to do it.

const int ledPin = 2;      // the pin that the LED is attached to
  byte serialA;
void setup()
  // initialize the serial communication:
  Serial.begin(19200); //baud rate - make sure it matches that of the module you got:
  // initialize the ledPin as an output:
  pinMode(ledPin, OUTPUT);

void loop() {

if (Serial.available() > 0) {serialA = Serial.read();Serial.println(serialA);}

      switch (serialA) {
    case 1:
      digitalWrite(ledPin, HIGH);
    case 2:
      digitalWrite(ledPin, LOW);
    case 3:digitalWrite(ledPin, HIGH);
      digitalWrite(ledPin, LOW);



Step 3: The app itself & App inventor

If all you want is to get the app and see it running then download the app then upload it to your phone.
Download at -> https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing

Your phone has to be set to allow apps from outside the android market/google play to be able to download them - so check the settings on your mobile.

Now if you want to modify the app go to >>
to find out how to prepare your computer and install App inventor software. Once you have it running I suggest you do at least one or two of their basic tutorials.

Below is the source of the app that I used. You can upload it to the app inventor and then upload to your phone or modify it.

Step 4: Receiving data from arduino

This step presents an example on how to receive data from the arduino board.

I decided to make something useful so I chose a ds18b20 temperature sensor. The arduino board communicates with the sensor using 1 wire interface, calculates the temperature with the help of OneWire library for arduino and sends the readings through the bluetooth module every 500 ms.

The app checks every 500 ms if there is any data available from the serial port. If data is present it is read and displayed on the screen. Additionally, there is an option to activate text to speech function and make the app say the temperature readings every 15 seconds.

Step 5: Remote sensor - arduino code

The arduino code
Mind you that you need a OneWire library - you can find a link to it here:

arduino code >>>>>>>

#include <OneWire.h>
int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

void setup()
  // initialize the serial communication:
  // initialize the ledPin as an output:


void loop() {

   float temperature = getTemp();
Serial.println(temperature); delay (500);


float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( !ds.search(addr)) {
//no more sensors on chain, reset search
return -100;

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;

ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) {
data[i] = ds.read();


byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB);
float TemperatureSum = tempRead / 16;

return TemperatureSum;}

Step 6: Receiving data - the application side

Here you can find links to the app that receives temperature reading. There is also a source code that can be uploaded into MIT's app inventor (when you're in 'my projects' click the button 'More Actions' - you have an option 'Upload Source')

feel free to modify it ;-)

The application >>

The source file >>

I'll try to add something more descriptive soon, but here are some tips you might find useful if you're trying to create your own app: Make sure you understand the terms 'delimiter byte', know how to set it from MIT's app inventor and that it is a byte so be careful what data types you use. Also it seems that there is no serial timeout function implemented in the app inventor so sending data more often than receiving it can cause the app to crash (probably because there isn't anything to flush the buffer)
Can we control four motors via motor shield with this module? If not then please suggest a way. <br>
<p>the link you provided to convert to aia file doesn't work do you have another one?</p>
<p>Hey man thanks for the awesome tutorial and package of files. Really helped me figure the way through the MIT app inventor and bluetooth interface around it !!!!</p>
<p>Hello,</p><p>I am trying to connect my smartphone with a genuino 101 board with bluetooth but I can't. Two devices are in pair and I put this code:</p><p>#include &lt;Servo.h&gt;<br><br>#include &lt;CurieBLE.h&gt;<br><br>#include&lt;BLEPeripheral.h&gt;<br>#include&lt;BLEService.h&gt;<br><br><br>BLEPeripheral blePeripheral;<br><br>Servo servos[13];<br><br><br><br>// creaci&oacute; del objecte servo per controlar els servos<br><br>void waitForInput(){<br><br><br>while(Serial.available()==0){<br> delay(500);<br>}<br><br><br> while(Serial.available()&gt;0){<br> char incomingChar= Serial.read();<br> manageChar (incomingChar);<br> }<br>}<br> void manageChar (char c){<br><br> switch(c){<br><br> ...<br><br> }<br>}<br><br><br>void setup() {<br> servos[3].attach(3); <br> servos[4].attach(4); <br> Serial.begin(19200);<br><br> blePeripheral.setLocalName (&quot;LEDCB&quot;);<br><br> blePeripheral.begin();<br><br>}<br><br>void loop() {<br> waitForInput(); <br><br>}<br><br><br>Could anyone help me?</p><p><br>Thaks a lot<br><br>Daniel</p><p>I am tryiy</p>
<p>i am here using MLX90614 instead of your temperature detector.</p><p>will this code will work fine for me??</p>
<p>Hi,</p><p>I followed the guidance step by step several times. The end result is always the same-- android is paired with BT, but when I want to connect the app, I always get error 507. I am using BT hm-10 and braud 9600</p><p>I laso tried with dc motors--the same result.</p><p>I also made my own app at appinventor--still error 507.</p><p>Could anyone guide me, how I could find my mistake?</p><p>I foll</p>
<p>hi the baud rate u are using might ne the problem the bluetooth module uses a different baud rate . i am not sure but i think its 38400. for more info i suggest you look at the data sheets</p>
<p>Hey RasmusHD,</p><p>HM-10 is bluetooth 4.0 module. It is not compatible with APP Inventor which works only with bluetooth 2.0.</p><p>Check out HC-06 or HC-06 they should work just fine.</p>
<p>I think you meant HC-05 or HC-06, non?</p><p>Be aware that the HC-06 is a slave unit and only receives BT. The HC-05 talks as well as listens and is best for most project methinks. Even if this project only listens, your next project may require the added direction. Street pricing for the units is within a couple of USD of each other. There are Arduino coding differences between the units, so I would opt to learn using the more flexible part.</p><p>Also, keep in mind that MIT's App Designer (MAD) which is great for a beginner's two-button app such as this one, is Android only and if you have *any* aspirations for using a different BT device, you might be better off building the phone-side app with a cross-platform tool, such as Apache Cordova <br>(formerly PhoneGap). </p><p>Just my tuppence...YMMV</p>
<p>HC-06 can talk and recieve! The fact that it is SLAVE only means that it cannot be used as a HOST device to which other devices are connecting. Still as a SLAVE connected to other HOS such as Android device, the HC-06 is able to communicate both directions - send and recieve data.</p>
<p>Thanks for that info. Back to the data sheets...</p>
<p>This is so FAKE !!!</p>
<p>Do you also have the app inventor aia-file?</p>
<p>Download the .zip file from the google drive link provided above.</p><p>Since there is new version of app inventor, use this site </p><p><a href="http://convert.appinventor.mit.edu/" rel="nofollow">http://convert.appinventor.mit.edu/ </a> </p><p>to upload the .zip obtained(app inventor 1 - called classic) and it will return you aia-file compatible with the new version - app inventor 2. </p><p>There is a format change in the blocks file *.blk -&gt; *.bky and this site will do the transform. Without this, there will be no blocks displayed after upload.</p>
<p>if i got HC-06 that works on 9600 bauds... in this case, should I change my BT bauds to 19200 or just change the arduino code to serial.begin(9600)??</p>
<p>dont know why I get RUNTIME ERROR</p><p>Need BLUETOOTH_ADMIN permission: Neither user 10064 nor current process has android.permission.BLUETOOTH_ADMIN.</p><p>Im using HC-06...</p>
<p>Hola, como termina el dise&ntilde;o de la aplicaci&oacute;n en App inventor porque en la imagen en la parte baja no se alcanza a ver? </p><p>Gracias </p>
<p>Si hace clic una vez en la imagen aparecer&aacute; una ventana con s&oacute;lo la imagen. Haga clic una vez en esa imagen y ver&aacute; una p&aacute;gina con opciones de tama&ntilde;o a la izquierda.<br><br>Perdonen mi pobre espa&ntilde;ol.</p>
<p>Hey, I was pretty close to getting everything working. Just one question. This is the Bluetooth module I have <a href="http://www.tinyosshop.com/index.php?route=product/product&product_id=705" rel="nofollow">http://www.tinyosshop.com/index.php?route=product/product&amp;product_id=705</a> will this work? it connects to the device but wont connect to your app or any other app emulators.</p>
<p>I don't think it will work. The MIT App Inventor uses Bluetooth 2.0, while the module you have is Bluetooth 4.0.</p>
<p>Android App:<br>BlueUino: Bluetooth Remote for Arduino, Control your Arduino Over Voice as well as Buttons<br>https://play.google.com/store/apps/details?id=g.patels.blueuino<br><br>If you want to make app like this as per you requirements please Email me : micky.patel41@gmail.com.<br>Visit web site for more info : blueuino.blogspot.com.</p>
<p>Good looking app. Folks might want to know that it is written for the (defacto standard) HC-05.</p>
<p>The application &gt;&gt;</p><p><a href="http://speedy.sh/RMFgg/bluetoothforarduino-app-temperaturereadings.apk" rel="nofollow">http://speedy.sh/RMFgg/bluetoothforarduino-app-tem...</a></p><p>is the file deletd?</p>
<p>Yes, I also would need the code. Can you post it clearly?</p><p>I've a Itead Bluetooth shield with HC-05 BT module, can I use it for this project?</p><p> Thank you</p>
<p>will you please keep the mit app code clearly</p>
<p>If you want control your Arduino via WiFi or SMS as well as Bluetooth and you want to design your own custom menus and have the Arduino code generated for you and not do any Android coding at all. Then take a look at the many detailed example projects using pfodApp on www.pfod.com.au and here on instructables (just search for pfod)</p>
Good article
<p>For those who are at a loss of getting the App on your phone:<br>-make a usb connection between your phone and computer<br>-your phone may or may not come with questions like 'you want to switch on USB storage' if so 'YES'<br>-copy the &quot;bluetooth.apk&quot; (or any other apk file) to your phone<br>-go to &quot;Settings&quot; and allow yr phone to receive and install 'third party' or 'unknown' apps</p><p>-go to your filemanager app in your phone<br>-browse to the *.apk file you have just copied.<br>-open it</p>
<p>If anyone is still following this topic and they are still looking for a way to convert from &quot;Classic&quot; App Inventor (.blk) to AI2 (.aia) then go to this link http://appinventor.mit.edu/explore/classic.html</p><p>They talk about the demise of AI classic but part way down the page they give a link to a converter. Click on the link and follow instructions. Make sure you point it to the .zip file not the extracted files and presto... works like a charm.</p>
<p>can also go directly here: </p><p><a href="http://convert.appinventor.mit.edu/" rel="nofollow">http://convert.appinventor.mit.edu/</a></p>
<p>find the code given in below link and troubleshooting techniques and circuit diagram</p><p>http://knowledge-cess.com/arduino-android-interfacing-example-code-and-troubleshooting/</p>
<p>this is exactly what i need but i have to do the android code with Android studio can you help me pleaaaaaaaaaaaaaase :) :) </p>
<p>Hello... may you please help me in my project, What the requirement i need it to done my project. I want to control my room lights by using android phone but actually im confused how i can do it. What kind of tools and devices that help me to complete my project by using arduino. Thank you </p>
<p>Can somebody upload a .aia file for the app inventor? I cannot figure out how to import any of the files from that google drive into my app inventor.</p>
<p>thanks for the explanation , I will try soon . if I have not could please help me. thank you</p>
<p>Hello ,i tried this tutorial using the blutoothF2M03GLA BUT IT IS NIT Working , can i get ur help plz? realy feel lost !</p>
<p>hey @kerimil nice tutorial, I am having an issue sending data to the arduino with appinventor. The data is being sent but the HC-06 seems to be misinterpreting the sent data. I think it has something to do with the DelimiterByte value that is being used in appinventor 2. Right now it defaults to &quot;0&quot;. I attached a logic analyzer to see if I could identify the issue and I am getting framing errors. I am not sure what to think, any advice on the DelimiterByte? does that deliminate the byes or the sentence?</p>
<p>Hi kerimil. Great article. i wanna ask your advice and opinion regarding my project. i'm working on a project (final year project in university) where i try to make a tracker that can be controlled by android application. I'm trying to make the application can</p><p>1) set the maximum distance between the tracker device and the phone</p><p>2) trace the distance between the device and the phone,</p><p>3) phone will produce a sound when the device reach the maximum distance </p><p>so, what's your opinion? how can i make this using arduino? which kit? I really dont know anything about arduino. thanks :-)</p>
<p>Hi Kerimil;</p><p>Great article, thanks for taking the time to post it. I got it to work but know I want to dig in and understand your code. I'm not at all familiar with app inventor, but it looks cool, a lot friendlier than Eclipse! </p><p>How do I import your files into App Inventor, I know how to import the aia files but can't find anything on importing the .scm and .blk files you supplied.</p><p>Happy New Year!!</p><p>Don</p>
@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 &quot;evaluate and ignor results&quot;. The reply I got from the forum was that &quot;MIT was aware of the problem and would correct it in the next release.&quot; 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.
<p>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?</p><p>thanks!</p>
<p>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.</p>
<p>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!</p>
<p>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!</p>
<p>Hi JohnN3<br><br>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.<br><br>If you download the zip file listed in the article &quot;bluetoothforarduino_app&quot; from <a href="https://drive.google.com/folderview?id=0B_PfPoEotOF8N2JwT3RSX011SjQ&usp=sharing" rel="nofollow">https://drive.google.com/folderview?id=0B_PfPoEotO...</a> - you can go to - <a href="http://appinventor.mit.edu/explore/classic.html" rel="nofollow">http://appinventor.mit.edu/explore/classic.html </a> and import the zip file into &quot;Classic&quot; app inventor by going to &quot;My Projects&quot; then &quot;More Actions&quot; then &quot;upload source&quot; - The source being the zip file you d/lded above<br><br>Hope this helps :)<br><br>Ed</p>
<p>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.</p>
<p>Thanks ed, I'll see if I can move ahead with your info thanks for sharing!</p>
<p>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.</p>
<p>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. </p><p>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(&quot;Hello&quot;); 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 .</p><p>here is my work </p><p>I would be gratefull if you can hep me with this </p>
<p> 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.</p>

About This Instructable



More by kerimil:Simplest and cheapest adjustable power supply How to make the simplest compression fitting for a silent air compressor / vacuum pump How to log data from the arduino board 
Add instructable to: