Pages: [1]   Go Down
Author Topic: Bluetooth Detection. ("bluetooth is working" LED)  (Read 574 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: December 04, 2012, 08:32:08 pm by millencolin543 » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 84
Posts: 3417
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25752
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have arduino BT  http://www.arduino.cc/en/Main/ArduinoBoardBluetooth <---- 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
Logged

Dee Why NSW
Offline Offline
Full Member
***
Karma: 5
Posts: 206
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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"

3. 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.
Logged

Scottsdale
Offline Offline
Newbie
*
Karma: 0
Posts: 27
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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().
Logged

RadarProject - Arduino Autopilot for RC http://radarproject.wordpress.com/

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
  while(Serial.available() != NULL) //making sure there is data to be read
Serial.available() returns an int, not a pointer!

Code:
while(Serial.available() > 0)
{
}

Code:
    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.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 24
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: