Here is my setup:
Arduino Nano 168
HC-05
Samsung Galaxy S4
The project is this. I'm trying to connect the nano to the S4 via bluetooth. I am following Controlling Nano using BT for the instructions. I have thinned down the code to extreme basics and added a pass through to monitor.
Here is my code from the Nano:
#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); // HC-05 default speed in AT command more
}
void loop(){
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()) {
Serial.write(BTSerial.read());
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;
}
}
What I see this doing, is when I connect the phone to the HC-05, any data received from the HC-05 will get put to the Nano, and the data will get pushed out the serial port to my monitor.
I can program the HC-05 via the AT commands, no problem. I use basically the same code as above, and I can setup the H-05.
The HC-05 settings are:
Rate: 38400, 1 stop, 0 parity.
Mode: Slave
VERSION:3.0-20170601
I use the MIT Appinventor to create the app on the S4. It is setup to connect to the HC-05, and when I click a button, the app transmits a "1" via bluetooth to the Nano.
Ok, all of that to tell you this.
I connect everything up, and at initial power on, the led on the HC-05 is blinking fast. Then I connect the phone to the HC-05, and the led blinks slow.
When I connect my laptop to the Nano, and connect the phone to the HC-05, I do get data on the serial monitor. When I click "connect" on the app, the serial monitor prints:
+DISC:SUCCESS
OK
But when I click "button" on the app (which should send a "1" to the HC-05", nothing. Nada. Zip. Not even a new line. But if I click "connect" again, the nano prints out the same lines.
I am reading that as "Disconnect: Success", but that is not what I want (obviously). The phone is paired to the HC-05 via the phone's OS.
So my question/trouble is why is this not working? I know a little broad for a question. What do I need to look at to try and resolve this? I can see that I am able to transmit to and from the HC-05 via the Nano (by being able to program the HC-05 via the AT commands). But for some reason, it looks like the data from the phone is not going through the HC-05 to get to the Nano. I believe that is where my issue lies, is between the phone and the HC-05, but I am not sure.
Thank you in advance for your help.