Hi, I'm trying to use an HC-06 module but I'm having a weird behaviour.
Standard version:
char serialValue;
void setup() {
Serial.begin(9600);
while(!Serial){}
}
void loop() {
if (Serial.available() > 0) {
serialValue = Serial.read();
if (serialValue == 'H') {
Serial.println("ON");
} else if (serialValue == 'L') {
Serial.println("OFF");
} else {
Serial.println("NOT VALID");
}
}
}
SoftwareSerial version:
#include <SoftwareSerial.h>
#define BT_RX 10
#define BT_TX 11
SoftwareSerial bluetooth(BT_RX, BT_TX);
char serialValue;
void setup() {
Serial.begin(9600);
while(!Serial){}
bluetooth.begin(9600);
}
void loop() {
if (bluetooth.available() > 0) {
serialValue = bluetooth.read();
if (serialValue == 'H') {
Serial.println("ON");
} else if (serialValue == 'L') {
Serial.println("OFF");
} else {
Serial.println("NOT VALID");
}
}
}
Using both codes, I get the same results.
When I send a command from my mobile, the Serial Monitor shows this (i.e. sending 'H'):
ON
NOT VALID
NOT VALID
If I send any other character than 'H' or 'L', the Serial Monitor shows this:
NOT VALID
NOT VALID
NOT VALID
And when I disconnect from the mobile it shows 'NOT VALID' 19 times.
What I'm I missing here?