Cannot send AT commands to HM-10

Hello guys,

Just bough an HM-10 module for my genuino Mega and I don’t achieve to use AT commands.
The code I’m using is close to SoftwareSerialExemple :

#include <SoftwareSerial.h>

//SoftwareSerial mySerial(50, 51); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(9600);

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  Serial1.begin(9600);
  Serial.println("Hello, world?");
}

void loop() // run over and over
{
  if (Serial1.available()){
    Serial.write(Serial1.read());
    //Serial.println("ok2");
  }
  if (Serial.available()){
    char data = Serial.read();
    Serial1.write(data);
    Serial.write(data);
  }

}

The serial communication works fine, I tried it with an android app called BLEscanner and I can send data to my arduino from my phone. Though when I send “AT” to my module, there is no answer …
My HM-10 is fixed on a ZS-040 board.

Am I Missing something ?

Help would be much appreciated, and if you need me to give your more info I will :slight_smile: (I also appologize for my english, french ppl ain’t realy good at it :frowning: )

The first thing you need to be more informative about is which pins the bluetooth is connected to.

You call up Software serial - myserial - but you aren't using it. If HM-10 is connected to 50,51 it has no chance of working. This is not such a bad start as using software seria with a Mega is a stupid idea anyway.

You then call Serial1 software serial. It isn't, it is a hardware serial, pins 18,19

You then want to Serial.print Hello world to Serial0, which will probably work but is equally probably not what you intended.

Finally, the programme you are using is not involved in sending AT commands

You might find the following background notes useful

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Therein is also a programme for configuring an HC-06 with a Mega, that should eb OK for your HM-10

Hi, thanks for the answer !

I plugged my bluetooth module to 18 and 19 pins and cared about connecting the RX of the Mega to the TX of the module and the TX to the RX aswell. About the "Myserial" part, I commented the line, I started my code by pasting the existing one I found in the exemples given by Arduino. I was willing to send my AT commands through the Serial Monitor by typping them. The part about Serial.print was already into the exemple I took, I just changed the baudrate to fit what I found in the HM-10 data sheet, as far as I understand it this should display "Goodnight moon" and "Hello world" into my serial monitor if the calls to Serial.begin and Serial1.begin are succesfull. (When I run the code, I do see them).

While typping this, I found a realy usefull blog that got me out of it. It appears that my HM-10 is accually a copycat, and in order to get AT commands working they have to be followed by an return carriage/new line combination (so "\r\n") to work. Here is the link to that website, if someone else needs it.

Thanks for your answer anyway Nick ;)

The AT commands have to be sent from the Mega at full speed, ie no gaps between the characters, so typing them from a keyboard wont work.

I may have been unclear, but I meant to type them into the Serial Monitor and then send them. That should work right ?

Yes. I don't actually see how you can send them any other way.

Hello, i am facing the same issue of sending “AT” command through Serial monitor and unable to receive the “OK” response.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2,3); //RX|TX


void setup(){
  Serial.begin(9600);
  mySerial.begin(9600); // default baud rate
  Serial.println("start");
  delay(1000);
  Serial.println("AT commands: ");
}

void loop(){
  //read from the HM-10 and print in the Serial
  if (mySerial.available())
    {
  
    Serial.write(mySerial.read());
    }
   //read from the Serial and print to the HM-10
  if (Serial.available())
    {
    char data = Serial.read();
   
    mySerial.write(data);
    
}
}

Hope that any kind soul can help me, thanks in advance :slight_smile: