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;
}
}
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;
}
}
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.
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.
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.