I worked this code to receive a single letter of the arduino I can not see any response on the phone text viewer when I want arduino sends the letter 'A' shows me the word 'ON'and if Send 'Z' shows me the word in the text viewer off
Note that the connection between the Android phone arduino been successfully and Android phone sends to arduino but it did not receive
class Ahmed extends Thread {
public void run() {
for (; ; ) {
try {
int bytesAvailable = btSocket.getInputStream().available();
byte []packetBytes= new byte[bytesAvailable];
if (bytesAvailable > 0) {
tb.setText(bytesAvailable+ "ok");
btSocket.getInputStream().read(packetBytes);
for(int i=0; i<bytesAvailable;i++)
{
if (packetBytes[i]==65)
tb.setText("ON");
else if (packetBytes[i] ==90)
tb.setText("off");
}
}
} catch (Exception e) {
}
}
}
}
arduino code
#include<SoftwareSerial.h>
void setup() {
Serial3.begin(9600);
pinMode(13,OUTPUT);
digitalWrite(13,LOW);
}
void loop() {
char x=Serial3.read();
if(x=='A')
{
digitalWrite(13,HIGH);
Serial3.print('A');
}
if(x=='Z')
{digitalWrite(13,LOW);
Serial3.print('Z');
}
}