This is a revival of an older item. Trying to connect HC-05 bluetooth device to Arduino sketch. the circuit is an "Instructables" tutorial on using HC-05 but their forum seems to not respond to this query.
The sketch code:
</>
#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX | TX
char AT_RMAAD_command[9] = {'A', 'T', '+', 'R', 'M', 'A', 'A', 'D', '\0'};
int pin9 = 9;
int pin6 = 6;
void setup() {
pinMode(6, OUTPUT); // pin 6 is for the LED (useless pilot light)
pinMode(9, OUTPUT); // Pin 9 will pull the HC-05 pin 34 ("key" pin)
// switch module to AT mode
digitalWrite(9, HIGH); // Setting pin to HIGH set the key to AT
digitalWrite(6, HIGH); // pilot light
Serial.begin(9600);
Serial.println("Enter AT commands:");
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop() {
/* coment everytHing from orig at-mode out
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available())
Serial.write(BTSerial.read());
// Keep reading from Arduino Serial Monitor and send to HC-05
if (Serial.available())
BTSerial.write(Serial.read());
*/
//
BTSerial.write(AT_RMAAD_command);
Serial.print("\tcommand is ");
Serial.print(AT_RMAAD_command);
Serial.print("\t");
BTSerial.write(Serial.read());
if (BTSerial.available())
Serial.write(BTSerial.read());
Serial.println(BTSerial.read());
delay(10000);
}
</>Preformatted text
The AT command codes are coding into the sketch as string arrays. The are written to the HC-05 but the return code constatnly is -1. The HC-05 is recognised to the extent that the unit's red LED flashses once the VCC is connected. Yes; the sketch does comple and upload. Serial is connected at 9600, while the BTSerial is connected at 38400.
Tom Kane , Vancouver, BC, Vanada