Communication HC-06 with android

Asked

Viewed 370 times

1

Hello, I am layman on the subject and I would like to know how to make, if possible, a data transfer via bluetooth from Android to the module HC-06 of the Internet using the phone pairing itself. That is, how to handle only the programming of sending/reading functions on Android and Arduino to establish communication. I did a little research on the subject and found only very robust projects or involving ready-made applications, which are not interesting at the moment. If you can teach me, indicate some tutorial or make a recommendation I would be very grateful.

1 answer

0

You can read what is received by the HC-06 module, with the Arduino, as a normal serial entry. An example of code (to read and write) can 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()); 
  } 
}

Arduino must have 2 interfaces in series, one to connect to the PC and the other to the Bluetooth module. This example was taken from here.

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

After you can verify that there is indeed communication between Arduino and android is that you should (if you want to) create an application of your, for example using Cordova/Phonegap/Phonegap Build and the plugin Bluetoothserial to read BT data in your app.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.