Arduino link GY-521 (mpu6050) Module

Source: Internet
Author: User
This example uses the 'lilypad 'link mpu6050 module, 'arduino uno' as the USB download device, the specific connection method please move:

# How to connect lilypad to mpu6050
! [Lilypad] ( "Lilypad ")

The pins corresponding to Lilypad and mpu6050:

* + *-> * VCC *

*-> * Gnd *

* A4 *-> * SDA *

* A5 *-> * SCL *

# Download the i2cdev Library


After decompression, add the code in the Arduino folder to the path of the class library of the Arduino IDE.

Take Ubuntu as an example:

CP-RF */usr/share/Arduino/Libraries

# Test Program

# Include "wire. H"
# Include "i2cdev. H"
# Include "mpu6050.h"
Mpu6050 accelgyro;

Int16_t ax, ay, AZ;
Int16_t GX, Gy, GZ;

// The default value of the onboard led pin is 13.
Int led_pin = 13;
// Led status information
Bool blinkstate = false;

Void setup (){

// Access the I2C bus
Wire. Begin ();
Serial. Begin (38400 );
// Initialize the device
Serial. println ("Initializing I2C devices ...");
Accelgyro. initialize ();

// Link the device
Serial. println ("Testing Device connections ...");
Serial. println (accelgyro. testconnection ()? "Mpu6050 connection successful": "mpu6050 connection failed ");

// Configure the onboard led pin
Pinmode (led_pin, output );

// Modify the original value
Void fix (){
Ax/= 16384;
Ay/= 16384;
AZ/= 16384;

GX/= 131;
Gy/= 131;
GZ/= 131;

// Do other things
Void process (){


Void loop (){

Accelgyro. getmotion6 (& ax, & ay, & AZ, & GX, & Gy, & GZ );

// Process the original value
Fix ();

// Do other things
Process ();

Serial. Print ("A/G: \ t ");
// X, Y, Z axis Acceleration
Serial. Print (ax); Serial. Print ("\ t ");
Serial. Print (AY); Serial. Print ("\ t ");
Serial. Print (AZ); Serial. Print ("\ t ");

// X, Y, and Z axis Angular Velocity
Serial. Print (Gx); Serial. Print ("\ t ");
Serial. Print (Gy); Serial. Print ("\ t ");
Serial. println (GZ );

// Led status on the control panel
Blinkstate =! Blinkstate;
Digitalwrite (led_pin, blinkstate );

After writing it into Lilypad, we can see that the LED is almost bright.

View serial port information in Ubuntu

Sudo ttylog-D/dev/ttyacm0-B 38400

! [Mpu6050] ( "mpu6050 ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.