I'm trying to send AT commands to an HC-05 Bluetooth module
The following code worked fine last month (and for the previous many years), but it's currently not working. I'm getting no response from the software serial port.
In fact, none of my sketches using SoftwareSerial are working!!!!
I was trying a new serial libraries (AltSoftSerial, and NeoSWSerial) and after that everything stopped communicating. I'm not sure if that had an impact.
I tried uninstalling the Arduino IDE (including the other folders, e.g Arduino15) and re-installing
I just want this to work again.
I know that some people don't like SoftwareSerial for some valid reasons, but I just need this to work like it did a month ago, so telling me that SoftwareSerial sucks and I should use "X" instead doesn't really help me.
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(11, 12); // RX | TX
void setup()
{
pinMode(9, OUTPUT); // This pin will pull the HC-05 pin 34 (KEY pin) HIGH to switch module to AT mode.
digitalWrite(9, HIGH); // If you're using the "button method" to reach AT mode, then this doesn't matter
Serial.begin(9600); // This is the serial communication between the PC and the Arduino
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command mode is 38400
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
Serial.write(BTSerial.read());
}
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available()){
BTSerial.write(Serial.read());
}
}
Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
When you run the code does the HC05 go into AT mode as evidenced by the LED flashing about 2 seconds on and about 2 seconds off. If it is still flashing fast, it is not going into AT mode.
Even though the HC05 is powered by 5V, connecting the EN or Key pins to 5V is not a good idea. The HC05 inputs are not necessarily 5V tolerant. That is why the RX pin of the HC05 should be connected to a 5V TX through a level shifter (voltage divider).
As far as I know, the button must be pressed or the key/en pin must be at 3.3V before power is applied to the HC05 for it to go into AT mode. You cannot just set the key/en pin high to enter AT mode.
Thanks for these tips groundFungus.
I have run the HC-05 TX through a voltage divider,
and the LED is blinking slowly, indicating it's in AT-mode.
Like I said in the post, I have successfully executed this operation many times before.
It is as-if the SoftwareSerial just isn't working anymore.
I send "AT" to the module and receive nothing.
I've tried similar operations on other SoftwareSerial sketches......also nothing
I've tried with multiple boards (Uno and Nano) and multiple HC-05 / HC-06.......nothing.
I tested your code with one of my HC05 modules and an Uno. It will not go into AT mode with that code. If I connect the en pin to 3.3V and power the module it goes into AT mode. The same module works fine with SoftwareSerial using my communication mode and AT mode test codes (put into AT mode then powered up).
I used the "button method" to get it into AT-mode (i.e. the high-Pin9 becomes irrelevant)
The LED is blinking 2 secs off, 2 secs on. This had been an indication of AT-mode previously.
Is there a way it could be blinking like this without being in AT-mode?
Once you were in AT mode, this worked fine?
As Martyn Currie says in one of his tutorials, there are, on some HC05 modules, 2 AT modes. One is entered by pressing the button, powering the HC05 then releasing the button. This enters "mini" AT mode where only some commands work.
Tying the EN pin to 3.3V and powering the HC05 puts it into full AT mode.
That is in the Martyn Currie page that I linked in reply #4.
ok. I used the 3.3V method. The blinking is the same as before, but perhaps it's on a higher plane now.
Still doesn't appear to be working.
I tried switching the RX and TX just to be sure.
I tried tried powering off and powering on the unit.
Perhaps a different version of the IDE?
Update....I tried on a separate windows laptop with a fresh install of Version 1.8.15
still doesn't work
I have not seen any difference in SoftwareSerial from many versions of the IDE.
Some versions of the HC05 modules do not connect pin 34 (the EN pin) to the EN on the module. You have to connect a wire to pin 34. Please read the page that I linked. It may answer some of your questions.
Try this test code. It works on my HC05 connected to an Uno.
HC05 TX to Uno pin 11 (RX)
HC05 rx to Uno pin 12 (TX) through a voltage divider 5V to 3.3V.
HC05 EN pin to Uno 3.3V
HC05 Vcc to Uno 5V
HC05 ground to ground serial monitor baud set to 38400
When the sketch is loaded there will be a message "Bluetooth send and receive test." in serial monitor. Type "AT" (without quotes). You will probably see "ERROR:(0)" the first time. Type "AT again and you should get the "OK". Then try to send some AT codes. I tried a few codes and they all work.
Actually, I think you solved it!!!!
I needed the EN pin constantly connected to power.
Previously, I was only transiently connecting it.
Must be this new batch of HC-05's
Amazon....cripes.