   Serial.print("File name: ");
   Serial.println(logFileName); // Debug print the file name
 }
-
-
-/* End code */
+void setupMPU()
+{
+  Wire.begin();
+  Wire.beginTransmission(MPU);
+  Wire.write(0x6B);
+  Wire.write(0);
+  Wire.endTransmission(true);
+}
+void getMPUData()
+{
+  //Read accelerometer data from MPU 6050
+  Wire.beginTransmission(MPU);
+  Wire.write(0x3B); //Read register 0x3B (AcX)
+  Wire.endTransmission(false);
+  Wire.requestFrom(MPU,6,true); //Read 6 register from 0x3B (included)
+  // Each value is 2 register long
+  AcX=Wire.read()<<8|Wire.read();
+  AcY=Wire.read()<<8|Wire.read();
+  AcZ=Wire.read()<<8|Wire.read();
+  //Colculate angles X and Y using the tangent formulae
+  Acc[1] = atan(-1*(AcX/A_R)/sqrt(pow((AcY/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
+  Acc[0] = atan((AcY/A_R)/sqrt(pow((AcX/A_R),2) + pow((AcZ/A_R),2)))*RAD_TO_DEG;
+  //Read gyroscope data from MPU 6050
+  Wire.beginTransmission(MPU);
+  Wire.write(0x43); //Read register 0x43 (GyX)
+  Wire.endTransmission(false);
+  Wire.requestFrom(MPU,4,true); //Read 4 registers from 0x43 (included)
+  GyX=Wire.read()<<8|Wire.read();
+  GyY=Wire.read()<<8|Wire.read();
+  //Apply conversion ratio for Gyro
+  Gy[0] = GyX/G_R;
+  Gy[1] = GyY/G_R;
+  //Apply complementary filter
+  Angle[0] = 0.98 *(Angle[0]+Gy[0]*0.010) + 0.02*Acc[0];
+  Angle[1] = 0.98 *(Angle[1]+Gy[1]*0.010) + 0.02*Acc[1];
+  delay(10); //Delta is 10 milliseconds
+}
+/* End code */
    Serial.print((int)GPS.fix);
    Serial.print(',');
    Serial.print((int)GPS.fixquality);
    Serial.println();
  }

  File logFile = SD.open(logFileName, FILE_WRITE);
  if (logFile)
  {

#include <SoftwareSerial.h>
#include <SD.h>
#include <avr/sleep.h>
#include <Wire.h>
////////////////////////////
// MPU 6050 related stuff //
////////////////////////////
// MPU 6050 I2C address
#define MPU 0x68
//Conversion ratios for accelerometer and gyroscope
#define A_R 16384.0
#define G_R 131.0
//Radion to degree conversion 180/PI
#define RAD_A_DEG = 57.295779
//MPU 6050 outputs 16bit integer raw values
int16_t AcX, AcY, AcZ, GyX, GyY, GyZ;
float Acc[2];
float Gy[2];
float Angle[2];
///////////////////////
// GPS related stuff //
///////////////////////
SoftwareSerial mySerial(8, 7);
Adafruit_GPS GPS(&mySerial);
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console
// Set to 'true' if you want to debug and listen to the raw GPS sentences
#define GPSECHO  true
/* set to true to only log to SD when GPS has a fix, for debugging, keep it false */
#define LOG_FIXONLY false
void useInterrupt(boolean); // Func prototype keeps Arduino 0023 happy
// Set the pins used
#define chipSelect 10
#define ledPin 13
////////////////////////////
// Log File related stuff //
////////////////////////////
#define LOG_FILE_PREFIX "gpslog"
#define MAX_LOG_FILES 100
#define LOG_FILE_SUFFIX "csv"
char logFileName[13];
#define LOG_COLUMN_COUNT 14
char * log_col_names[LOG_COLUMN_COUNT] = {
  "longitude",
  "latitude",
