Hi guys,
I'm new here. With ready app, I can use my car with HC-06 via bluetooth. But I need BLE for Android code so I bought a HM-10. Because of I am a newbie, can't handle with it.
Vcc --->3.3V,
Gnd ---> ground,
Rx--->Tx0 1,
Tx--->Rx0 0.
But when I tried any of codes like;
int led = 13;
int ledHIGH = 0;
long bauds[] = {
// major
9600, 57600, 115200,
// others
19200, 38400, 4800, 2400, 1200, 230400
};
bool detectBleBaudRate() {
Serial.println("Detecting BLE baud rate:");
for (int i=0; i<(sizeof(bauds)/sizeof(long)); i++) {
Serial.write("Checking ");
long cur_baud = bauds[i];
Serial.println(cur_baud, DEC);
Serial1.begin(cur_baud);
Serial1.write("AT");
Serial1.flush();
delay(50);
String response = Serial1.readString();
if (response == "OK") {
Serial.println("Detected");
return true;
} else {
Serial1.end();
}
}
return false;
}
void setup() {
// init
Serial.begin(9600); // USB (choose 115200 in terminal)
if (detectBleBaudRate())
Serial.write("Ready, type AT commands\n\n");
else
Serial.write("Not ready. Halt");
pinMode(led, OUTPUT);
}
void loop() {
// read from BLE (HM-10)
if (Serial1.available()) {
Serial.write("ble: ");
String str = Serial1.readString();
Serial.print(str);
Serial.write('\n');
}
// read from USB (Arduino Terminal)
if (Serial.available()) {
Serial.write("usb: ");
String str = Serial.readString();
Serial1.print(str);
Serial.print(str);
Serial.write('\n');
}
}
Serial monitor gives me;
\Z⸮]⸮Detecting BLE baud rate:
Checking 9600
Checking 57600
Checking 115200
Checking 19200
Checking 38400
Checking 4800
Checking 2400
Checking 1200
Checking 230400
Not ready. Halt
2nd example is when I upload ;
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(0, 1); //RX|TX
void setup(){
Serial.begin(9600);
BTSerial.begin(19200); // default baud rate
while(!Serial); //if it is an Arduino Micro
Serial.println("AT commands: ");
}
void loop(){
//read from the HM-10 and print in the Serial
if(BTSerial.available())
Serial.print(BTSerial.read());
//read from the Serial and print to the HM-10
if(Serial.available())
BTSerial.print(Serial.read());
}
It gives ;
AT commands:
By the way, when I tried to write AT command, nothing happens. Is there any settings for Master/slave because when I connected device to HM-10, I can send data but Arduino doesn't do anything.
Thank you for your helps. Regards,
