Go Down

Topic: Give a AT command to HC-06 bluetooth module using a Arduino due (Read 1 time) previous topic - next topic

wkdxoghdi

Hello.
I'd like to give a AT command to a HC-06 bluetooth module using the Arduino due.
I connect lines as below.

Arduino DUE       HC-06
5v               >     Vcc
GND             >     GND
TX1             >     RX
RX1             >     TX

And i upload this code to due board. but the HC-06 bluetooth module has no reaction to AT command.

I don't know what's the cause of this.
Please help me. Thank you.

Code: [Select]

void setup() {
  Serial.begin(9600);
  Serial1.begin(9600);
}
void loop() {
 
   if(Serial.available())
      Serial1.write(Serial.read());
     
      if(Serial1.available())
    Serial.write(Serial1.read());
   
     }

Nick_Pyner

I understand a Due is a 3.3v Mega, so try this.

Code: [Select]
/*
 This is for MEGA
 
 It seems internally HC-06 only responds to 9600 anyhow.
 Even if you set the baud rate to 115200 you can "reprogram"
 the sketch again with 9600.
 
 JY-MCU board pins
 RX    - 18   Tx1     orange
 TX    - 19   Rx1     white
 GND   - GND        black
 VCC   - 5v             red
 
 Kudos to marguskohv - he sowed the seed....
Serial monitor is just aide memoire
 */

String command = ""; // Stores response from HC-06

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);       //monitor
  Serial1.begin(9600);      //bluetooth

  Serial.println("AT"); 
  Serial1.print("AT");                  //PING
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
    delay(3);
    char c = Serial1.read();
      command += c;   
    }
  }

  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+NAMEFosters");
  Serial1.print("AT+NAMEFosters");        //CHANGE NAME
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read(); 
    }
  }

  delay(2000);
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+PIN1234");
  Serial1.print("AT+PIN1234");        //CHANGE PASSWORD
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
        delay(3);
      command += (char)Serial1.read(); 
    }
  }

  delay(2000);   
  Serial.println(command);
  command = ""; // No repeats
  Serial.println("AT+BAUD8"); 
  Serial1.print("AT+BAUD8");               //CHANGE SPEED TO 115K
  if (Serial1.available()) {
    while(Serial1.available()) { // While there is more to be read, keep reading.
      command += (char)Serial1.read();   
      delay(2000);
      Serial.println(command);
    }
  }
}

void loop(){
}   //one-shot - nothing here

wkdxoghdi

Thank you.

I got a result like this. (attached image)


Nick_Pyner

I must admit I never looked at the screen when I did it but I guess it gives you what you want. Just edit the programme to change the name, p/w, and/or baud rate to what you want.

Go Up