Hey all i am wondering what is wrong with my code below. I have 2 issues.
First issue I am checking if c equals "hi" and if it does then display said hi. I currently see the output of c when it hits the Serial.println(c); but never see the said hi even though Serial.println(c); does say "said hi".
Second issue is that when i startup the arduino i am sending the AT command AT using bluetooth.println("AT"); // just a check but all it seems to do is display AT on the phone instead of OK as it should.
#include <SoftwareSerial.h>
SoftwareSerial bluetooth(8,9); // RX, TX
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("PC Side Connected");
bluetooth.begin(9600);
while (!bluetooth) {
; // wait for serial port to connect. Needed for native USB port only
}
bluetooth.println("Bluetooth Side Connected");
bluetooth.println("AT"); // just a check
}
void loop() { // run over and over
String c;
if (bluetooth.available()) {
//What is sent back from the BT module
c = bluetooth.readStringUntil('\n');
delay(10);
Serial.println(c);
if (c.equals('hi')) {
Serial.println("said hi");
}
}
if (Serial.available()) {
//Send back data to Bluetooth module
bluetooth.write(Serial.read());
}
}