How to receive data from Arduino to Android?

Hi, i’m using CC2541 bluetooth with Atmega 2560 and i send msg from Serial Terminal app android to Serial of Arduino, otherwise, i can’t know how i can send data from Arduino to Android Serial Terminal and receive this data in a variable, by example.

Someone have it? How?

This is code to send data from android to arduino:

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(11, 10); // RX | TX

void setup()
{
  pinMode(13, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(13, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(9600);  // HC-05 default speed in AT command more
}

void loop()
{
  // Continue lendo o HC-05 e envie para o Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Continue lendo no Arduino Serial Monitor e envie para o HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

http://www.martyncurrey.com/bluetooth-modules/

If you have your code written properly, the Bluetooth terminal app on your smartphone will display whatever the Arduino Mega via the connected Bluetooth module is sending.
There is no "variable" to read.
The Bluetooth terminal app handles everything.

If you send "123" from the Arduino, the Bluetooth app on your smartphone will display "123".

ieee488:
Bluetooth Modules | Martyn Currey

If you have your code written properly, the Bluetooth terminal app on your smartphone will display whatever the Arduino Mega via the connected Bluetooth module is sending.
There is no "variable" to read.
The Bluetooth terminal app handles everything.

If you send "123" from the Arduino, the Bluetooth app on your smartphone will display "123".

I must be send from the line command Monitor Serial?

I assume English is a second language, but your post is incoherent, your intentions are incomprehensible, and it is not even clear which Bluetooth module you are using.

You imply you can receive a message from Android but, if that is so, it is hard to see why you have a problem sending to it.

As I understand it the only issues you may have with CC2541 is that the phone app must be compatible with BT4 and CC2541 must be in the right mode for terminal application. If you can receive a message, it suggests that neither is an issue here.

The code you post is written for configuring an HC-05, in AT mode, and there is comment that says 9600 baud is the default for HC-05 in AT mode, which is not true. Further, if that is your intention, you cannot communicate with Android while in AT mode, irrespective of whether Bluetooth is CC2541 or HC-05.

After ensuring you know what you have in your hand you might try

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(11, 10); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(9600);  
}

void loop()
{
Serial.println("hello");
BTSerial.println("hello");
delay(1000);
}

Nick_Pyner:
I assume English is a second language, but your post is incoherent, your intentions are incomprehensible, and it is not even clear which Bluetooth module you are using.

You imply you can receive a message from Android but, if that is so, it is hard to see why you have a problem sending to it.

As I understand it the only issues you may have with CC2541 is that the phone app must be compatible with BT4 and CC2541 must be in the right mode for terminal application. If you can receive a message, it suggests that neither is an issue here.

The code you post is written for configuring an HC-05, in AT mode, and there is comment that says 9600 baud is the default for HC-05 in AT mode, which is not true. Further, if that is your intention, you cannot communicate with Android while in AT mode, irrespective of whether Bluetooth is CC2541 or HC-05.

After ensuring you know what you have in your hand you might try

#include <SoftwareSerial.h>

SoftwareSerial BTSerial(11, 10); // RX | TX

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(9600); 
}

void loop()
{
Serial.println(“hello”);
BTSerial.println(“hello”);
delay(1000);
}

Basically:

I can send data from Android to Arduino

But, i can’t send data from Arduino to Android.

I believe that problem happens because the ROLE Parameter, but i don’t understand about it.

When i send AT+ROLE is returned to me “AT+ROLE=0”.

And in Docs of CC2541, has that:

0 – SLAVE MODE?
1 – MASTER MODE?
2 – SENSOR MODE?
3 – iBEACON MODE
4 – WeCHAT MODE

Role=0 is slave which means it is not a master and Android must make the connection. After that it doesn't matter which is which, hence your ability to receive message from Android. If you have done that, rather than just think you do, then, clearly, this is not the problem. Further, there is nothing wrong with your wiring.

I suggest you stay away from AT mode, and AT commands. There is nothing to suggest you need to configure Bluetooth. You will find more information on using BT4 devices on the Martyn Currey website, as suggested above.

@LukeDaniel19

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

ballscrewbob:
@LukeDaniel19

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

The other post was better than this...

Nick_Pyner already told you not to put the module into AT mode and you persist in ignoring him.

shaking my head

.

LukeDaniel19:
The other post was better than this...

Then bring this one up to par as requested by others !
You have been given the links to do that.
Unless you need some time to read them in which case I would be happy to oblige you.

Bob.

ballscrewbob:
Then bring this one up to par as requested by others !
You have been given the links to do that.
Unless you need some time to read them in which case I would be happy to oblige you.

Bob.

I saw his newer post.
He re-posted the same sketch as this one.

.

ieee488:
I saw his newer post.
He re-posted the same sketch as this one.
.

Which given there was one answer to tell him about his cross post was acceptable to delete.