Arduino/Android Bluetooth project

Hi,

We are a group of 3 students. This year, our project is to connect an Android tablet and an Arduino with Bluetooth, itself equipped with LEDs. We have an Arduino Mega 2540 with a “bluetooth shield v1.1 by Seeedstudio” and a Samsung Galaxy Tab 2. The pairing between the devices is done, but the data transfer fails. The aim is to send the value 1 to the Arduino when the button “Turn the LED 1 on” is clicked on the app developped by ourselves. Same idea for the LEDs 2 and 3.

So it seems that it’s the bluetooth program which contains a problem because the original one without bluetooth function passed the tests successfully.

Here is the code :

#include <SoftwareSerial.h> //Software Serial Port
#define RxD 7
#define TxD 6
SoftwareSerial blueToothSerial(7,6); //(RxD, TxD)
const int LED0 = 0;
const int LED1 = 1;
const int LED2 = 2;
char serialA = 0;
void setup() {
Serial.begin(9600);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
pinMode(LED0, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
digitalWrite(LED0, LOW);
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
}
void loop() {
char serialA;
if(blueToothSerial.available()){//check if there’s any data sent from the remote bluetooth shield
serialA = blueToothSerial.read();
Serial.print(serialA);
}
else{
digitalWrite(LED0, HIGH);
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
}
switch (serialA)
{
case 1:
digitalWrite(LED0, HIGH);
break;
case 2:
digitalWrite(LED0, LOW);
break;
case 3:
digitalWrite(LED1, HIGH);
break;
case 4:
digitalWrite(LED1, LOW);
break;
case 5:
digitalWrite(LED2, HIGH);
break;
case 6:
digitalWrite(LED2, LOW);
break;
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as “SeeedBTSlave”
blueToothSerial.print("\r\n+STPIN=0000\r\n");//Set SLAVE pincode"0000"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println(“The slave bluetooth is inquirable!”);
delay(2000); // This delay is required.
Serial.println(“2 seconds passed”);
//char recstatus;
//blueToothSerial.print("\r\n+RTSTA:XX\r\n");
// recstatus = blueToothSerial.read();
//Serial.print(recstatus);
blueToothSerial.flush();
}

Sorry for our english we are French :slight_smile:

Regards.

It is definitely doable because I was able to do it myself, so I can help you. But first, your post is in the wrong place, it should be in the Programming Questions section.

When/if your post does get moved and even if it doesn't, please provide everything you have so far, what app you're using, a link to your Bluetooth module and what you have tried already.

Are you familiar with a terminal program called Putty or Realterm?

One big thing we cringe over, is code format and the use of code tags. If you will, please fix your code using the Arduino software by pressing CTRL+T, and then post it inside [ code ] ... [/ code] tags. Look for the # symbol above the smiley faces.

SoftwareSerial isn't a good choice - if you have a hardware uart free on your board use that (the Mega has 4 UARTs)

Hi, in your android app (if it is a native app) you can use this opensource java library: http://lucascassiano.github.io/AndroidArduinoAPI/. Android Arduino Bridge - AABridge - is an API developed with the aim of making easy and fast the implementation of Bluetooth connections between Android dispostivos and Arduino. Its differential is in the fact of possess methods which tend to be familiar to developers Arduino.

I hope that it is useful for your project.

Thx for sharing - will give it a try.

But the Release date of the SampleSketch is VERY VERFY in the future :D

Release Date (mm/dd/yy)
~29/23/2014