Setting HC05 (ZS-040) to AT mode [code example]

I have used the following instruction to put HC05 (ZS-040) modules into AT mode to make changes to your setup. Also at least 3 other members have used this instruction with success.

This instruction is for the HC05 module marked ZS-040 connected to an Arduino Uno, Nano or any mega328 based board. Connect the HC05 as shown in the Martyn Currey page on AT mode for the HC05 (ZS-040) in my prior post. HC05 TX to Arduino pin 2 and HC05 RX to Arduino pin 3 (through voltage divider).

To change the baud rate you must first put the HC05 into AT mode. Do that by connecting the EN pin to 3.3V, NOT 5V. Then power up the Arduino board and HC05 module. The LED on the module should alternate lit for about 3 seconds and off about 3 second if it enters AT mode.

Upload the following code to the Arduino board.

// code by Martyn Currie.
// To enable AT mode connect the EN pin of the HC05 
// to 3.3V before powering the HC05.  
// Caution, do not connect EN to 5V.

#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX

const long baudRate = 38400;
char c = ' ';
boolean NL = true;

void setup()
{
   Serial.begin(38400);
   Serial.print("Sketch:   ");   Serial.println(__FILE__);
   Serial.print("Uploaded: ");   Serial.println(__DATE__);
   Serial.println(" ");

   BTserial.begin(baudRate);
   Serial.print("BTserial started at "); 
   Serial.println(baudRate);
   //BTserial.print("BTserial started at "); 
   //BTserial.println(baudRate);
   Serial.println(" ");
}

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();
      BTserial.write(c);

      // Echo the user input to the main window. The ">" character indicates the user entered text.
      if (NL)
      {
         Serial.print(">");
         NL = false;
      }
      Serial.write(c);
      if (c == 10)
      {
         NL = true;
      }
   }
}

In serial monitor (baud rate set to 38400) you should see something like (the file directory will be a bit different):

    Sketch: D:\bt_test_AT\bt_test_AT.ino
    Uploaded: May 19 2022

BTserial started at 38400

Type "AT" (no quotes) and enter. You may see:

    AT
    ERROR:(0)

That is normal.

Type "AT" (no quotes) and enter again. Now you should see:

    AT
    OK

If that is what you see, the HC05 is in AT mode and ready to accept AT commands.

To set to baud 115200, enter "AT+UART=115200,0,0" (no quotes).

HC05 AT command list with examples.

More HC05 information by Martyn Currie.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.