Hi all.
I recently purchased an HC-06 module and have been getting quite comfortable with the device lately. Currently I have changed the name pin and a few other things using the command mode.
However, I am looking to have the device connect automatically when my phone is paired.
Currently, when I pair the device, it goes into a connected mode where the LED on PIO8 blinks slower than when it is not connected. When I turn off bluetooth on my phone the LED blinks the same. Only when I repower the BT module does the LED blink fast again, and doesn't until I unpair and repair with the device. PIO9 does not change state (it is always low) unlike the datasheet that states it should change states when connected or not connected.
When I use a terminal program on my phone, it can connect to the device after power on without a re-pair and put the BT device back into a connected mode.
How can I make it so that when I am paired, and the BT on my phone is turned off- the device is in the nonconnected mode.
When the BT on my phone is turned on- the device is in the connected mode.
I am looking to have two distinguished states- connected and disconnected, without the use of a terminal program or other app.
The code I am using is:
#include <SoftwareSerial.h>
int bluetoothTx = 2; // TX-O pin of bluetooth mate, Arduino D2
int bluetoothRx = 3; // RX-I pin of bluetooth mate, Arduino D3
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
Serial.begin(9600); // Begin the serial monitor at 9600bps
bluetooth.begin(9600);
}
void loop()
{
if(bluetooth.available()) // If the bluetooth sent any characters
{
// Send any characters the bluetooth prints to the serial monitor
Serial.print((char)bluetooth.read());
}
if(Serial.available()) // If stuff was typed in the serial monitor
{
// Send any characters the Serial monitor prints to the bluetooth
bluetooth.print((char)Serial.read());
}
}