I have been looking through StackExchange, and searching on the web and cannot find an answer to my issue.
Setup: Arduino Nano 168 HC-05 VERSION:3.0-20170601
I am trying to connect my Android phone to my Nano to control an output. I have found tons of varying examples, but they all basically boil down to MIT App Inventor to create app to connect via BT and send data to the Nano to control.
After many attempts with no results, I attempted the following:
#include <SoftwareSerial.h>
int light=8;
int Received=0;
int light_state =0;
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup(){
Serial.begin(38400);
pinMode(light,OUTPUT);
BTSerial.begin(38400);
}
void loop(){
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()) {
Serial.write(BTSerial.read());
}
if(BTSerial.available()>0) {
Received = BTSerial.read();
}
if (light_state == 0 && Received == '1') {
digitalWrite(light,HIGH);
light_state=1;
Received=0;
}
if (light_state ==1 && Received == '1') {
digitalWrite(light,LOW);
light_state=0;
Received=0;
}
}
So, when I run the MIT app on my phone to connect to the HC-05 the status LED on the HC-05 changes. Before I connect, the status LED flashes fast. After I connect, it flashes slow.
I have the serial monitor open on my laptop monitoring the Nano. The HC-05 connects via pins 10 & 11. When the phone connects to the HC-05, the data printed on the serial monitor is garbage.
⸮x⸮x⸮⸮x⸮x⸮x⸮⸮xxxxxx⸮x⸮⸮xx⸮⸮xxx⸮⸮
That is what I get.
The app is set to transmit a "1" via BT to the Nano. When I press the button to send the 1, no data comes across. But every time I pick the HC-05 and tell the app to connect to the unit, I get that same string of data above.
Thank you in advance for your help.