0

I have an Arduino Mega 2560 and a HM10 Bluetooth module (this one)

I have connected the Bluetooth according to the manufacturer's specifications: VCC -> 5v GND -> GND

TXD and RXD of the Bluetooth, I have tried to put them in pins of Arduino, in Serial1, in Serial2, in Serial3, with the same result.

The code I use for my tests is this:

#define BTserial Serial1

int LED_BOARD = 13;
int LED_RED = 2;
int LED_GREEN = 3;

void setup() {
    BTserial.begin(9600);
    Serial.begin(9600);
  
    pinMode(LED_BOARD,OUTPUT);
    pinMode(LED_RED,OUTPUT);
    pinMode(LED_GREEN,OUTPUT);
}

void loop() {
    if (Serial1.available()) {
        dato = Serial1.readStringUntil('\n');

        Serial.println("DATA RECEIVED: [" + String(dato) + "]");

        if (dato.equals("1")) {
            digitalWrite(LED_BOARD, HIGH);
        }
        if (dato.equals("0")) {
            digitalWrite(LED_BOARD, LOW);
        }
        
        if (dato.equals("RED_ON")) {
            digitalWrite(LED_RED, HIGH);
        }
        if (dato.equals("RED_OFF")) {
            digitalWrite(LED_RED, LOW);
        }

        if (dato.equals("GREEN_ON")) {
            digitalWrite(LED_GREEN, HIGH);
        }
        if (dato.equals("GREEN_OFF")) {
            digitalWrite(LED_GREEN, LOW);
        }
    }
}

I have an Android phone, and I use the Arduino Bluetooth Controller (HM-10 Module) app.

  • I send the text 1, and the led of the Arduino board (pin 13) turns on.
  • I send the text 0, and the led of the Arduino board (pin 13) turns off.
  • I send RED_ON, and the led of my breadboard, connected to pin 2, turns on
  • I send RED_OFF, and the led of my breadboard, connected to pin 2, turns off
  • I send GREEN_ON, and the led of my breadboard, connected to pin 3, turns on
  • I send GREEN_OFF, and the led of my breadboard, connected to pin 3, turns off

So the Bluetooth works.

My problem is trying to see the list of Bluetooth commands (AT+HELP command).

I have a method that is responsible for sending AT+HELP to bluetooth, but I have no response.

This is the method, which I run in the main:

String str_ii = "";
int ii_0 = 0;
void ble_help(){
    Serial.println("ble_help");

    BTserial.println("AT+HELP"); // list all AT+ commands
    while (true){ // loop to print all AT+ commands
        char in_char = BTserial.read();
        if (int(in_char)==-1 or int(in_char)==42){
            continue;
        }
        str_ii+=in_char;
        if (in_char=='\n'){
            if (str_ii==String('\r')+String('\n')){
                if (ii_0 == 0){
                    ii_0 = 1;
                    continue;
                }
                break; // break after more than 1 empty carriage return and newline
            }
            Serial.print(str_ii);
            str_ii = "";
        }
    }
}

When executing this method, in application Arduino Bluetooth Controller (HM-10 Module) app i see the text AT+HELP, but there is no reaction / response from the bluetooh. Neither in the Arduino Bluetooth Controller (HM-10 Module) application nor in the Arduino serial monitor

What am I doing wrong?

Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.