I am trying to connect a bluetooth module to my phone to send commands.
It is possible to pair the module (we enter the PIN code and it works) but then impossible to connect to the module, tested on 2 phones and a computer.
I tried with 2 HC-06 modules and an HC-05 and the result is the same.
I tried different code, it doesn't change anything either.
Here is the only wiring I tested for the HC-05, I tested without resistors with the HC-06s.
When I try to use AT commands, the module doesn't even respond. I used this tutorial: Arduino and Bluetooth module HC-05 • AranaCorp
I really don't understand where the problem comes from.
Especially since two years ago, I had followed a video to control a led with an android app and it worked without problems with the HC-06, same wiring, same program.
Could the problem come from the Arduino UNO? Elsewhere ?
Load the following (tested and working on my setup)
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // RX | TX
const long baudRate = 38400;
char c = ' ';
boolean NL = true;
void setup()
{
Serial.begin(9600);
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;
}
}
}
You should be able to enter AT commands and see the responses from the HC05. Sometimes the first time, after a reset, that you send "AT" you will get "error" for a response. Try again and usually you will get "OK".
What app on the phone are you using to connect with the previously paired module?
I would suggest Kai Morich's Serial Bluetooth Terminal
No code is needed. Just give 5v power to the HC05. The app should find the module and you can connect.
The flashing light on the HC05 should change from a rapid flash (about 5 times a second which indicates unconnected) to double quick flash every 2 seconds (indicates connected to another device).
I guess that I am confused. Is the problem that it will not connect to a Bluetooth app on a phone, PC or tablet? Or is it a problem with entering and using AT mode with the Uno? The 2 things are completely different.
I followed the wiring as @groundFungus showed. I set the EN pin to 3.3v.
AT mode seems to be activated: led ~3s off then ~4s on
Unfortunately, the module does not respond when I send AT (tried several times). I do not understand why.
I tried AT commands, just to see if the module at least worked with that. But I only intend to use the module with an application on an android smartphone.
Install the app on your phone, load the code which responds to it on your Arduino, and have a go. The HC05 is just a bridge between the app and the Arduino.
When I set 9600 bauds, when I send the "AT" command, the module does not respond, it does not return "OK". (several attempts).
When I upload the code made to go with the application and therefore, ready to receive commands from an app, I can very well connect the module (led which flashes differently) but the module seems not to understand the commands sent.
Nor should it. Use 38400 when sending AT commands.
It is not Bluetooth's job to understand anything. It merely receives information and passes it on. The understanding is done by Arduino.
This suggests Bluetooth is working, and whatever problems you have lie elsewhere. It could be simply the wrong baud rate. Since you are incapable of using AT mode, make sure the rate is the default 9600 in your Arduino programme.
You might find the following background notes useful.
I was told to try with 9600 baud but I had already done with 38400 baud and the result is the same.
It seems to work better when I use pins 0 and 1 of my arduino. The problem is solved but I don't understand why we can't connect directly in the phone's bluetooth settings.