Bhargav  Veepuri
Published

Arduino Integration with Accelerometer

Working of accelerometer+gyroscope with Arduino. MPU6050 is the module for accelerometer and gyromscope (combined).

IntermediateFull instructions provided3,834
Arduino Integration with Accelerometer

Things used in this project

Hardware components

GY-521 MPU-6050 3 Axis Gyroscope + Accelerometer Module For Arduino
×1

Story

Read more

Schematics

Arduino connected to MPU6050

Code

Code for MPU6050 with arduino

Arduino
/*
 * Interfacing:
 * 
 * Vin: 3V3
 * GND: Gnd
 * SCL: SCL/AD5
 * SDA: SDA/Ad4
 * INT: D2
 */


#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"

MPU6050 accelgyro;

int16_t ax, ay, az;
int16_t gx, gy, gz;

#define OUTPUT_READABLE_ACCELGYRO



void setup() {
    Wire.begin();   //begin I2c
    Serial.begin(115200);

    // initialize device
    Serial.println("Initializing I2C devices...");
    accelgyro.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");

}

void loop() {

    
    accelgyro.getAcceleration(&ax, &ay, &az);
    accelgyro.getRotation(&gx, &gy, &gz);

    //you can also uncomment the following method to get the raw data
    // accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

        Serial.print("a/g:\t");
        Serial.print(ax); Serial.print("\t");
        Serial.print(ay); Serial.print("\t");
        Serial.print(az); Serial.print("\t");
        Serial.print(gx); Serial.print("\t");
        Serial.print(gy); Serial.print("\t");
        Serial.println(gz);

        delay(1000);      // delay so that we can see the output   
}

Credits

Bhargav  Veepuri
2 projects • 12 followers
Contact

Comments

Please log in or sign up to comment.