1

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.

8
  • 1
    Seems, that you have a mismatching baud rate. Is the HC-05 really set to 38400 baud? You can try other baudrates to test
    – chrisl
    May 1, 2019 at 10:03
  • I forgot to mention, if I can access the HC-05 and run AT commands to read settings from the HC-05.
    – Chris Wren
    May 1, 2019 at 11:53
  • @chrisl I checked the baud rate on the HC-05 via the AT commands, but I will double check it tonight. On the serial monitor, I checked every baud rate, but that was just between the Nano and the laptop.
    – Chris Wren
    May 1, 2019 at 11:56
  • @chrisl, I checked the settings. I used AT+UART? and it returned 9600, 0, 0. I have reset it to 34800, 1, 0. I looked up the default settings for the Arduino Nano, and it said default is an 8bit word, 1 stop bit, and 0 parity bits. So I made sure to match this setup. I will test again shortly.
    – Chris Wren
    May 1, 2019 at 17:50
  • 1
    @chrisl, I got the units from ebay. However, I have found out that my hardware and Nano code is correct (I setup a software serial port and used a BT terminal program on my phone to send data from the phone to the HC-05 on the software port on the nano, then the nano dumps the data to the hardware serial port to my serial monitor on my laptop). My issue lies in my App Inventor code somewhere. That is where I am working on now.
    – Chris Wren
    May 5, 2019 at 23:45

1 Answer 1

1

This issue has been resolved. There was an issue with the parity and stop bits.

When setting up for arduino comms, remember, baud rate, 1 stop bit, 0 parity bits.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.