Hc 05 not recieving data

I am using an Hc 05 bluetooth module to control pin 13 with its built in led. I need help because I can't make the Hc 05 recieve data. I also tried using SoftwareSerial.h but it still does not work. I am using mit app inventor to send '1' or '2'. Please help.

int data;
void setup(){
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop(){
if(Serial.available()>0){
data = Serial.read()
}

switch(data){

case '1':
digitalWrite(13, HIGH);
break;

case'2':
digitalWrite(13, LOW);
break;

default:
break;
}
}

Thanks.

Much better to use SoftwareSerial because that will allow you to send debug messages to the Serial Monitor using Serial.

Print the values that the Arduino receives with the HC05. Maybe they are not what you think they are.

...R

Use a standard Bluetooth terminal, not something concocted with app inventor

Nick Pyner What do you mean? Robin2 I did what you are saying I am getting values like 51, 52, 53.

kyletheflipper:
Robin2 I did what you are saying I am getting values like 51, 52, 53.

Please post your program (always).

Those numbers look like the ASCII values for '3' '4' and '5'

...R

The Serial Bluetooth terminal app.

Groundfungus thanks. Robin I guess yes you are correct because 1 is 49. So what do I have to do to make the arduino execute the program whenever it recieves a specific data like this.

#include<SoftwareSerial.h>
SoftwareSerial myserial(2,3);
int data;

void setup() {
pinMode(13,OUTPUT);
myserial.begin(9600);

void loop() {
if(myerial.available()>0){
data = myserial.read();
Serial.print(data);
}
switch(data){

case '1':
digitalWrite(13, HIGH);
break;

case '2':
digitalWrite(13, LOW);
break;

default:
break;
}
}

kyletheflipper:
So what do I have to do to make the arduino execute the program whenever it recieves a specific data like this.

Define the variable data as char rather than int

...R

Then should I still use the character or the ASCII?

kyletheflipper:
Nick Pyner What do you mean?

I mean exactly what I said. Who would ever know what you have been doing with app inventor? If you use a proper terminal app, everybody can assume it is kosher. Your Arduino code is not familiar to me but it may be entirely kosher too, but there is nothing to suggest your app is. If you want to re-invent the wheel, do it after you have proven Arduino is OK. See reply #5.

And on reflection, this

void loop() {
if(myerial.available()>0){

doesn't look too clever......

kyletheflipper:
Then should I still use the character or the ASCII?

I don't understand what was in your mind when you asked that question.

Did you try what I suggested? What was the result?

...R

Oh I see @Nick Pryner. I have a bluetooth terminal app but it still shows the same result as the app that I made. Thanks.

@Robin2 Its night time right now in my country, I will try to redo the code tomorrow. Anyways what I am trying to ask is should it be:

case '1':
//execute program
break;

Or

Case "49": //ASCII of 1
//execute program
break;

Should I use the ASCII or still '1'.

If you don't get my question its ok. I will try it tomorrow. Thanks

kyletheflipper:
I have a bluetooth terminal app but it still shows the same result as the app that I made.

That is still not an excuse for using your app. All you have proven is that it might be innocent, not that it actually is. Having said that, the switch case code is not quite as weird as I thought, and it may be that your only problem is the mistake I pointed to. I would not have thought your code would compile with something like that going on.

kyletheflipper:
Anyways what I am trying to ask is should it be:

case '1':
//execute program
break;

Or

Case "49": //ASCII of 1
//execute program
break;

It could be either of these

case '1':
// or
case 49: // with no quotes

Using '1' probably makes the code easier to follow

...R

Good news! I was able to make the motor work as I wanted it to but I observed the voltage drop. I was shocked to see that from 9 volts power supply only 4 volt was powering my motor.

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