HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CONNECT

I love my Arduino :x

HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CONNECT

Postby agamgilang » Mon Jun 09, 2014 3:14 pm

Hi everyone, i'm newbie here smiley
i really hope you guys would like to help my project.
I want to set up a simple communication with my tablet and my arduino via bluetooth and the digital buzzer for alarm.

My goal is to simply turn on the digital buzzer when the bluetooth connection is lost, and turn off when bluetooth connection is connected to my tablet.
but i have a problem with my digital buzzer. It's not turning on when the bluetooth connection is lost, how arduino read if bluetooth connection is lost ?
I don't want to send or receive a character between my tablet and arduino (not using recvChar code), just need to connect each other. Just for tracking a case and bag at bus or train using bluetooth as transmission. And when the case or bag is far from the owner, the bluetooth connection is lost and the buzzer will turn on at the bag and case as a alarm.

Here is the code i made CMIIW:
Code: Select all
#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 7
#define TxD 6
int buzzPin = 4;
 
SoftwareSerial blueToothSerial(RxD,TxD);
 
void setup()
{
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  pinMode(buzzPin, OUTPUT);
  setupBlueToothConnection();
 
}
 
void loop()
{
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
    digitalWrite(buzzPin, LOW);
    delay(1);
    }
   if(!blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
    digitalWrite(buzzPin, HIGH);
    delay(1);
    }
    }
}


 
void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=Receiverone\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STPIN=0000\r\n");
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  Serial.println("2 seconds passed");
  blueToothSerial.flush();
}



i really appreciate for any help, thankyou so much guys :)
agamgilang
 
Posts: 2
Joined: Mon Jun 09, 2014 3:08 pm

Re: HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CON

Postby Ian » Fri Jun 13, 2014 10:51 am

Hi and welcome to the forum.

From your Arduino you can send the word

ping

and BTInterface will send back the word

pong

so you can use this to check that you are still connected because if BTInterface doesn't send back the word pong then you know you are no-longer connected.

Have a look at the list of commands in the help section under developer help... another thing you could use is the echo command then you can choose what word BTInterface sends back.
Image
BTInterface

Its a thing that allows you to do things with things.

Please Donate to support further development of BTInterface, thank you
https://www.paypal.com/cgi-bin/webscr?c ... aNonHosted
User avatar
Ian
Site Admin
 
Posts: 267
Joined: Sun Jan 13, 2013 3:24 pm

Re: HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CON

Postby agamgilang » Sun Jun 15, 2014 6:40 pm

is the word could send automatically without typing it myself ?
i just can't find the right Arduino's code for this, would you like to help me to get the right code ? i'll be so thankfull for that :)
agamgilang
 
Posts: 2
Joined: Mon Jun 09, 2014 3:08 pm

Re: HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CON

Postby Ian » Sun Jun 15, 2014 7:18 pm

Hi, well a lot of what you've done in your code looks a bit wrong, sorry.

You might start with the very simple program here: viewtopic.php?f=3&t=7

You'll note that in the loop you build up a string of text and you are left with a string of 1 or more words which you can then do tests on, when you have the correct word or words you can then act on them.
Image
BTInterface

Its a thing that allows you to do things with things.

Please Donate to support further development of BTInterface, thank you
https://www.paypal.com/cgi-bin/webscr?c ... aNonHosted
User avatar
Ian
Site Admin
 
Posts: 267
Joined: Sun Jan 13, 2013 3:24 pm

Re: HOW ARDUINO READ THE BLUETOOTH SHIELD WHEN BLUETOOTH CON

Postby merlin2049er » Wed Aug 06, 2014 6:51 pm

Great, this is exactly what I'm looking to do. Need to read the incoming bluetooth commands and take a look at them (in the terminal).
I'm sending a string of 44 bits with a "\n" terminating bit.
merlin2049er
 
Posts: 66
Joined: Fri Apr 19, 2013 3:30 pm


Return to Arduino

Who is online

Users browsing this forum: No registered users and 2 guests

cron