Go Down

Topic: Bluetooth connection between Android and Arduino (Read 3324 times) previous topic - next topic


Hello, I want to send data from an android smartphone to an Arduino Board through the RN-42-SM Bluetooth Transmitter.
The Android program only need to send either the characters '1' and '2' or the values 1 and 2. The Bluetooth receiver is checking for values on the network and when one of the both values is recognized the program must start a function.
The connection between the smartphone and the board is done perfectly : the LED is green and not flashing. The problem is when I send some data, on the smartphone, everything looks good but on the board, the voltage is always the same between Reception PIN and the Ground and, of course, the arduino program does nothing.
Apparently, there is nothing on the bluetooth network though the android smartphone is apparently sending perfectly the data.
If anybody know something about the bluetooth board's initialization please help me because I read many examples and tutorials and not have the same lines in the Setup function. It could also be a wrong setting or use of functions in either the arduino or the android code.
P.S. : Sorry for my English because I'm not a native speaker.


There are so many things that can go wrong here. You might have connected the module in the wrong way, the baud rate might be wrong etc.

Could you post the both the arduino code and the android app?


Feb 23, 2013, 04:28 pm Last Edit: Feb 23, 2013, 04:36 pm by MoaMoaK Reason: 1
Sorry to be late. So here are the both code. The goal of my project is to open and close a door from a smartphone. There is MD22 board linked with the arduino board.

On the android code I use a three buttons interface : one to connect, one to send "1" and the last to send "2"
show(String) is to show messages into a textView.

Android (only an extract):
Code: [Select]
public void onClick (View v)
if (v==butConnect)
connect(); // connect is to initialize the bluetooth radio, search for the MAC adress of my BT board and to connect.
else if (v==but1)
else if (v==but2)

public void sendData(int data)
} catch (IOException e)
show("Not send " + data.tostring()

//extract from the connect() function : to connect the smartphone

    try {
socket = device.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
sendStream = socket.getOutputStream();
} catch (IOException e)
show("Connect FAIL");
return -4;
    show("Connect OK");
    return 1;

Arduino :
Code: [Select]
#include <SoftwareSerial.h>

// Values to send to control the motor (MD22 board)
const int ouv = 255; // Value when opening
const int fer = 0; // Value when closing
const int stp = 128; // Vlaue when we want to stop the motor

const int pinSCL = 11; // Where we send these values to control the motor
const int pinTX0 = 2; // Linked to RX of the bluetooth board
const int pinRX1 = 3; // Linked to TX of the the bluetooth board
const int pinPI06 = 16; // To reset the bluetooth board

SoftwareSerial bluetooth(pinTX0, pinRX1);

char reception = 0; // to receive what the bluetooth send to the arduino board

unsigned long tempo = 5000;

void ouvrir() // to open our door
  analogWrite(pinSCL, ouv);
  delay (tempo);
  analogWrite(pinSCL, stp);

void fermer() // to close our door
  analogWrite(pinSCL, fer);
  analogWrite(pinSCL, stp);

void resetBT()
  digitalWrite(pinPI06, HIGH);
  digitalWrite(pinPI06, LOW);

void setup()
  pinMode(pinSCL, OUTPUT);
  pinMode(pinPI06, OUTPUT);
  analogWrite(pinSCL, stp);
void loop()
  if (bluetooth.available())
    reception = Serial.read();
    if (reception == 1)
    else if (reception == 2)


have you tried connecting with the arduino board from the computer via bluetooth to establish if the code is ok ?? Just use serial monitor - choose the right COM port and baud rate
that's the first thing you should do - if it works then there is something wrong with the android side of the project

have you got a datasheet of the BT module ?? I can't find it anywhere. My module doesn't require sending AT commands every time

ohh and I am affraid I can't help you as far as java is concerned - sorry


Connecting Arduino with Android via bluetooth with security?

Does anyone know how to connect an Arduino with Android via bluetooth with security? As in, the Arduino should only communicate with MY android device. No one else should be able to establish connections with the arduino. If anyone tries to search for the arduino bluetooth device, it should not be shown to them. But if I search for the arduino bluetooth device from my phone, it should be visible to me.
I did some research and found out that in order to achieve my requirement, I have to program the Arduino in such a way that only MY PHONE'S bluetooth mac address is allowed to connect to the arduino. But i have no idea about the programming part what so ever. In fact i don't even know if it's possible, Some one please help me. This is for my Final year project.
Sorry about my english. Hope you can understand.


Feb 27, 2013, 10:16 pm Last Edit: Feb 27, 2013, 10:17 pm by kerimil Reason: 1
You have to configure the bluetooth module - IIRC you have to use AT commands to get the MAC addresses of both the slave module and master module - then use command 'ATD=macaddress' on both of them, then set the slave module into undiscoverable mode ('ATH0')

other master devices shouldn't be able to discover the slave... the master should automatically connect with the slave and slave should accept the connection

That's how it works on the module I use (btm222) check the datasheet of yours just to be sure

here is the datasheet of btm222 with AT commands -> http://atnel.pl/download/elektronika/atb_btm_222/btm222_datasheet.pdf

Go Up