Arduino Forum

Using Arduino => Project Guidance => Topic started by: evilcubed on Jan 28, 2013, 02:16 am

Title: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: evilcubed on Jan 28, 2013, 02:16 am
i have a budget of about 60-70ish dollars. i want to make a project where the Arduino takes the info from the sensors connected into the arduino, but i want to send that information to an android smartphone. The project also needs to be small, and i dont need that many pins in the arduino. what do you think is the best arduino and best way to do this?
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: HazardsMind on Jan 28, 2013, 02:46 am
I used a JY-MCU Bluetooth slave module to get my robot to work with an Android tablet. However you can also use Wifi, to do the same. Look at the Bluetooth chat program.
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: evilcubed on Jan 28, 2013, 03:39 am
will it work with the arduino pro mini? or arduino lilypads? is there any setup required or is it plug and play type thing?
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: HazardsMind on Jan 28, 2013, 05:36 am
It should just be plug and play, mine was, aside from the pairing.
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: teckel on Jan 28, 2013, 06:49 am

i have a budget of about 60-70ish dollars. i want to make a project where the Arduino takes the info from the sensors connected into the arduino, but i want to send that information to an android smartphone. The project also needs to be small, and i dont need that many pins in the arduino. what do you think is the best arduino and best way to do this?


I paid $8 for a bluetooth connection to my Android phone.

http://rctimer.com/index.php?gOo=goods_details.dwt&goodsid=764&productname=

Works perfectly.

Tim
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: evilcubed on Jan 28, 2013, 02:12 pm
Ok thanks :) sho you know if our works with the Arduino pro mini? Because that's the board I want to use
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: teckel on Jan 28, 2013, 11:14 pm

Ok thanks :) sho you know if our works with the Arduino pro mini? Because that's the board I want to use


It will work with any Arduino.

Tim
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: trendski on Feb 04, 2013, 11:22 am
Hi teckel,

do you have any code examples of how to get this working with arduino and android?

cheers
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: MichaelMeissner on Feb 04, 2013, 02:20 pm

Hi teckel,

do you have any code examples of how to get this working with arduino and android?

cheers

Most of the bluetooth modules that you can buy have 4-6 pins (Rx, Tx, Power, Ground, and optionally Key, State).  You hook Rx up to a port that does serial input, Tx up to a port that does serial output, Power and Ground to their respective rails, and State up to a LED if you want an indication of the connection.  On your pro mini, you might connect Rx to pin 0, Tx to pin 1, and use the hardware serial port using the Serial function.  You could use other pins with the software serial port emulation.  On my Teensy 3.0, I'm using pins 7 & 8, which on that chip is the 3rd hardware serial port.

Here is some quick and dirty code that I was using to test my HC-05 bluetooth serial device on my Teensy 3.0.  I have 4 LEDs hooked up to pins 13, 12, 11, and 10.  I use a single character command:


Code: [Select]


#include <stddef.h>

const int leds[] = { 13, 12, 11, 10 };

#define NUM_LEDS (sizeof (leds) / sizeof (leds[0]))

void
setup (void)
{
 size_t i;

 Serial3.begin (9600);
 Serial3.print ("Start\r\n");
 Serial3.flush ();

 for (i = 0; i < NUM_LEDS; i++)
   {
     pinMode (leds[i], OUTPUT);
     digitalWrite (leds[i], LOW);
   }
}

static int number = 0;

void
loop (void)
{
 if (Serial3.available ())
   {
     char ch = Serial3.read ();
     if (ch >= 'a' && ch < 'a' + NUM_LEDS)
digitalWrite (leds[ ch-'a' ], LOW);

     else if (ch >= 'A' && ch < 'A' + NUM_LEDS)
digitalWrite (leds[ ch-'A' ], HIGH);

     else if (ch == '.')
delay (1000);

     else if (ch == ',')
delay (250);

     else if (ch == '0')
{
 for (size_t i = 0; i < NUM_LEDS; i++)
   digitalWrite (leds[i], LOW);
}

     else if (ch == '*')
{
 for (size_t i = 0; i < NUM_LEDS; i++)
   digitalWrite (leds[i], HIGH);
}

     number++;
     Serial3.print ("Bluetooth number: ");
     Serial3.print (number);
     Serial3.print (", read: ");
     Serial3.write (ch);
     Serial3.print ("\r\n");
   }
}


I happen to use the "Connection Terminal"  app on the phone that provides a simple serial terminal interface: https://play.google.com/store/apps/details?id=app.bluetooth&hl=en (https://play.google.com/store/apps/details?id=app.bluetooth&hl=en).

I also tested the BTInterface trial app as mentioned in this thread: http://arduino.cc/forum/index.php/topic,145241.0.html (http://arduino.cc/forum/index.php/topic,145241.0.html).

One thing to watch out for is whether the device you buy can operate at the voltage  your pro mini runs at (5v or 3.3v).

I bought my unit from a US seller on ebay (nyplatform) for $11US, and the app on the phone was free.  There are various other bluetooth apps on the phone.
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: HazardsMind on Feb 04, 2013, 02:29 pm
A simple code you can try is already provided to you in the Android examples, BlueToothChat. That is the same program I used to get started with, until I was able to break it down to what I needed, to make my own test app.

Get that code, pair the BT module and use a simple arduino code to toggle an LED on and off with "H" and "L".
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: trendski on Feb 04, 2013, 03:59 pm
Thanks for the input guys

I'll get myself one of those devices and play with it.

cheers
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: teckel on Feb 04, 2013, 04:15 pm

Hi teckel,

do you have any code examples of how to get this working with arduino and android?

cheers


It seems others have taken care of this for you.  They're right, you just treat it like a standard serial connection.  You need to be running some sort of app on the other end (like a terminal emulator on an Android).  You could then expand that to a mobile app.  I've only done Android apps, but I'm sure you could do the same with the iPhone/iPad.

Tim
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: MichaelMeissner on Feb 04, 2013, 06:37 pm


Hi teckel,

do you have any code examples of how to get this working with arduino and android?

cheers


It seems others have taken care of this for you.  They're right, you just treat it like a standard serial connection.  You need to be running some sort of app on the other end (like a terminal emulator on an Android).  You could then expand that to a mobile app.  I've only done Android apps, but I'm sure you could do the same with the iPhone/iPad.

Tim

From what I've read, iphone apps are a little bit more tricky, since the iphone bluetooth will only connect to bluetooth devices blessed by Apple, and in order to be blessed by Apple, the developer needs to pay a hefty fee to be licensed as an Apple developer.

In terms of Android apps, I just download the Bluetooth Controller App, which gives you 9 buttons that you can label, and these buttons will send a particular text message to your device.  For my usage, that is sufficient, since I just want a simple replacement for an IR remote control, and it is a lot simpler than a chat program that you enter in text, and hit a send key.  https://play.google.com/store/apps/details?id=apps.BT&hl=en (https://play.google.com/store/apps/details?id=apps.BT&hl=en)
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: teckel on Feb 04, 2013, 10:00 pm



Hi teckel,

do you have any code examples of how to get this working with arduino and android?

cheers


It seems others have taken care of this for you.  They're right, you just treat it like a standard serial connection.  You need to be running some sort of app on the other end (like a terminal emulator on an Android).  You could then expand that to a mobile app.  I've only done Android apps, but I'm sure you could do the same with the iPhone/iPad.

Tim

From what I've read, iphone apps are a little bit more tricky, since the iphone bluetooth will only connect to bluetooth devices blessed by Apple, and in order to be blessed by Apple, the developer needs to pay a hefty fee to be licensed as an Apple developer.

In terms of Android apps, I just download the Bluetooth Controller App, which gives you 9 buttons that you can label, and these buttons will send a particular text message to your device.  For my usage, that is sufficient, since I just want a simple replacement for an IR remote control, and it is a lot simpler than a chat program that you enter in text, and hit a send key.  https://play.google.com/store/apps/details?id=apps.BT&hl=en (https://play.google.com/store/apps/details?id=apps.BT&hl=en)


Nice little app for simple testing.  Thanks, it will help.

Tim
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: HazardsMind on Feb 04, 2013, 10:04 pm
I didn't see that app when I was starting out :( , is it new? That would have made things much easier for me.
Title: Re: Cheap way to connect an Arduino to a Android Smartphone via bluetooth
Post by: MichaelMeissner on Feb 04, 2013, 10:23 pm

I didn't see that app when I was starting out :( , is it new? That would have made things much easier for me.

I just noticed it today.  I was looking at one of the other bluetooth apps, and it was listed as an app other people who had looked at the page I was one also looked at.