HM-10 Starting Problem

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,

Please edit your post to add code tags. See the "How to use this forum" post for instructions.

Is it ok?

Hi,

See THIS PAGE that has HM-10 Info.

Also, most HM-10 modules have a built-in voltage regulator and run from 5V.

Can you show photo of the version you have??

Hi,
this is my HM-10. By the way, from Bluetooth 4.0 HM-10 Master Slave Module - Wiki, I tried to send and receive strings via LightBlue app and observed that I can send string from Arduino serial monitor to phone but can’t receive message from my iOS phone.

Is It necessary to setup HM-10 with FTDI cable? After that, can I use it comfortably?

Thanks for your help.

Hi,

this is my HM-10.

OK, that module is powered by 5V not 3.3 and it has level-shifting chip to run to Arduino that is running at 5V.

You should be able to use the test sketch on the page mentioned above at send/receive AT commands.

I can use AT commands with code below

void setup() {
  //define 2 serial port
  Serial.begin(9600);
  Serial1.begin(9600); 

}

void loop() {
  char c;
  //the IDE send,phone receive
  if (Serial.available()) {
    c = Serial.read();
     Serial1.print(c);
  }
  //the phone send ,IDE receive
  if (Serial1.available()) {
    c = Serial1.read();
    Serial.print(c);
  }
}

I setup name password slave mode.When this code is uploaded I can communicate in both ways from iPhone to Mac and opposite. Every string is shown in serial monitor from phone and every string is shown in phone from serial monitor. but when I tried echo code which is

String message; //string that stores the incoming message

void setup()
{
  Serial.begin(9600); //set baud rate
  Serial1.begin(9600); 
}

void loop()
{
  while(Serial.available())
  {//while there is data available on the serial monitor
    message+=char(Serial.read());//store string from serial command
  }
  if(!Serial.available())
  {
    if(message!="")
    {//if data is available
      Serial1.println(message); //show the data
      message=""; //clear the data
    }
  }
  delay(50); //delay
}

can't get any response from Mac to iPhone or opposite.