Communication HC-06 with android

1
Hello, I am a layman and I would like to know how to make, if possible, a bluetooth data transfer from Android to the Arduino HC-06 module using the cellular pairing itself. That is, how to only manipulate the programming of data sending / reading functions in Android and Arduino to establish communication. I did a little research on the subject and found only very robust projects or applications that are not currently relevant. If you can teach me, indicate some tutorial or make a recommendation would be very grateful.

    
asked by anonymous 19.05.2016 / 21:43

1 answer

0

You can read what is received by the HC-06 module, with the Arduino, as a standard serial input. An example of the code (for reading and writing) might be this:

#include <SoftwareSerial.h>

// Define os pinos para comunicação de série (RX, TX)
// Pinos 6 e 7 neste caso
SoftwareSerial MinhaSerial(6,7);
String command = "";

void setup()  
{ 
  // Inicia a comunicação de série com o PC
  Serial.begin(115200); 
  Serial.println("Digite os comandos AT :"); 
  // Inicia a comunicação de série com o módulo BT (portas 6 e 7)
  MinhaSerial.begin(9600); 
} 

void loop() 
{
  // Se o módulo BT tiver bytes para ler
  if (MinhaSerial.available())
  { 
    // Enquanto o módulo BT tiver bytes para ler
    while(MinhaSerial.available())
    {
      // Acrescentar os bytes lidos à variável "comando"
      comando += (char)MinhaSerial.read(); 
    }

    // Deixando o módulo de ter bytes para ler
    // Imprimir a variável "comando" para a interface de série ligada ao PC
    Serial.println(comando);
    // Fazer reset à variável "comando"
    comando = ""; 
  } 

  // Se a interface do PC tiver bytes para ler
  if (Serial.available())
  {
    // Esperar 10ms
    delay(10);
    // Escrever para o módulo BT o que é recebido do PC
    MinhaSerial.write(Serial.read()); 
  } 
}

The Arduino will have to have 2 serial interfaces, one to connect to the PC and another to the Bluetooth module. This example was taken from from here .

In order to communicate with an android mobile phone I advise you first to use an application that works like a Bluetooth terminator, such as Bluetooth Terminal .

After you have verified that there is in fact communication between the Arduino and the android, you should (if you so desire) create an application of yours, for example using cordova / Phonegap / Phonegap Build and the BluetoothSerial plugin to read the BT data in your app.

In this way, if you know web programming (JS, HTML and CSS) you do not have to program natively on android, which may be good for those who are starting.

    
24.05.2016 / 23:22