Bluetooth Detection. ("bluetooth is working" LED)

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, the light turns on. If you never read the data, Serial.available() will continue to read greater than 0.

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?

Oh, I think i see... are you saying if there is data in Serial.available(), in order to clear it for a later re-check, i need to read it?

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

Most BT modules have a LED on them that blinks when they are not connected and go solid when they are.

Is that it, is that all you want to do?

Just out of curiousity, what BT module do you have?

I couldn't see any reason for these two threads to exist in separate sections of the forum, so I merged them.

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

HazardsMind:
Most BT modules have a LED on them that blinks when they are not connected and go solid when they are.

I have not had much joy with my bluetooth but I think I have seen three signals from the LED

  1. blink about 2hz - I assume power but no action

2 blink about 1 Hz - I assumed this "connected"

  1. continuous red - I assumed this was "talking" but only because I have only seen it once.

Come to think of it, 1. and 2. could be the other way round, as I have never actually sent or received anything that I know about.

The problem is that the code section only runs through the if statement once. So it will check it once, and then move on... unless it's in the loop().

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
}
}

while(Serial.available() != NULL) //making sure there is data to be read

Serial.available() returns an int, not a pointer!

while(Serial.available() > 0)
{
}
    int data = Serial.read(); //storing data as an int
    if (data == -1) /* if -1 is returned, there is no connection

If you call Serial.available() properly, data will NEVER be -1, so this test is unnecessary.

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