Hello, Arduino Community!
This is my first post. I am trying to communicate with an HC-05 ZS-040 module with AT commands. The consistent problem is that no response comes back from the HC-05 module after sending the "AT\r\n" command. And, as far as I can tell (after adding blinking to the BT.available condition as described below), no data on the serial line from the HC-05 becomes available.
My setup includes:
- Arduino Uno by Elegoo
- Screw Shield 1.0
- Two (2) 270 ohm resistors in parallel from 5V to LED annode
- White 3.2-3.4V LED in series with resistors and State pin of HC-05
- 2k ohm resistor from Rx of HC-05 to GND
- 1k ohm resistor from Rx of HC-05 to D10 (alternatively, D11) of Uno
- 3.3V of Uno to EN pin of HC-05 (alternatively 5v or D9 of Uno).
My code, although it has been changed many times during the testing I will describe, is as follows:
#include <SoftwareSerial.h>
SoftwareSerial BT(10, 11); // RX | TX
char c;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT); // Enable on-board LED
Serial.begin(9600); // baud rate for com with PC
Serial.println("Enter AT commands:"); // indicates Serial is begun on PC
BT.begin(38400); // baud rate for com with HC-05
while (BT.available()) { // end of fast blinking confirms
digitalWrite(LED_BUILTIN, HIGH); // HC-05 serial connection
delay(150); // is begun
digitalWrite(LED_BUILTIN, LOW);
delay(150);
}
}
void loop()
{
delay(1000); // Last attempt, delay until
BT.write("AT\r\n"); // "AT" command is sent over software
delay(200); // serial port. After delay,
while (BT.available() > 0) { // do nothing other than report chars
c = BT.read(); // from software serial port as long as
Serial.write(c); // anything is available
}
while (Serial.available() > 0) { // Left over from previous code
c = Serial.read(); // to send ASCII from PC serial monitor
Serial.write(c); // to HC-05 in case we get that far.
BT.write(c); // [Spoiler Alert] We haven't.
}
}
- I started with a blank sketch and 5V to the EN pin as directed in some tutorials
- I sent "AT" on the Arduino IDE Serial Monitor with Newline and Carriage Return as the method
- I, alternatively, used the Arduino Create web-based Serial Monitor in the same way. This was done, in both cases, with the Rx and Tx pins both matching and reversed.
- In all cases, both 9600 and 38400 baud rates were tried.
- In all cases, pressing the button on the HC-05 (presumably connected to pin 34) was done during boot up of the Uno, continuously during boot and during attempt to send "AT" over serial and not at all.
- Once using code to include the SoftwareSerial library, all iterations above were attempted multiple times.
Alterations to the code I've attempted, so far, include (and are not limited to)
- Adding LED blinking of different rates to BT.available and Serial.available if statements
- Echoing or not echoing BT to Serial and vice versa
- Waiting in setup to confirm BT.isListening with a while statement and LED blinks
- Changes in baud rate in BT.begin from 9600 to 38400 and back
- Changing write commands to print and back
- Writing read chars directly rather than first storing them as the char variable c
- Using both "if" and "while" have been used for the *.available() conditions
- Most recently, using a single BT.write command in code to send "AT\r\n" in case, as was suggested in one forum, sending the string one char at a time was too slow for the HC-05.
I have tried many other iterations of the code and wiring, as well.
In every instance, consistently, the red LED on the HC-05 (there is no other LED) blinks in a pattern of on for one second and off for one second any time the module is powered up while (or after) either 3.3v or 5v is applied to EN pin. Also, the same blink pattern occurs when holding down the button on the HC-05 during power up of the module or while continuing to hold it after power up. In all cases, this behavior is consisted when my phone lists this device as paired and when this device is deleted from by phone's Bluetooth device list.
I have successfully used a slight modification of the above code to echo serial data sent from my PC over the Arduino IDE and Arduino Create Serial Monitors to my phone using a Bluetooth serial terminal app. Both can send, both can read, and this occurs when both baud rates are set to 9600. Other baud rates cause the misreading of data one would expect.
I feel I've tried everything in every forum I've found with Google, so far. At this point in my post, I expect someone is thinking I fried my HC-05 module in some strange way. Buckle in, because all the tests I've listed above have been carried out on three HC-05 modules with the same markings. Two were ordered recently and another was ordered about a month ago from the same seller on Amazon. All three, by the way, still operate normally in another project (related to this one) as a slave device sending and receiving ASCII data to and from my phone (at 9600 baud rate over SoftwareSerial on pins D10 and D11).
All that said, I really hope there is some super simple solution I'm overlooking. I know this is an extremely common and simple module and there's no reason my module would be waiting for some command other than "AT\r\n" before it tells me "OK." I'll try anything suggested and provide code and pictures if asked.
To everyone who responds, thank you in advance for even reading this gigantic post!