Monday, April 11, 2016

Android BluetoothChat connect to Arduino Uno + HC-05

Last example show "Android BluetoothChat example link with HC-05 Bluetooth", to connect to PC via FTDI adapter. Here is another example - Arduino UNO + HC-05 to echo received data back to the sender.

For my on-hand HC-05 sample, it set as slave role and 9600, 0, 0, PIN="1234" by default. So it can be used in this example without any extra setting.


Connection between UNO and HC-05
HC-05 Rx - Uno Tx (1)
HC-05 Tx - Uno Rx (0)
HC-05 GND - Uno GND
HC-05 VCC - Uno 5V
(My HC-05 marked "Power: 3.6V-6V", refer here, make sure your HC-05 can work on 5V.)

Uno_Serial_echo.ino
/*
Arduino Uno + HC-05 (Bluetooth) - echo bluetooth data

Serial (Tx/Rx) communicate to HC-05
HC-05 Rx - Uno Tx (1)
HC-05 Tx - Uno Rx (0)
HC-05 GND - Uno GND
HC-05 VCC - Uno 5V

*/

void setup()
{
  delay(1000);
  Serial.begin(9600);
}

void loop()
{
  while(Serial.available())
  {
    char data = Serial.read();
    Serial.write(data);
  }
}

This video show how Android BluetoothChat example link with Arduino UNO + HC-05. For the Android BluetoothChat example, refer last post.


Related:
Connect Arduino Due with HC-06 (Bluetooth Module)





3 comments:

  1. Can you do it also for a mega
    and turn on a led

    ReplyDelete
  2. Were you able to fix the problem with data being sent from the ht-05 to the chat program on the Android? I noticed you have the same problem I do, with character loss and extra s. I am not sure if it is the arduino or android program, at this point. I assume Android timing with receiving.

    ReplyDelete
    Replies
    1. As I remember, i think that it relate to the buffer size of Of Uno's Serial library. I haven't looked in details, so I can't confirm it.

      Delete