Bluetooth Communication
hello new here
i little experienced programming , elctronics.
i hope can me project.
i want set simple communication tablet , arduino via bluetooth.
it working far, tablet finds blutooth module can send , recieve commands , answeres , arduino.
my goal turn on , off led string commands.
when send commands via usb-serial arduino working well, when send same command via bluetooth code not working.
here code:
when send commande via usb serial output:
arduino revieved command: .
arduino executing command: .
command executed
arduino revieved command: -
arduino executing command: -
command executed
i same output when send command via bluetooth led doesnt turn on.
i happy every suggestion
i little experienced programming , elctronics.
i hope can me project.
i want set simple communication tablet , arduino via bluetooth.
it working far, tablet finds blutooth module can send , recieve commands , answeres , arduino.
my goal turn on , off led string commands.
when send commands via usb-serial arduino working well, when send same command via bluetooth code not working.
here code:
code: [select]
string command;
char input;
boolean led;
// variable receive data serial port
int ledpin = 8; // led connected pin 48 (on-board led)
void setup() {
pinmode(ledpin, output); // pin 48 (on-board led) output
serial.begin(9600); // start serial communication @ 9600bps
}
void loop() {
readcommand();
if(command.equals(".")){
led=true;
}
else if(command.equals("-")){
led=false;
}
serial.print("arduino executing command: ");
serial.println(command);
if(led==true){
digitalwrite(ledpin,high);
}
else if(led==false){
digitalwrite(ledpin,low);
}
serial.println("command executed");
}
void readcommand(){
command="";
while(serial.available()==0){}
serial.flush();
command="";
while(serial.available()==0){}
while(serial.available()>0){
input=serial.read();
command+=string(input);
delay(1);
}
serial.print("arduino revieved command: ");
serial.println(command);
}
when send commande via usb serial output:
arduino revieved command: .
arduino executing command: .
command executed
arduino revieved command: -
arduino executing command: -
command executed
i same output when send command via bluetooth led doesnt turn on.
i happy every suggestion
ok solved problem,
i used integer based commands instead of string based.
kann tell me why stringcomparison operiation wrong in code above?
i used integer based commands instead of string based.
kann tell me why stringcomparison operiation wrong in code above?
code: [select]
if(command.equals("comparestring"){
//do somthing
}
Arduino Forum > Using Arduino > Project Guidance > Bluetooth Communication
arduino
Comments
Post a Comment