[size=150]Connecting Bluetooth Shield with Arduino Mega[/size]
1 Modify your program:
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 10
#define TxD 11
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD,TxD);
void setup()
{
Serial.begin(38400);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
}
void loop()
{
char recvChar;
while(1){
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);
}
}
}
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=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
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.
blueToothSerial.flush();
}
2 Jumper wires:
Please connect digital 6(7) to digital 10(11) via jumper wire.
Note:Don’t forget to turn the PIO1 to A1 position.
If you have set a high baud rate to Bluetooth shield, such as 230400, but Arduino IDE can support a high baud rate, so you need to reset a lower baud rate to Bluetooth via a USB to Serial device, such as UartSBee(seeedstudio.com/depot/UartSB … Path=63_66)
Don’t forget turn the switch of UartSBee to 3.3v position.
Then open a serial tool,
Setting: 230400,8,N,1.
Send a Blank command first and then send +STBD=38400. (Similar information please refer to this topic : viewtopic.php?f=18&t=4161)