I have the following code in which if I write some AT commands(AT, AT+VERSION etc.) in the Serial Monitor they are being executed. If I send them with my phone through that bluetooth, nothing is executed. I want the board to execute the commands received through bluetooth as well. How can I do that ?
#include <SoftwareSerial.h>
SoftwareSerial mySerial(4, 2); // RX, TX
String command = ""; // Stores response of the HC-06 Bluetooth device
void setup() {
// Open serial communications:
Serial.begin(9600);
Serial.println("Type AT commands!");
// The HC-06 defaults to 9600 according to the datasheet.
mySerial.begin(9600);
}
void loop() {
// Read device output if available.
if (mySerial.available()) {
while(mySerial.available()) { // While there is more to be read, keep reading.
command += (char)mySerial.read();
}
Serial.println(command);
command = ""; // No repeats
}
// Read user input if available.
if (Serial.available()){
delay(10); // The delay is necessary to get this working!
mySerial.write(Serial.read());
}
}