Bluetooth connect Arduino to Android

I have a JY-MCU Bluetooth Module that I have connected to a Arduino Micro with a logic level converter to convert the RX/TX from the JY-MCU to 5V.

I have been using this tutorial: http://www.instructables.com/id/Success-Using-the-JY-MCU-linvor-Bluetooth-Module/?ALLSTEPS
and this software on Android: http://code.google.com/p/amarino/downloads/detail?name=Amarino_2_v0_55.apk&can=2&q=

My problem is that my communication is a bit strange. When I type something into the serial monitor through the Arduino software, I don’t see anything on the phone. But, if after this failure I send something from the phone to the Arduino, the Arduino responds back with what was pending in its serial monitor plus what was sent from the phone.

So, for example, this happens:
(send) phone: A
(receive) arduino: nothing
(receive) phone: A
(send) arduino: asdf
(receive) phone: nothing
(send) phone: B
(receive) phone: asdfB

Soooo, I am confused. I am using SoftwareSerial to have the multiple serial connections but they seam to be getting confused. My Arduino code is:

#include <SoftwareSerial.h>

SoftwareSerial bluetoothSerial(6, 5); // RX, TX
String command = "";

int alwaysOnPin = 12;
int messagePin = 11;

void setup() {
  pinMode(alwaysOnPin, OUTPUT);
  pinMode(messagePin, OUTPUT);
  
  delay(2000);
  
  Serial.begin(9600);
  Serial.println("Type AT commands!");
  
  bluetoothSerial.begin(9600);
  
  digitalWrite(alwaysOnPin, HIGH);
}

void loop() {
  //I NEVER MAKE IT INTO THIS IF STATEMENT, ALWAYS FALSE
  if (bluetoothSerial.available()) {
    while (bluetoothSerial.available()) {
      char received = (char)bluetoothSerial.read();
      
      command += received;
    }
    
    Serial.println(command);
    command = "";
  }
  
  if (Serial.available()) {
    delay(10);
    bluetoothSerial.write(Serial.read());
  }
  
  delay(500);
  Serial.println("looping");
}

shiznatix:
Soooo, I am confused.

No surprise there. You have been reading an Instructable.

There are two things you can do with a bluetooth module, you can configure it with AT+ commands, or you can use it to communicate.

What are you trying to do with your bluetooth?

One of the most important things you need to know is that you don't have to configure a JY-MCU in order to use it.

I ask this particularly because the code refers to sending AT commands but there is no suggestion that that is what you want. I assume the code complies OK, but I suspect it is junk. I understand you are ignoring the writers admonishment to feed the JY-MCU with 3.3v VCC.

Nick_Pyner:
What are you trying to do with your bluetooth?

I want my bluetooth to be able to send sensor readings to my phone and, if needed, for the phone to be able to send information to my Arduino. Right now it only partially works.

Nick_Pyner:
I ask this particularly because the code refers to sending AT commands but there is no suggestion that that is what you want.

:blush: oh boy, of course it is. Wasn't paying attention.

Nick_Pyner:
I understand you are ignoring the writers admonishment to feed the JY-MCU with 3.3v VCC.

No I am feeding it with 3.3v, I have seen multiple tutorials saying to use 3.3 instead of 5 but until I get it to work myself, I believe nothing :slight_smile:

shiznatix:
I want my bluetooth to be able to send sensor readings to my phone and, if needed, for the phone to be able to send information to my Arduino. Right now it only partially works.

OK Here are some notes I have put together

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

The objective is to prove the point with two-way traffic. Pretty basic approach, but bulletproof all the same and, once you get it together, you should be good for anything.

No I am feeding it with 3.3v, I have seen multiple tutorials saying to use 3.3 instead of 5 but until I get it to work myself, I believe nothing :slight_smile:

I have seen nothing but confusing junk come out of those Instructables. Feeding 3.3v to a JY-MCU may not do any harm, but cannot possibly be a good idea, and may even be a cause of your problems. The writing on the back clearly says 3.6 > 6v. It has an on-board regulator to deliver 3.3v and needs 3.6v for stable operation. This s exactly the same as a 5v Arduino requiring a minimum of 7v at the barrel jack.

I don't even have a divider on the Tx pin, but at least I can see a clear reason for doing it. it.

Sorry for the bit of thread necromancy but I thought it might help someone in the future.

The issue I was having was that when you write out to a Serial connection, it queues up all of the chars. It is only if you send the int 19 that it will push the cache out.

So, if you want to send from the Arduino to the phone the string “cool” you would have to do:

bluetoothSerial.write("cool");
bluetoothSerial.write(19);

This does the trick! The 19 is also sent at the end of the string from the phone to the Arduino so if you just loop back what is received, it works.

Anyway, the magic int is 19!

So, if you want to send from the Arduino to the phone the string "cool" you would have to do:

bluetoothSerial.write("cool");

bluetoothSerial.write(19);



This does the trick!

Interesting, but does that have anything to do with sending sensor readings to the phone?

I want my bluetooth to be able to send sensor readings to my phone and, if needed, for the phone to be able to send information to my Arduino.