user040311 user040311 - 6 days ago 5
Android Question

how to connect android phone&ardunio with bluetooth to light led

i want to connect android phone and arduino mega2560 with bluetooth (JY-MCU) to open or close led. its my arduino code:`

include



#define arduinoRx 2
#define arduinoTx 3
int gelen_veri;
int LedCikis = 8 ;

SoftwareSerial bluetooth(arduinoRx,arduinoTx);

void setup()
{
bluetooth.begin(9600);
}

void loop(){
if(bluetooth.available()>0)
{
gelen_veri=bluetooth.read();
switch(gelen_veri)
{
case 'A' :
digitalWrite(LedCikis,HIGH);
break;
case 'K' :
digitalWrite(LedCikis,LOW);
break;
default:
break;
}
}
}`


also it has at the top of the code include< SoftwareSerial.h>. In addition i have android code:

onlight.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
// String msg = "A\n";
// mmOutputStream.write(msg.getBytes()); // transmitter nesnemize 'A' karakterini ilettik.
mmOutputStream.write('A');
} catch (IOException ex) {
Log.e("hata", ex.getMessage());
}
}
});



offlight.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
mmOutputStream.write('K'); // aynı şekilde transmitter nesnemize 'K' karakterini ilettik.
} catch (IOException ex) {}
}
});
}


When i debug my android code ; everything is normal. But it doesnt work. Help me please...

Answer

Do you know blueArduıno? You can try and test your program & bluetooth devıce to understand where is the problem.