Quantcast
Channel: Seeedstudio Forum
Viewing all articles
Browse latest Browse all 6612

Bluetooth Shield + Arduino Uno not discoverable!

$
0
0
For those that are having problems getting BTShield to work properly This is what I have done to get it to function as wanted....
Code:#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED  1
SoftwareSerial blueToothSerial(RxD,TxD);
int led = 13;
void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT); // led onboard arduino uno pin 13
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection(); 
}

void loop()
{
  char recvChar; 
  if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
    recvChar = blueToothSerial.read();
    Serial.print(recvChar);
  }
  if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
    recvChar  = Serial.read();
    blueToothSerial.print(recvChar);
  } 
  // ADD Code HERE:
  if (recvChar == '0' ) // if input from serial is = 0
  {
    digitalWrite(led, LOW); // turn off led on arduino uno pin 13
    delay(45);
  }
  if (recvChar == '1') // if input from serial is = 1
  {
    digitalWrite(led, HIGH); // turn on led on arduino uno pin 13
    delay(45);
  }

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to 38400 ..default baud rate 38400 (btShield plays nicely at default baud rate)
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBT\r\n"); //set the bluetooth name as "SeeedBT"
  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
  blueToothSerial.print("\r\n+STPIN=0000\r\n");//set pin to 0000
  blueToothSerial.print("\r\n+RTPIN=0000\r\n");// ask to input pin
  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.
  blueToothSerial.flush();
}







All I did was attach BT shield to arduino then upload code unplug arduino wait 5 seconds replug the arduino and wait for red and green led to blink alternatively...Normally takes 3-5 secs to initiate.... Once leds are blinking then you should b able to connect with other device to seeedBT..... for (windows 7) i found that once you upload code unplug arduino and replug arduino back in that if you open the serial monitor in arduino ide windows will pop up a alert box saying (A bluetooth device is trying to connect click here to allow) once you click the alert it will ask for pincode, which is 0000 . Once entered all should be well in BT land and you should be able to enter 0 or 1 in serial monitor and watch led onboard arduino turn on/off.....enjoy

Statistics : Posted by reebbhaa • on Mon Apr 22, 2013 3:47 am • Replies 15 • Views 2029

Viewing all articles
Browse latest Browse all 6612

Trending Articles