user15341: Hi I am making a sketch and circuit with a HC-05 BT receiver to upload sketches via Bluetooth to my Uno.  This requires giving AT commands from the sketch.  I would like to see the response from the HC-05 but so far I haven't got it to work.  I want to view the response via the standard serial connection and serial monitor.  The commands from the sketch are not being recognized by the HC-05 and I would like to see the HC-05 response to troubleshoot it.
If you have a minute would you mind giving me a tip?  I would greatly appreciate it.  See the ArdProgramModeOn() and Off functions at the end.
Thanks

int ATModePin = 2;  // pin for HC-05 AT comand mode
int HC05powerPin = 3;  // pin for powering HC-05 when high
char btserialrx;  // data through from bt connection
char myChar; // data through serial port connection
#define rxPin 8 // HC-05 bt serial pin
#define txPin 9 // HC-05 bt serial pin

#include <SoftwareSerial.h>
SoftwareSerial btSerial(rxPin, txPin); // RX, TX

void setup() {
  pinMode(ATModePin, OUTPUT);
  pinMode(HC05powerPin, OUTPUT);
  pinMode(5, OUTPUT);
  Serial.begin(9600);   
  btSerial.begin(115200); 
  
  digitalWrite(HC05powerPin, HIGH);
  delay(2000);
  }

void loop() {

  while (btSerial.available()) {
    btserialrx = btSerial.read();
  }

  if(btserialrx == '1'){  // change to upload / reset mode
    Serial.println("switching to upload mode");
    ATModeOn();
    ArdProgramModeOn();
    ATModeOff();
    btserialrx = '0';
  }
  else if (btserialrx == '2'){  // change to normal mode
    Serial.println("switching to normal mode");
    ATModeOn();
    ArdProgramModeOn();
    ATModeOff();
    btserialrx = '0';
  }
}


void ATModeOn(){  // reset HC-05 and change HC-05 to AT Command Mode
  digitalWrite(5, HIGH);
  digitalWrite(ATModePin, HIGH); // AT command mode on upon reset
  delay(2000);
  digitalWrite(HC05powerPin, LOW); // hc-05 off
  delay(2000);
  digitalWrite(HC05powerPin, HIGH); // hc-05 on
  delay(2000);
} 

void ATModeOff(){  // reset HC-05 and return HC-05 to std. operation 
  digitalWrite(5, LOW);
  digitalWrite(ATModePin, LOW); // AT command mode off upon reset
  delay(2000);
  digitalWrite(HC05powerPin, LOW); // hc-05 off
  delay(2000);
  digitalWrite(HC05powerPin, HIGH); // hc-05 on
  delay(2000);
}

void ArdProgramModeOn(){
  btSerial.println("AT");
  delay(1000);
  btSerial.println("AT+POLAR=1,0");  // Arduino reset mode upon HC-05 connection for programming
  delay(1000);
  btSerial.println("AT+POLAR?");  // Arduino reset mode upon HC-05 connection for programming
  delay(2000);
  while (btSerial.available()) {  // Show responses from HC-05
    myChar = btSerial.read();
    Serial.print(myChar);
  }
  delay(4000);
}

void ArdProgramModeOff(){
  btSerial.println("AT");
  delay(1000);
  btSerial.println("AT+POLAR=1,1");  // Arduino normal mode no reset upon HC-05 conection
  delay(1000);
  btSerial.println("AT+POLAR?");  // Arduino reset mode upon HC-05 connection for programming
  delay(2000);
  while (btSerial.available()) {  // Show responses from HC-05
    myChar = btSerial.read();
    Serial.print(myChar);
  }
  delay(4000);
}




user19034: Unless you've manually set the btSerial speed, you need to be at the default for AT commands which is 38400 -> btSerial.begin(38400);
If you want to read regular Serial communication, you'll need to monitor 9600 -> btSerial.begin(9600);
If you are unable to to send commands, I feel as if you wouldn't have changed the default speeds.
I used this link as a reference with my project: Modify The HC-05 Bluetooth Module Defaults Using AT Commands
Lastly, you didn't mention whether or not you soldered a jumper wire to PIN 32 for your ArdProgramOff/On. Another reference for you as well: DIY Arduino Bluetooth Programming Shield
Hope my answer helps! Good luck!

15341: <p>Hi I am making a sketch and circuit with a HC-05 BT receiver to upload sketches via Bluetooth to my Uno.  This requires giving AT commands from the sketch.  I would like to see the response from the HC-05 but so far I haven't got it to work.  I want to view the response via the standard serial connection and serial monitor.  The commands from the sketch are not being recognized by the HC-05 and I would like to see the HC-05 response to troubleshoot it.</p>

<p>If you have a minute would you mind giving me a tip?  I would greatly appreciate it.  See the ArdProgramModeOn() and Off functions at the end.</p>

<p>Thanks</p>

<pre>
int ATModePin = 2; &nbsp;// pin for HC-05 AT comand mode
int HC05powerPin = 3; &nbsp;// pin for powering HC-05 when high
char btserialrx; &nbsp;// data through from bt connection
char myChar; // data through serial port connection
#define rxPin 8 // HC-05 bt serial pin
#define txPin 9 // HC-05 bt serial pin

#include &lt;<b>SoftwareSerial</b>.h&gt;
<b>SoftwareSerial</b> btSerial(rxPin, txPin); // RX, TX

void setup() {
 &nbsp;pinMode(ATModePin, OUTPUT);
 &nbsp;pinMode(HC05powerPin, OUTPUT);
 &nbsp;pinMode(5, OUTPUT);
 &nbsp;<b>Serial</b>.begin(9600); &nbsp;&nbsp;
 &nbsp;btSerial.begin(115200); 
 &nbsp;
 &nbsp;digitalWrite(HC05powerPin, HIGH);
 &nbsp;delay(2000);
 &nbsp;}

void loop() {

 &nbsp;while (btSerial.available()) {
 &nbsp;&nbsp;&nbsp;btserialrx = btSerial.read();
 &nbsp;}

 &nbsp;if(btserialrx == '1'){ &nbsp;// change to upload / reset mode
 &nbsp;&nbsp;&nbsp;<b>Serial</b>.println("switching to upload mode");
 &nbsp;&nbsp;&nbsp;ATModeOn();
 &nbsp;&nbsp;&nbsp;ArdProgramModeOn();
 &nbsp;&nbsp;&nbsp;ATModeOff();
 &nbsp;&nbsp;&nbsp;btserialrx = '0';
 &nbsp;}
 &nbsp;else if (btserialrx == '2'){ &nbsp;// change to normal mode
 &nbsp;&nbsp;&nbsp;<b>Serial</b>.println("switching to normal mode");
 &nbsp;&nbsp;&nbsp;ATModeOn();
 &nbsp;&nbsp;&nbsp;ArdProgramModeOn();
 &nbsp;&nbsp;&nbsp;ATModeOff();
 &nbsp;&nbsp;&nbsp;btserialrx = '0';
 &nbsp;}
}


void ATModeOn(){ &nbsp;// reset HC-05 and change HC-05 to AT Command Mode
 &nbsp;digitalWrite(5, HIGH);
 &nbsp;digitalWrite(ATModePin, HIGH); // AT command mode on upon reset
 &nbsp;delay(2000);
 &nbsp;digitalWrite(HC05powerPin, LOW); // hc-05 off
 &nbsp;delay(2000);
 &nbsp;digitalWrite(HC05powerPin, HIGH); // hc-05 on
 &nbsp;delay(2000);
} 

void ATModeOff(){ &nbsp;// reset HC-05 and return HC-05 to std. operation 
 &nbsp;digitalWrite(5, LOW);
 &nbsp;digitalWrite(ATModePin, LOW); // AT command mode off upon reset
 &nbsp;delay(2000);
 &nbsp;digitalWrite(HC05powerPin, LOW); // hc-05 off
 &nbsp;delay(2000);
 &nbsp;digitalWrite(HC05powerPin, HIGH); // hc-05 on
 &nbsp;delay(2000);
}

void ArdProgramModeOn(){
 &nbsp;btSerial.println("AT");
 &nbsp;delay(1000);
 &nbsp;btSerial.println("AT+POLAR=1,0"); &nbsp;// Arduino reset mode upon HC-05 connection for programming
 &nbsp;delay(1000);
 &nbsp;btSerial.println("AT+POLAR?"); &nbsp;// Arduino reset mode upon HC-05 connection for programming
 &nbsp;delay(2000);
 &nbsp;while (btSerial.available()) { &nbsp;// Show responses from HC-05
 &nbsp;&nbsp;&nbsp;myChar = btSerial.read();
 &nbsp;&nbsp;&nbsp;<b>Serial</b>.print(myChar);
 &nbsp;}
 &nbsp;delay(4000);
}

void ArdProgramModeOff(){
 &nbsp;btSerial.println("AT");
 &nbsp;delay(1000);
 &nbsp;btSerial.println("AT+POLAR=1,1"); &nbsp;// Arduino normal mode no reset upon HC-05 conection
 &nbsp;delay(1000);
 &nbsp;btSerial.println("AT+POLAR?"); &nbsp;// Arduino reset mode upon HC-05 connection for programming
 &nbsp;delay(2000);
 &nbsp;while (btSerial.available()) { &nbsp;// Show responses from HC-05
 &nbsp;&nbsp;&nbsp;myChar = btSerial.read();
 &nbsp;&nbsp;&nbsp;<b>Serial</b>.print(myChar);
 &nbsp;}
 &nbsp;delay(4000);
}


</pre>
 19034: <p>Unless you've manually set the btSerial speed, you need to be at the default for AT commands which is 38400 -> btSerial.begin(38400);</p>

<p>If you want to read regular Serial communication, you'll need to monitor 9600 -> btSerial.begin(9600);</p>

<p>If you are unable to to send commands, I feel as if you wouldn't have changed the default speeds.</p>

<p>I used this link as a reference with my project: <a href="http://www.instructables.com/id/Modify-The-HC-05-Bluetooth-Module-Defaults-Using-A/?ALLSTEPS" rel="nofollow">Modify The HC-05 Bluetooth Module Defaults Using AT Commands</a></p>

<p>Lastly, you didn't mention whether or not you soldered a jumper wire to PIN 32 for your ArdProgramOff/On. Another reference for you as well: <a href="http://makezine.com/projects/diy-arduino-bluetooth-programming-shield/" rel="nofollow">DIY Arduino Bluetooth Programming Shield</a></p>

<p>Hope my answer helps! Good luck!</p>
