title: How to connect Arduino with MPU6050 and HC-06 blutetooth to MIT App Inventor for both receiving and transceiving data?
body: <p>I have a sketch for a project using arduino, MIT App Inventor, and a hc06 bluetooth module. Basically the arduino is supposed to take data from an accelerometer (MPU6050) and digital PIR sensor, so that if the Pir sensor is a high, and there is no acceleration, then finVal (a temporary variable) would become high. This finVal would then be transmitted to the App, where certain protocols are given during different times where finVal is true. If no button on the app is pressed, and if finVal is true, then out becomes true (which powers speakers and lights on the arduino board). I have the following arduino sketch and mit app inventor blocks and have no idea why it's not working. I would appreciate any help. Thanks!</p>
  
  <pre><code>    int pirInput = A3;
  int accValue;
  int pirValue;
  int finVal;
  String t;
  int out = A0;
  int out1=A1;
  int OldAcX;
  int OldAcY;
  //_bluetooth.enable();
  int state = LOW;
  
  #include "I2Cdev.h"
  #include "MPU6050.h"
  
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
  #include "Wire.h"
  #endif
  
  MPU6050 accelgyro;
  const int MPU = 0x68; // I2C address of the MPU-6050
  int16_t ax, ay, az, gx, gy, gz;
  
  #define OUTPUT_READABLE_ACCELGYRO
  
  
  void setup() {
  #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
    Wire.begin();
  #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
    Fastwire::setup(400, true);
  #endif
    accelgyro.initialize();
    Serial.begin(9600);
    delay(750);
    pinMode(out, OUTPUT);
    pinMode(finVal, OUTPUT);
    pinMode(pirInput, INPUT);
    pinMode(out1,OUTPUT);
    digitalWrite(pirInput, LOW);
    digitalWrite(out, 0);
    digitalWrite(out, LOW);  
    digitalWrite(accValue, LOW);
  }
  
  void loop() {
  
  
    accelgyro.getMotion6(&amp;ax, &amp;ay, &amp;az, &amp;gx, &amp;gy, &amp;gz);
    // #ifdef OUTPUT_READABLE_ACCELGYRO
    // display tab-separated accel/gyro x/y values
    Serial.print("x" + ax); Serial.print("\t");
    Serial.print("y" + ay); Serial.print("\t");
  
  //if motion is changing in any direction more than the allowed tolerance
    if (abs(ax - OldAcX) &lt; 200 &amp;&amp; abs(ay - OldAcY) &lt; 200)
    {
      accValue == HIGH;
    }
    else {
      accValue == LOW;
    }
  
    pirValue = digitalRead(pirInput);
    Serial.println("pir" + pirValue);
    if (pirValue == HIGH &amp;&amp; accValue == HIGH)
    {
      finVal = 1;
    }
    else {
      finVal = 0;
    }
  
  while(Serial.available()){
  t+=(char)Serial.read();
  }
    //turns alarm on/off
    if(t=="on"){
    digitalWrite(out, HIGH);
    digitalWrite(out, 1);
    delay(1000);
    }
  
    else {
      digitalWrite(out, LOW);
      digitalWrite(out, 0);
      delay(1000);
    }
  
  
    if (out &gt;0) //blinks led on external breadboard
    {
      digitalWrite(out1, HIGH);
      delay(1000);
      digitalWrite(out1, LOW);
      delay(1000);
    }
    //new accValues
    OldAcX = ax;
    OldAcY = ay;
  
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/cpzeR.png" rel="nofollow">enter image description here</a><a href="http://i.stack.imgur.com/ok0cN.png" rel="nofollow">enter image description here</a></p>