[solved]Bluetooth Problems Serial

I am trying to connect Bluetooth to my Arduino, I connected the hc-05 and downloaded app on my phone. The problem I am having is when I don't use the Serial.begin(9600) I can see the characters in my serial monitor when i use the app on my phone. But when I use Serial.begin(9600) I don't see the characters in my serial monitor. In both, the code still doesn't do what he meant to.
The code:

char data = 0;
void setup() 
{
//Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
Serial.print(data);
Serial.print("\n");
if(data == '1')
digitalWrite(13, HIGH);  
else if(data == '0')      
digitalWrite(13, LOW);   
}                            

}

I connected the hc-05 and downloaded app on my phone.

explain how you wired things up

we have no clue about which app you are talking about... provide lots of information to help us help you...

5v-5v
GND-gnd
tx-Tx(digtal pin 1)
rx-rz(digtal pin 0)
im using this app-https://play.google.com/store/apps/details?id=de.kai_morich.serial_bluetooth_terminal&hl=en&gl=US

So your BT module is on the Serial port.

In a nutshell, You can either use BT or the Serial monitor, but not both at the same time.

You could use Software Serial to install the HC-05 on pin 2 and 3 for example and then Serial would remain available for debugging and uploading the code.

There are lots of examples on line for this

I tried this code and couple others and its still doesnt woek i dont get any input:

#include <SoftwareSerial.h> 
SoftwareSerial MyBlue(2, 3); // RX | TX 
int flag = 0; 
int LED = 13; 
void setup() 
{   
 Serial.begin(9600); 
 MyBlue.begin(9600); 
 pinMode(LED, OUTPUT); 
 Serial.println("Ready to connect\nDefualt password is 1234 or 000"); 
} 
void loop() 
{ 
 if (MyBlue.available()) 
   flag = MyBlue.read(); 
   Serial.println(flag);
 if (flag == 1) 
 { 
   digitalWrite(LED, HIGH); 
 } 
 else if (flag == 0) 
 { 
   digitalWrite(LED, HIGH); 
 } 
}  

You are probably missing {} in your first if

Its not spamming 0 anymore but it still doesnt get any input.

Post the new code

Are you sure you paired the unit?
Are you sure if the baud rate ?
Did you wire Rx and Tx to the right pins ?

#include <SoftwareSerial.h> 
SoftwareSerial MyBlue(2, 3); // RX | TX 
int flag = 0; 
int LED = 13; 
void setup() 
{   
 Serial.begin(9600); 
 MyBlue.begin(9600); 
 pinMode(LED, OUTPUT); 
 Serial.println("Ready to connect\nDefualt password is 1234 or 000"); 
} 
void loop() 
{ 
 if (MyBlue.available()){
   flag = MyBlue.read(); 
   Serial.println(flag);
 }
 if (flag == 1) 
 { 
   digitalWrite(LED, HIGH); 
 } 
 else if (flag == 0) 
 { 
   digitalWrite(LED, HIGH); 
 } 
}  

I am on the right baud rate 9600
I am paired with my phone
rx is connected to digtal pin 2
tx is connected to digtal pin 3

So I switched between my rx and tx and now when i send i get 3 sets of numbers
if i send a i get
97
13
10
if i send 1 i get:
49
13
10
I get the ascii of each thing but what are the 13 and 10 and how do i make it not as ascii

So final update I hope: I got it working i switched the rx and the tx so that rx is pin 3 and tx pin 2. and added in the code where it will make the ascii back to char.Thank you for the help

#include <SoftwareSerial.h> 
SoftwareSerial MyBlue(2, 3); // RX | TX 
int flag = 0; 
int LED = 13; 
char character;
void setup() 
{   
 Serial.begin(9600); 
 MyBlue.begin(9600); 
 pinMode(LED, OUTPUT); 
 Serial.println("Ready to connect\nDefualt password is 1234 or 000"); 
} 
void loop() 
{ 
 if (MyBlue.available()){
   flag = MyBlue.read(); 
   character = char(flag);
   Serial.println(character);
 }
 if (character == '1') 
 { 
   digitalWrite(LED, HIGH); 
 } 
 else if (character == '0') 
 { 
   digitalWrite(LED, LOW); 
 } 
}  

CarriageReturn and LineFeed; your Bluetooth app more than likely sends them (similar to what Serial.println will do).

That’s wrong - change it

Oops - sorry missed the following discussion

Seems you are all set you get the ascii code and a trailing CR and LF

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.