HC-05 Bluetooth Module stopped working

I was working on my first project in HC-05 module (power on and off an LED on pin 8 with my android phone). Then suddenly the project wasn't working and I started testing. I disconnected the HC-05 module and used my serial monitor to send commands and the LED on pin 8 worked fine. I tried to connect to HC-05 with my phone and sometimes it did connect and sometimes didn't and when it did connected I couldn't blink the LED ON or OFF. Then I tried to set my HC-05 in AT mode but it didn't work too. I also know that in the receiver of the HC-05 I needed to apply a voltage divider because it works at 3.3V so I don't think that this is the problem. Can anyone help?

vassilisamir:
I disconnected the HC-05 module and used my serial monitor to send commands and the LED on pin 8 worked fine.

That implies there is nothing wrong with your code.

I tried to connect to HC-05 with my phone and sometimes it did connect and sometimes didn't and when it did connected I couldn't blink the LED ON or OFF.

In the light of the above, this suggests bad wiring, not wrong, just sloppy. There is a possibiilty that that the power supply isn't kosher. Please don't tell us you are using a 9v battery.

Then I tried to set my HC-05 in AT mode but it didn't work too.

Not relevant. Forget about AT mode for the moment.

Nick_Pyner:
In the light of the above, this suggests bad wiring, not wrong, just sloppy. There is a possibiilty that that the power supply isn't kosher. Please don't tell us you are using a 9v battery.

Of course I am not using a 9V battery, I have connected it to my PC.

About the AT mode I finally managed to set it and when I typed AT+STATE instead of showing

+STATE:INITIALIZED
OK

the result was

ERROR: (0)

and then after I typed agaian AT+STATE the result was the right one.

There is no of course about it. Inadequate power was strong possibility, and 9v batteries are a likely cause of it. Connecting to PC via USB cable can also lead to the same problem, but a lot less likely.

As it is, your problem may simply be bad user input, and you are not doing what you say you are doing.

I submit the correct command is AT+STATE?

And when you got the right result it is probably because you types AT+STATE?, and not what you said you typed. The situation is more or less confirmed by the receipt of ERROR (0), which signifies an AT command error. This is caused by wrong user input, or the signal simply not getting through as a result of the aforementioned sloppy wiring, or inadequate power.