Androino! Control an Arduino from your Android device using a cheap bluetooth module.

 by metanurb
values.JPG
jy_mcu_bt_module.jpg
This instructable shows you how to read sensor values from an Arduino with your Android device using a cheap bluetooth serial device you can order for under $10 on dealextreme or ebay.
This example uses Python as the scripting language for the Android scripting layer (SL4A) but you can choose from other languages like Perl, Lua, JavaScript etc. see: http://code.google.com/p/android-scripting/

 
Remove these adsRemove these ads by Signing Up

Step 1: You need:

jy_mcu_bt_module.jpg
1. JY-MCU bluetooth wireless serial port module.
http://www.dealextreme.com/p/jy-mcu-arduino-bluetooth-wireless-serial-port-module-104299
or search for "bluetooth module" on ebay
I've bought mine for $8.20 on dealextreme.
2. An Android device with bluetooth.
3. An Arduino board.
4. Some sensor or potentiometer to read values from.

1-40 of 45Next »
akeonly says: Apr 16, 2013. 3:46 AM
Hi metanurb,

I have the exact bluetooth module that you have but I can't send anything to this module. Below is simple echo code that I use. Have I missed anything?

Thank you.

Arduino mega 2560

const int LED_PIN = 13;
boolean toggle = true;

void setup() {
Serial1.begin(9600);
}

void loop() {
if (Serial1.available()) {
Serial1.println(Serial1.read());
digitalWrite(LED_PIN, toggle);
toggle = !toggle;
delay(1000);
}
}
4ntoine says: Apr 13, 2013. 11:56 PM
With ArduinoDroid (https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinodroid) you can develop for Arduino on Android:
anand91 says: Mar 23, 2013. 8:09 PM
HI ..
please tell the program for arduino to transfer accelerometer sensor value serially using a bluetooth ttl interface
rikil says: Feb 21, 2013. 2:07 AM
My bluetooth module is discovered by Nokia feature phone but Samsung Galaxy Ace can't find it. FYI, Ace is running on Android GingerBread 2.3.6. Is there any problem with class parameter of Bluetooth module?

My module's documentation goes here :http://www.robokits.co.in/documentation/Bluetooth%20UART%20Module%201545.pdf

I think this will be helpful to lot of other undocumented module owners cause I have similar module.

Is there any idea how to make it discovered by Android?
F4LLCON says: Dec 20, 2012. 1:13 PM
I have done everything in the tutorial, but I don't get any values. The bluetooth does connect because the blinking led on the bluetooth module stops blinking and stays on. But I do not get any values. I have the HC-06 2.0 bought from ebay. Any ideas of what might be wrong? Am a total noob at this. Thanks anyway
F4LLCON in reply to F4LLCONDec 20, 2012. 1:41 PM
I used the code below with the programs and scripts you provided. It should work right? What am I doing wrong? Please someone help, I really want it to work. I am using:
"HC-06 Bluetooth V2.0 RF Wireless Transceiver Module Interface RS232 TTL"

This is my code:

#define trigPin 13
#define echoPin 12
const int LED1 = 8;

int sensorValue = 0;

boolean toggle = true;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(LED1, OUTPUT);
}

void loop() {
 
  if (Serial.available()) {
  Serial.read();
  }
 
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line

  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance >= 200 || distance <= 0){
    Serial.println("Out of range");
    digitalWrite(LED1, LOW);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    digitalWrite(LED1, HIGH);
   
    sensorValue = Serial.print(distance);;
    digitalWrite(LED1, toggle); // toggle the LED
    toggle = !toggle;
  }
  delay(500);
}
AndroidWallies says: Dec 3, 2012. 2:44 PM
Great stuff! Thank you so much! :)
adagio15 says: Nov 29, 2012. 11:44 AM
Hi!
Is there any way to just send serial command to arduino like the serial monitor in the IDE?
Anyway, Pretty neat instructable....
Tone341 says: Nov 25, 2012. 5:03 PM
I am using Samsung galaxy note 2. when i run androino.py i get a black screen and then crashes,"unfortunately, SL3A has stopped." any solution?
loscat says: Nov 6, 2012. 10:17 AM
Nice instruct able. I do have one issue, when I run androino.py it doesn't open the html in a WebView, I see it in plain text :(. Any ideas?
stretcho says: Nov 4, 2012. 2:06 PM
Excellent, thanks for this - managed to tx/rx data dynamically between my website and my pad and the Arduino - fantastic - thanks again!

One question, as my Python scripting is not that hot - if I wanted to connect multiple bluetooth modules e.g. 2+ and route them all through my pad to my website how would I poll each module? something like this?.....

For x = 0 to (amount of bluetooth modules)
If BT(x) connected/success Then .....
TX/RX
End If
Loop

instrumentek says: Sep 25, 2012. 5:56 PM
Thank you for this. I have a problem, I loaded everything as per your instructions including the device I. When i load the androino.html it just opens the html file in text form. Is my android O.S. to old? Thanks
mb1793 says: Sep 9, 2012. 7:40 PM
hello i have been having trouble with youre code . every time i run the androino.py code i get this Message
[SyntaxError: can't assign to operator (androino2.py, line 13)]

line 13 is the line where i am assigning the BT_DEVICE_ID.
Melbfella says: Aug 17, 2012. 11:49 PM
Thanks for such a straightforward tutorial - I feel like an idiot having issues, where everyone else seems to have succeeded!

When I open SLA4, all I see is the html file, not the py file, which is defininately in the same directory as the html one...

Any thoughts on where I've gone wrong?

Thanks in advance :)
smaw51 says: Aug 2, 2012. 3:56 PM
Check out http://beta.appinventor.mit.edu/ for an easy way to make an android app for use with your bluetooth communication arduino stuff. It is a pretty easy interface and free!

Great for making buttons to send what you want for your commands. message me if you want an example of what I did for my android controlled car. easier in my opinion than a keyboard with small letters and big fingers.
davefish88 says: Jul 16, 2012. 1:45 PM
Thanks for the project. I found this after making a BT module work with a Picaxe14M2 and a little Android app called the Rocket Controller
from -- http://rocketbrandstudios.com/ -- This worked fine and returned
either an 8-bit or 10-bit value (depending on the call in the axe firmware) that
matched voltage on a pot (turn the pot, get a new value).

So now I am trying to use your Python approach. I have the BT only connected as a transmitter from the Picaxe and it just loops and sends a value out. When I run the Python code I see the connection light work but nothing happens when I click "get sensor data". I also tried the "dump.py" code. It also connects and gives back a couple of lines --

Result(id=2, result=u' .. very long what look like a MAC address ...', error=None)
Result(id=3, result=u'linvor', error=None)

-- and then nothing else. From some looking around, it looks like 'linvor' may be the default name for the module. Any ideas? Is there someplace where I can find documentation on ... droid.bluetoothReadLine() ...? Thanks for any help.
davefish88 in reply to davefish88Jul 16, 2012. 2:09 PM
Posted too soon -- changed "bluetoothReadLine()" to "bluetoothRead()" and it works !! Also found -- API reference --

http://code.google.com/p/android-scripting/wiki/ApiReference

beverageexpert says: May 25, 2012. 7:43 PM
When I goto bluetooth settings it finds linvor and I can pair with 1234 but it says paired but not connected. When I run the script it says javo.io.exception service failed to start. then it goes to the html and when i hit get sensor data it says sensor value null

any thoughts
beverageexpert in reply to beverageexpertMay 28, 2012. 4:13 PM
that was it. works like a champ
Now I would like to reverse it and have the android phone send a signal to the arduino to turn a led on and off
metanurb (author) in reply to beverageexpertMay 26, 2012. 4:54 PM
did you change the line:
BT_DEVICE_ID = '00:11:11:18:62:60'
to the id of your module?
crussoma says: May 2, 2012. 9:23 PM
How do you find the address of your BT Module? Also, for some reason, I cannot detect my BT module (w/ my Android) when it is hooked up to my Arduino as described above. Do I need to change the settings to make it findable?
metanurb (author) in reply to crussomaMay 3, 2012. 3:46 AM
You see the address in the android system settings -> bluetooth.
Did you pair the module with your android?

crussoma in reply to metanurbMay 3, 2012. 8:04 AM
Is the address that goes into the .py file the bluetooth address of the Android or the BT address of the module? When my module is powered it is recognized w/ the device name "OBDII", not linvor. I am able to pair with it using the pin 1234 but then when I run the .py file in sl4a and press the gear, nothing happens.

If the address that goes into the .py file is from the BT module, I'm not sure how to find it. As far as I can tell, I cannot find it just by looking at the module in the list of devices shown on my phone. Could this be that I am using an older phone (Nexus One), or the 2.3.6 operating system?

So you know, I ordered my piece from Ebay but it looks almost identical to the one shown above from dealextreme. It's my theory that the settings were changed by whoever the vendor was. The only physical difference I can see in the parts is that the gold strip that "zig-zags" at the top of my module has one less "zig-zag". I don't know what it does though. See the image I attached of my own module.
photo.JPG
metanurb (author) in reply to crussomaMay 3, 2012. 10:42 PM
The device id of your BT module goes into the .py file. You don't have to enter it at all, if the parameter is missing android shows you a dropdown menu where you can select the paired adapter: droid.bluetoothConnect('00001101-0000-1000-8000-00805F9B34FB')
For changing the module name, baud rate etc.: http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry
armonfire says: Apr 25, 2012. 7:09 AM
I ordered from dealextreme, taking forever, 3 weeks and I had to email them twice about the status to get them to ship it.
Advice to anyone else in the USA, use a North American seller on eBay.
metanurb (author) in reply to armonfireApr 27, 2012. 1:14 AM
Yeah.. I'm too waiting for stuff that I ordered 3 weeks before :/
And sometimes the orders get stuck in customs for over a week here in germany :(
slackbuster in reply to metanurbApr 30, 2012. 5:42 PM
I ordered an Ethernet shield from DX almost 2 months to the day and have not seen it despite it being "shipped". I'd recommend sending others to a more reputable site like Maplin (UK) or Sparkfun (US) before sending them to dealextreme.

Thanks for the writeup - I'll be trying this soon. :-)
(CH3CH2)2O says: Apr 26, 2012. 3:29 PM
This is awesome! I just got mine up and working. There is one thing I wanted to point out for others trying to do this.
In the androino.py python script, the following line of code opens the webview.

droid.webViewShow('file:///sdcard/sl4a/scripts/tulpe/androino.html')

In my case I had to modify the code to exclude "/tulpe". So it now reads

droid.webViewShow('file:///sdcard/sl4a/scripts/androino.html')

Without this change, I was getting a blank screen that did nothing because androino.py couldn't find the html file.

Anyway, Thanks metanurb for this instructable! I can't wait to start making awesome bluetooth telemetry stuff!
metanurb (author) in reply to (CH3CH2)2OApr 27, 2012. 1:10 AM
Oops.. I've updated the code.. thanks!
armenvegas says: Apr 9, 2012. 12:58 AM
hi this is my first time hear and im soo excited! can i use a bluetooth dongle and wire the into my arduino? in other words is there much difference in a bluesmirf and a d link bluetooth dbt-120?
EmmettBrown says: Apr 2, 2012. 7:51 AM
This looks really cool.

Question re the bluetooth: How does the JY-MCU compare to the BlueSmirf modules? It's a lot cheaper and so I was going to order one, but why is this one 8 bucks and the others are 40-60?

Also, what baud rates can you get through this module? If I had a python module talking to the bluetooth, how many commands could I issue per second?
metanurb (author) in reply to EmmettBrownApr 2, 2012. 11:12 PM
I don't have a BlueSmirf so I can't compare them.
Baud rate goes up to 230400 and I have mine running reliable at 115200 (7m indoor).
More info about the baud rates can be found here: http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry
As for the rate: 115200 / (8+1) = 12800 byte / second (if I get this right).
AtomSoft says: Mar 13, 2012. 7:41 AM
This is way better than using the full android dev! i didnt know they had a simpler way. Thanks!

Do you by any chance know of a barcode scanner using the Android Scripting Layer and/or Python for Android ?
metanurb (author) in reply to AtomSoftMar 13, 2012. 1:10 PM
this way-> http://www.mattcutts.com/blog/android-barcode-scanner/
AtomSoft in reply to metanurbMar 13, 2012. 2:27 PM
You are officially the man! in my book at least. :) Thanks a ton!
AtomSoft in reply to AtomSoftMar 13, 2012. 6:22 PM
Had to alter his code but works nice!

import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code.result['extras']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(‘android.intent.action.VIEW’, url)
AtomSoft in reply to AtomSoftMar 15, 2012. 2:10 PM
import android
droid = android.Android()
isbn = droid.scanBarcode().result['extras']['SCAN_RESULT'])
url = “http://books.google.com?q=%d” % isbn
droid.startActivity(‘android.intent.action.VIEW’, url)
patcc2 says: Mar 13, 2012. 4:07 PM
Could you make some python script to transmit the androids data to the arduino rather than the current design. I know it's fairly unrelated on the Android I could make the arduino bit but the Android is a bit tough since I don't know what functions print the androids built in sensor values.
metanurb (author) in reply to patcc2Mar 13, 2012. 11:05 PM
quemazon says: Mar 13, 2012. 8:13 AM
The specs say that this module runs a 3.3V max. How long have you been running it at 5V, and have you had any problems?
1-40 of 45Next »
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!