Androino! Control an Arduino From Your Android Device Using a Cheap Bluetooth Module.
Intro: Androino! Control an Arduino From Your Android Device Using a Cheap Bluetooth Module.
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/
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/
STEP 1: 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.
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.
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
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.
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.
STEP 4: Have Fun
Turn on Bluetooth on your Android and pair the device using the pin 1234.
Start SL4A on your Android device.
Select androino.py and then the gear symbol to start the application.
The SMD LED on your BT module should stop blinking at this point.
A WebView is started and when you click on the button, the sensor value gets read and displayed.
It's really that easy :)
SL4E API reference:
http://www.mithril.com.au/android/doc/
edit:
I've added this script which simply dumps anything that is send via serial out from your arduino.
dump.py http://pastebin.com/raw.php?i=uVxaD829
Select dump.py and then the console icon in SL4A to start.
Start SL4A on your Android device.
Select androino.py and then the gear symbol to start the application.
The SMD LED on your BT module should stop blinking at this point.
A WebView is started and when you click on the button, the sensor value gets read and displayed.
It's really that easy :)
SL4E API reference:
http://www.mithril.com.au/android/doc/
edit:
I've added this script which simply dumps anything that is send via serial out from your arduino.
dump.py http://pastebin.com/raw.php?i=uVxaD829
Select dump.py and then the console icon in SL4A to start.
51 Comments
SadanandT 8 years ago
find the code given in below link and troubleshooting techniques and circuit diagram
http://knowledge-cess.com/arduino-android-interfacing-example-code-and-troubleshooting/
BBMSuiDeatH 9 years ago
nice!
janley.molina 9 years ago
What do you mean by "sensor" ?
mmmatjaz 10 years 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...
Diego_Aquino 10 years ago
thank you
Mohammad_mm 10 years ago
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 ?
akeonly 11 years ago
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 11 years ago
anand91 11 years ago
please tell the program for arduino to transfer accelerometer sensor value serially using a bluetooth ttl interface
rikil 11 years ago
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 11 years ago
F4LLCON 11 years ago
"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 11 years ago
adagio15 11 years ago
Is there any way to just send serial command to arduino like the serial monitor in the IDE?
Anyway, Pretty neat instructable....
Tone341 11 years ago
loscat 11 years ago
stretcho 11 years ago
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 11 years ago
mb1793 11 years ago
[SyntaxError: can't assign to operator (androino2.py, line 13)]
line 13 is the line where i am assigning the BT_DEVICE_ID.
Melbfella 11 years ago
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 :)