Instructables

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

Picture of Androino! Control an Arduino from your Android device using a cheap bluetooth module.
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:

Picture of You need:
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.

Step 2: Setup the Arduino hardware

The BT module comes preprogrammed with the following settings:
Device name: linvor
Baud rate: 9600
PIN: 1234

You can leave the settings as they are or change them with a serial adapter.
For more info see: http://wiki.openpilot.org/display/Doc/Serial+Bluetooth+Telemetry

Connect the bluetooth module to your Arduino.
BT module Rx-> Arduino Tx
BT module Tx-> Arduino Rx
VCC to 5v
GND to GND

Connect a sensor or potentiometer to analog pin A0.

Upload this sketch to your Arduino: http://pastebin.com/raw.php?i=xmyr840j
The onboard LED at D13 is toggled everytime a sensor value is requested from the Arduino.

Step 3: Setup the Android device

Picture of Setup the Android device
Install Android Scripting Layer and Python for Android:
http://code.google.com/p/android-scripting/
http://code.google.com/p/python-for-android/
(This instructable is based on SL4A r4)

Copy the code from http://pastebin.com/raw.php?i=FVxKzf1g
and name it androino.html
Copy the code from http://pastebin.com/raw.php?i=XEmEsATU
and name it androino.py
Change the BT_DEVICE_ID in androino.py to the address of your BT module.
If set to None, Android will ask you at program start which bluetooth device to use.
Upload both files to the /sdcard/sl4a/scripts/ directory on your phone.


1-40 of 59Next »
BBMSuiDeatH3 months ago

nice!

janley.molina4 months ago

What do you mean by "sensor" ?

mmmatjaz8 months ago

The bluetooth module does not work with arduino micros's RX and TX pins, but I does work with software serial. Any advice on that, anyone? I can't use software serial as I need the PWM pins for other stuff...

Hello Friend, I am doing a mechanical arm, and I wonder how I control the servos via Bluetooth? Has a model Tutorial?
thank you
can I test this application with hyper terminal in windows ?
i make a connection between mobile bluetooth and my labtop
and select the com port of the Bluetooth in hyper terminal

but when i open the mobile application to send any thing from the terminal as a test before connecting the arduino
The application cannot start
it gives me w white screen with no thing else

I installed the sl4a r4 and python interpreter

but the problem still exists ?
akeonly1 year ago
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);
}
}
4ntoine1 year ago
With ArduinoDroid (https://play.google.com/store/apps/details?id=name.antonsmirnov.android.arduinodroid) you can develop for Arduino on Android:
anand911 year ago
HI ..
please tell the program for arduino to transfer accelerometer sensor value serially using a bluetooth ttl interface
rikil1 year ago
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?
F4LLCON1 year ago
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
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);
}
Great stuff! Thank you so much! :)
adagio152 years ago
Hi!
Is there any way to just send serial command to arduino like the serial monitor in the IDE?
Anyway, Pretty neat instructable....
Tone3412 years ago
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?
loscat2 years ago
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?
stretcho2 years ago
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

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
mb17932 years ago
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.
Melbfella2 years ago
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 :)
smaw512 years ago
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.
davefish882 years ago
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.
Posted too soon -- changed "bluetoothReadLine()" to "bluetoothRead()" and it works !! Also found -- API reference --

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

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
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)  beverageexpert2 years ago
did you change the line:
BT_DEVICE_ID = '00:11:11:18:62:60'
to the id of your module?
crussoma2 years ago
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)  crussoma2 years ago
You see the address in the android system settings -> bluetooth.
Did you pair the module with your android?

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)  crussoma2 years ago
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
armonfire2 years ago
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)  armonfire2 years ago
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 :(
1-40 of 59Next »