Arduino Sketch for detecting BAUD
//name
char NAME[21] = “MYPANEL”;
// 4 num bt code
char PIN[5] = “1234”;
/*
codes for BAUD
1 for 1200 bps
2 2400 bps
3 4800 bps
4 9600 bps
5 19200 bps
6 38400 bps
7 57600 bps
8 115200 bps
9 230400 bps
A 460800 bps
B 921600 bps
C 1382400 bps
*/
char BAUD=’7′;
char response[21]; // char array
int rv=0; // return value
int found=0; // module found
void setup() {
Serial.begin(9600);
Serial.print(“Setting up BT”);
// Search on each of the baud rates
long baud[12] = {1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600, 1382400}; //init it
for(int a = 0; a < 12; a++)
{
Serial.begin(baud[a]);
Serial.write(“AT”); // should get back an “OK”
while(Serial.available() < 0);
Serial.readBytes(response, 2);
if (strncmp(response, “OK”, 2) == 0)
{
Serial.print(“\nIt was at BAUD: “);
Serial.println(baud[a]);
found=1;
break;
}
else
{
Serial.print(“.”);
//Serial.println(baud[a]);
}
}
if (found==0)
{
Serial.println(“\nERROR: Blueooth Module not found!”);
Serial.println(“BT must NOT be enabled, try again”);
while(1);
}
delay(100);
/*
Serial1.write(“AT+VERSION”); // Check the firmware version, because we can
while(Serial1.available() < 0);
Serial1.readBytes(response,2);
if (strncmp(response, “OK”, 2)==0)
{
rv = Serial1.readBytes(response, 20);
response[rv] = 0;
Serial.print(“BT Module Firmware Version: “);
Serial.println(response);
}
else
{
Serial.println(“Error checking BT Version”);
}
delay(100);
Serial1.write(“AT+NAME”); // Set the bluetooth device name
Serial1.write(NAME);
while(Serial1.available() < 0);
Serial1.readBytes(response,9);
if (strncmp(response, “OKsetname”, 9)==0)
{
Serial.print(“Setting Name: “);
Serial.println(NAME);
}
else
{
Serial.println(“Error Setting Bluetooth Name”);
}
delay(100); //give us time to check all BAUD rates until we find the right one
void loop() {
}