I want to connect an Android phone and an Arduino Mega 2560 with bluetooth (JY-MCU) to open or close LED. Here's my Arduino code:
#include <SoftwareSerial.h>
#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;
}
}
}
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 doesn't work. Help me please.