Hey guys, this is my first project on arduino and I'm having a bit of trouble with this section of the project:
I am using Arduino BT and essentially what I want to do is turn on an LED when the Arduino is "paired" with my pc, and turn the LED off when it is no longer paired.
I've tried:
"if (Serial.available()!=0)
{
digitalWrite(ledBlue, HIGH);
}
else
digitalWrite(ledBlue, LOW);"
and ive also tried it with Serial.read();
I can get the light to turn on, but not turn off. Whenever I load the program, the LED will turn on and then I remove the dongle to see if it will turn the LED off but it still is lit up.
Basically, I don't care whether or not the arduino is receiving data from my PC. I just need to know how to detect whether a wireless connection is made, or "paired", so that I can turn the LED on or off.
Any suggestions?? Thanks so much guys, you have no idea how grateful I am for advice right now. Its been a week straight trying to figure this thing out
Once there is serial data to read, does that mean that the Arduino and PC are paired? So if they are not paired Serial.available() will return 0? or will it return NULL? and how can i get it to turn off? Is there a way to re-check if there is data to read every time the loop runs? Because perhaps there is data to read one second, and once I remove the bluetooth dongle, there is no more connection/pairing, so there shouldn't be any data to read once it is rechecked and the light will turn off. How to achieve this?
Hey guys, this is my first project on arduino and I'm having a bit of trouble with this section of the project:
I am using Arduino BT and essentially what I want to do is turn on an LED when the Arduino is "paired" with my pc, and turn the LED off when it is no longer paired.
Any suggestions?? Thanks so much guys, you have no idea how grateful I am for advice right now. Its been a week straight trying to figure this thing out
I have arduino BT docs.cc <---- it says it is the bluegiga WT11. All i want to do is have the LED turn on when the arduino and pc pair. But i am completely lost here. any help would be greatly appreciated
I'll send you what I have so far, but its definitely not working the way I want. I know the bluetooth chip on the arduino BT can definitely detect the presence of a bluetooth signal or else it wouldn't work. But how can I access that information? Do i have to use some clever algorithm for this or is there a better way??
int ledBT = 4;
void setup() {
// initialize the digital pin as an output
Serial.begin(115200);
pinMode(ledBT, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
Serial.println(100); //send packets of data to be detected
while(Serial.available() != NULL) //making sure there is data to be read
{
int data = Serial.read(); //storing data as an int
if (data == -1) /* if -1 is returned, there is no connection
(Serial.read() returns -1 instead of NULL */
{
digitalWrite(ledBT, LOW); //turn off "bluetooth is working LED"
}
else
{
digitalWrite(ledBT, HIGH); //turn on "bluetooth is working" LED
}
}
Hmm. I see your point, I've just been trying a lot of different things. From what I've gathered, I can get the LED to turn only while I'm sending data to the Arduino through the monitor, like typing in the number 10000 and hitting enter. But once the data has finished sending, the light will turn off again. Is the only way to do this just so continuously send data? Is that even possible? I know that the bluetooth module built into the Arduino BT recognizes if there is pairing or not. Is there a way to access this knowledge? Some mystical function that involves the virtual com port? like "COM3.isPaired(COM4)" there has to be an easier way to do this. I am just a young grasshopper, show me the ways