I am currently working on a project with an Arduino uno board. Basically, I would like to automatically turn on an LED when the Bluetooth module of my Arduino board is connected to a device and turn it off automatically when it is disconnected. So I would like to insert a LED indicator in my circuit so that I can know when my Bluetooth module is connected to a device or not. I know the project is a bit incomprehensible but rest assured I would be grateful to have some answers to my problem. I already managed to do all the connections (the Bluetooth module and the LED) but I can not find the right program to do this job.I did several searches without answers. If anyone knows the program that can do that it would be nice to comment on it because I'm bad at programming. I know there is a similar LED on the module itself but I would like to create it myself. I thank in advance those who can help me.
Please help me. Thanks.
How will the Arduino know that Bluetooth is connected ?
As far as the Arduino is concerned it is just a serial connection that may or may not be receiving some data.
If you use an HC-05 Bluetooth module, then it must be possible to know when it is connected by using AT commands:
Get the module working state
Command : AT+ STATE?
Respond : + STATEļ¼ OK
Parameter : Param: "INITIALIZED" "READY" "PAIRABLE" "PAIRED" "INQUIRING" "CONNECTING" "CONNECTED""DISCONNECTED" "UNKNOWN"
You can use this to switch your led on when connected
Hi
thanks but I don't think your are right because we can't use AT commands when the bluetooth module is connected to another devices. So I don't think AT commands will help me. But please do you have another idea.
I thank you a lot for your help. But please can you write the programme that permit me to turn on the LED? here I put you my programmme but he does work. please can you find the error?
//for turn on and turn off the LED
if (status == "CONNECTED")
{
digitalWrite(pinLed1, HIGH);
} else {
digitalWrite(pinLed1, LOW);
}
}
void loop()
{
// for the communication with another device
if (mavoieserie.available()) {
Serial.write(mavoieserie.read());
}
if (Serial.available()) {
mavoieserie.write(Serial.read());
}
}