arduinohm-10arduino-nano

Communication between Arduino Nano and HM-10 BLE controller is not working


I want to check if communication is working between my SerialMonitor in Arduino IDE and BLE controller.

I typed command AT to my SerialMonitor and it suppose to return OK response but nothing happened.

This is scheme what I used:

enter image description here

Code:

 #include <SoftwareSerial.h>
SoftwareSerial bleSerial(2, 3); // RX, TX
void setup() {
  //initialize serial port for logs
  Serial.begin(9600);
  while (!Serial) {
  }
  bleSerial.begin(9600);
}
void loop() {
  if (bleSerial.available()) {
     Serial.write(bleSerial.read());
  }

  if (Serial.available()) {
    bleSerial.write(Serial.read());
  }
}

UPDATE:

Changed values for SoftwareSerial bleSerial(3, 2); // RX, TX still doesnt work.

UPDATE2:

I've tried switching pins and code, nothing works. I should at least see HM-10 controller in my bluetooth devices on my Android phone, but I cant see anything.

UPDATE3:

I've used code from this Stackoverflow post and its working fine. I can finally see controller in my bluetooth devices on my Android phone also It returned name MLT-BT05 after AT+NAME? command. Looks like you have to read message per char and put delay 10ms between chars, otherwise it will not be possible to read message from BLE controller. That was the only problem.


Solution

  • You should connect RX-TX and TX-RX (not RX-RX and TX-TX like your graphic shows) so change the cables and the code from

     SoftwareSerial bleSerial(2, 3); // RX, TX
    

    to

     SoftwareSerial bleSerial(3, 2); // RX, TX
    

    Connect according to this graphic (incl voltage divider) enter image description here

    Abd use the following sketch to test (read comments for details):

    //  SerialIn_SerialOut_HM-10_01
    //
    //  Uses hardware serial to talk to the host computer and AltSoftSerial for communication with the bluetooth module
    //
    //  What ever is entered in the serial monitor is sent to the connected device
    //  Anything received from the connected device is copied to the serial monitor
    //  Does not send line endings to the HM-10
    //
    //  Pins
    //  BT VCC to Arduino 5V out. 
    //  BT GND to GND
    //  Arduino D8 (SS RX) - BT TX no need voltage divider 
    //  Arduino D9 (SS TX) - BT RX through a voltage divider (5v to 3.3v)
    //
    
    #include <SoftwareSerial.h>
    SoftwareSerial BTserial;      
    
    char c=' ';
    bool NL = true;
    
    void setup() 
    {
        Serial.begin(9600);
        Serial.print("Sketch:   ");   Serial.println(__FILE__);
        Serial.print("Uploaded: ");   Serial.println(__DATE__);
        Serial.println(" ");
    
        BTserial.begin(9600);  
        Serial.println("BTserial started at 9600");
    }
    
    void loop()
    {
        // Read from the Bluetooth module and send to the Arduino Serial Monitor
        if (BTserial.available())
        {
            c = BTserial.read();
            Serial.write(c);
        }
    
        // Read from the Serial Monitor and send to the Bluetooth module
        if (Serial.available())
        {
            c = Serial.read();
    
            if (c!=10 & c!=13 ) 
            {  
                 BTserial.write(c);
            }
    
            // Echo the user input to the main window. The ">" character indicates the user entered text.
            if (NL) { Serial.print("\r\n>");  NL = false; }
            Serial.write(c);
            if (c==10) { NL = true; }
        }
    }