2

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.

2
  • What is pin 8 doing? And why is it set to LOW two times but never set HIGH? Commented Aug 2, 2019 at 6:09
  • have you tried establishing a master-slave setup using I2C? Commented Aug 2, 2019 at 21:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.