I am trying send data from an Arduino to an android device with bluetooth. I want to send a date y and when it arrives, turn on a led, but when I send the data nothing happened. This is my code for Arduino (I use the bluetooth module hc-05)
char entrada;
void setup()
{
pinMode(8,OUTPUT);
Serial.begin(9600);
digitalWrite(8,LOW);
}
void loop()
{
if(Serial.available()>0)
{
entrada=Serial.read();
if(entrada=='1')
{
digitalWrite(8,LOW);
Serial.println("1");
}
}
And in the side of android i have this codec with my handler and thread for inputstream and outputstream
public void run()
{
byte[] espera=new byte [256];
int esperaalmacen;
while (true) {
try {
esperaalmacen=entradadatos.read(espera);
mhandler.obtainMessage(MENSAJELEYENDO,esperaalmacen,-1,espera).sendToTarget();
}catch (IOException e){}
}
And in my activity main I have:
@Override
public void handleMessage(Message msg)
{
super.handleMessage(msg);
switch (msg.what)
{
case CONECTADO:
//ManejarDatos msjre = new ManejarDatos((BluetoothSocket)msg.obj);
msjre = new ManejarDatos((BluetoothSocket)msg.obj);
break;
case MENSAJELEYENDO:
byte[] readBuf = (byte[])msg.obj;
String string = new String(readBuf);
Toast.makeText(getApplicationContext(), string, Toast.LENGTH_LONG).show();
}
}
My modulo I have configured as slave.