Issue connecting Arduino Nano using HC-05

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.

Update: I stumbled across this by accident.

My link between the HC-05 and the Nano is perfect. The issue is in my MIT AppInventor.

I was trying to read the HC-05 status using Bluetooth Terminal on the S4. When I entered in AT+STATUS? on the terminal, my serial monitor spat out AT+STATUS?. So data received from the HC-05 is getting put through to the Nano.

So now on to search the issue with AppInventor to the HC-05.

vader7071:

.........

BTSerial.begin(38400);  // HC-05 default speed in AT command more
}




......... Then I connect the phone to the HC-05, and the led blinks slow.

.........The phone is paired to the HC-05 via the phone's OS.

I believe that is where my issue lies, is between the phone and the HC-05, but I am not sure.

It probably isn't, and I suspect the real problem is that you don't know what you are doing, but you think you do, and you are kidding yourself with the results. Essentially, there are two modes of operation for the HC-05 - AT mode, and communications mode. You need to make up your mind which one you want to use because you cannot use both at the same time. If you want to communicate with the phone, no amount of AT commands will fix the problem, but if you get out of AT mode, there is a chance that it might work. Indeed, all this AT stuff is probably an unnecessary dead end, but at least it has proven that your wiring is kosher. Further, a successful connection between Android and Bluetooth means nothing as far as Arduino is concerned.
It would be a good idea to leave the app inventor stuff out of the game until you have Bluetooth working properly.

You might find the following background notes useful.

http://homepages.ihug.com.au/~npyner/Arduino/GUIDE_2BT.pdf
http://homepages.ihug.com.au/~npyner/Arduino/BT_2_WAY.ino

Nick_Pyner:
It probably isn't, and I suspect the real problem is that you don't know what you are doing, but you think you do, and you are kidding yourself with the results. .........

I am fully aware that AT mode is a different mode. I am also fully aware that the HC-05 has only one set of TX/RX pins, meaning communications MUST pass through that path, be it AT or regular comms.

Here is the interesting tidbit of information you can gleen from my second post.

vader7071:
....When I entered in AT+STATUS? on the terminal, my serial monitor spat out AT+STATUS?.....

tells you that when I entered in "AT+STATUS?" in the phone BT terminal app and it got printed out through the serial monitor exactly the same, guess what, comm mode is working. That means the HC-05/Nano setup acted a tunnel between phone and the laptop. But all you saw was "AT" and not the fact that there was a successful data transfer.

The fact that I can access and modify the HC-05 via the AT commands means that the TX/RX paths work. The fact that I can send data from a BT terminal app on my phone to the HC-05, the HC-05 take that data in via a software serial port and pass it on to the Nano which then connects to my laptop via the standard serial port and prints the data sent on the serial monitor on my laptop tells me that the comm mode on the HC-05 is functioning.

What was not shared, because it is not germane to this discussion, is the final result will be (2) separate HC-05/nano setups connecting to one Galaxy S4. But unless I can get one to work, it is pointless to discuss using (2) HC-05s. So I don't have to "make up my mind" about which mode I want to use. I know what mode I want to use. When I want to "personalize" each particular module and name it so I can quickly identify what piece of equipment I am trying connect to, I will use the AT commands to do this. Once I am completed and have the module configured for what I need, then I will return it to standard comm mode.

So I have been able to prove the TX/RX paths work, the HC-05 in comm mode will pair, receive data, transmit that data through the tested TX/RX paths to the Nano on a software configured serial port. I have confirmed the data received on the software serial port from the HC-05 is not corrupted, because I see the same data printed out on the hardware serial port from the Nano to the serial monitor on my laptop. I think I can now say definitively that HC-05 will connect to the phone, receive data, transmit the data to the Nano, and the Nano will receive it. Since I can do this with a BT terminal app, now it is time to try the same test using the App Inventor application. When I try and do the EXACT SAME TEST using the App Inventor application, I don't get the data all the way to my serial monitor. Since the sketch is the exact same sketch (copy all data from received from the HC-05 to the hardware serial port) it is a safe bet there is an issue inside the app in either connecting to the HC-05 or sending data out of the app, via BT from the phone to the HC-05.

So you are SLIGHTLY correct in your assumption that I "don't know what [I'm] are doing" in that this is the first time I am using the HC-05. However, I have been programming for many many years, and I am literate enough to be able to search data sheets, code examples, and see what other successful projects have done to be able to modify the code to do what I need to accomplish. But I guess my over 20 years in electrical and electronics experience doesn't count for much since I am just "kidding myself".