Serial Monitor not responding to input while trying to set HC-05(ZS-040) to AT

I can't run AT commands in Serial Monitor. (Both NL & CR + 9600 baud are set)
I followed this tutorial here.

Hardware:

  • Arduino MEGA 2560
  • Bluetooth Module HC-05 (ZS-040)
  • Ubuntu 16.04

This is the way I wired them:


I want to mention that before this I wired them multiple times without the resistors but not for more than 3-4 minutes.

This is the code I use:

 // Basic Bluetooth test sketch 5a for the Arduino Mega. 
    // AT mode using button switch
    // HC-05 with EN pin and button switch
    //
    // Uses serial with the host computer and serial1 for communication with the Bluetooth module
    //
    //  Pins
    //  BT VCC to Arduino 5V out. Disconnect before running the sketch
    //  BT GND to Arduino GND
    //  BT RX (through a voltage divider) to Arduino TX1 (pin 18)
    //  BT TX  to Arduino RX1 (no need voltage divider)   (pin 19)
    //
    // When a command is entered in to the serial monitor on the computer 
    // the Arduino will relay it to the Bluetooth module and display the result.
    //
     
    char serialByte = '0';
    const byte  LEDPIN = 13; 
     
    void setup() 
    {
        pinMode(LEDPIN, OUTPUT);
     
        // communication with the host computer
        Serial.begin(9600);  
     
        Serial.println("Do not power the BT module");
        Serial.println(" ");
        Serial.println("On the BT module, press the button switch (keep pressed, and at the same time power the BT module");
        Serial.println("The LED on the BT module should now flash on/off every 2 seconds");
        Serial.println("Can now release the button switch on the BT module");
        Serial.println(" ");
        Serial.println("After entering AT mode, type 1 and hit send");
        Serial.println(" ");
     
     
        // wait for the user to type "1" in the serial monitor
        while (serialByte !='1')
        {
            if ( Serial1.available() )   {  serialByte = Serial1.read();  }
        }  
     
     
        // communication with the BT module on serial1
        Serial1.begin(38400);
     
        // LED to show we have started the serial channels
        digitalWrite(LEDPIN, HIGH);  
     
        Serial.println(" ");
        Serial.println("AT mode.");
        Serial.println("Remember to to set Both NL & CR in the serial monitor.");
        Serial.println("The HC-05 accepts commands in both upper case and lower case");
        Serial.println(" "); 
    }
     
     
    void loop() 
    {
        // listen for communication from the BT module and then write it to the serial monitor
        if ( Serial1.available() )   {  Serial.write( Serial1.read() );  }
     
        // listen for user input and send it to the HC-05
       if ( Serial.available() )   {  Serial1.write( Serial.read() );  }
    }

The flash on the LED should change to on/off every 2 seconds, 1 second
on, 1 second off. This indicates AT mode. You can now release the
button switch.

Even though the LED is blinking like described (quote from above)
I get no response from typing 1 in Serial Monitor.

This is how my Serial Monitor looks after running everything as supposed:

Based on your pictures, it looks like all the pins at the top of the breadbord might be tied together. It is very common for the outside two rows to be common and you have all the pins of the board inserted into them.

blh64:
Based on your pictures, it looks like all the pins at the top of the breadbord might be tied together. It is very common for the outside two rows to be common and you have all the pins of the board inserted into them.

No the layout is correct, the 4 plugs together in a line in front of the BT PCB are in separate rows.
Tom... :slight_smile:

I also tried with this code:

#include <SoftwareSerial.h>

#define RxD 10
#define TxD 11

SoftwareSerial BTSerial(RxD, TxD);

void setup(){
  BTSerial.begin(250000);
  Serial.begin(9600);
  BTSerial.print("AT\r\n");
}

void loop(){

  if (BTSerial.available())
    Serial.write(BTSerial.read());

  if (Serial.available())
    BTSerial.write(Serial.read());

}

Having my module connected like this:

Bluetooth RXD → 10 pin on Arduino Mega 2560
Bluetooth TXD → 11 pin on Arduino Mega 2560
VCC → 5V
GND → GND

I tried all baud rated between 9600 - 460800 including the margins but I get no response. My Bluetooth HC-05 (ZS-040) is in AT mode as the led is blinking like it’s supposed.

grrigore,

I managed to do something like that with the same Bluetooth Module some time ago, going to look up for the code.

Hi,
If you have pin10 as Mega RX, then it should connect to Bluetooth TX.
Bluetooth Rx to Mega Tx.

Tom.. :slight_smile:

TomGeorge:
Hi,
If you have pin10 as Mega RX, then it should connect to Bluetooth TX.
Bluetooth Rx to Mega Tx.

Tom.. :slight_smile:

Oh, that's right. I didn't do this.

Thanks so much! :slight_smile: it worked for 9600

In your original post you appear to be using the exact code from the Martyn Curry tutorial linked, so I don't understand why it is not working. However, I do not like the Serial1.begin(38000) after the while loop() trying to read it. I would try place it before.

Serial1.begin(38400);
while (serialByte !='1')
        {
            if ( Serial1.available() )   {  serialByte = Serial1.read();  }
        }  
    
        // communication with the BT module on serial1
        //Serial1.begin(38400);

In your software serial code in the post #3 I do not think you have cross connected Tx>Rx and Rx>Tx.

EDIT: Yes, Tom pointed that out while I was posting

Originally you posted the image from the tutorial which does have the correct connections, rather than an image of your exact set up.

Are you certain that the module and the arduino are connected properly?

cattledog:
In your original post you appear to be using the exact code from the Martyn Curry tutorial linked, so I don't understand why it is not working. However, I do not like the Serial1.begin(38000) after the while loop() trying to read it. I would try place it before.

Serial1.begin(38400);

while (serialByte !='1')
        {
            if ( Serial1.available() )  {  serialByte = Serial1.read();  }
        } 
   
        // communication with the BT module on serial1
        //Serial1.begin(38400);




In your software serial code in the post #3 I do not think you have cross connected Tx>Rx and Rx>Tx.

EDIT: Yes, Tom pointed that out while I was posting

Originally you posted the image from the tutorial which does have the correct connections, rather than an image of your exact set up. 

Are you certain that the module and the arduino are connected properly?

Thank you for the answer.

I respected the connections from the tutorial when I tried but in the tutorial is used

// communication with the BT module on serial1
Serial1.begin(38400);

and for me, it now worked with 9600.