Go Down

Topic: blink leds using at commands of hc05 bluetooth module and arduino  (Read 74 times) previous topic - next topic

Achsah

#include <SoftwareSerial.h>
char str[30];
int flag=0,num;
char c9,s1;
char sone[40]="+INQ:825:25:8ED53D,5A020C,7FFF";
//sone =String("+INQ:1007:B6:967C33,5A020C,7FFF");
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
  pinMode(9, OUTPUT);  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);
  pinMode(LED_BUILTIN, OUTPUT);// HC-05 default speed in AT command more
}
void loop()
 {
  if (flag==0)
{
  BTSerial.println("at+init");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c=BTSerial.read();
  Serial.write(c);
  }
  BTSerial.println("at+cmode=1");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c2=BTSerial.read();
  Serial.write(c2);
  }
 BTSerial.println("at+role=1");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c3=BTSerial.read();
  Serial.write(c3);
}
BTSerial.println("at+iac?");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c4=BTSerial.read();
  Serial.write(c4);
  }
BTSerial.println("at+class=0");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c5=BTSerial.read();
  Serial.write(c5);
}
BTSerial.println("at+inqm?");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c6=BTSerial.read();
  Serial.write(c6);
}
BTSerial.println("at+inq");
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c7=BTSerial.read();
  Serial.write(c7);
  }
  delay(100);
   BTSerial.println("at+inqc");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c8=BTSerial.read();
  Serial.write(c8);
}
BTSerial.println("at+inq");
  delay(100);
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c9=BTSerial.read();
  Serial.write(c9);
  }
 delay(100);
    BTSerial.println("at+pswd?");
  // From HC-05 and send to Arduino Serial Monitor
 if (BTSerial.available())
  while (BTSerial.available())
  {
   char c14=BTSerial.read();
  Serial.write(c14);
    }
    delay(100);
    BTSerial.println("at+pair=34E9,11,B47C36,20");
 
  // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c12=BTSerial.read();
  Serial.write(c12);
 BTSerial.println("at+pair=825,25,8ED53D,20");
   // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c13=BTSerial.read();
  Serial.write(c13);
  delay(100);
 
 
  {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);
  }
  }
  }

  for (;;);
 
   BTSerial.println("at+state?");
   // From HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
  while (BTSerial.available())
  {
   char c20=BTSerial.read();
  Serial.write(c20);
  delay(100); 
  }
 }
 }
 
 

Go Up