# • Featured

:
• Makerspace Contest
• Internet of Things Class
• BBQ & Grilling

Object 1

With Instructables you can share what you make with the world, and tap into an ever-growing
community of creative experts.

How to Measure Angle With MPU-6050(GY-
521)
by BurkayKirnik in arduino
I will measure angle with an Arduino. We need some cables, an Arduino UNO and GY-521(MPU-
6050) for measure angle.

Step 1: Connecting MPU-6050 to Arduino UNO

You need some male-female cables, an Arduino UNO and GY-521(MPU-6050) for measure angle.
You have to connect MPU-6050 to Arduino UNO like in the picture. So,
• VCC to 5V(MPU-6050 works with 3.3V but GY-521 increases it to 5V.),
• GND to GND,
• SCL to A5,
• SDA to A4,
• ADO to GND,
• INT to digital pin 2.
Step 2: Code

Here is code. It uses I2C. I took some parts of code from internet.(I2C part)
//Written by Ahmet Burkay KIRNIK
//TR_CapaFenLisesi //Measure Angle with a MPU-6050(GY-521)
#include
const int MPU_addr=0x68; int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
int minVal=265; int maxVal=402;
double x; double y; double z;
void setup(){ Wire.begin(); Wire.beginTransmission(MPU_addr); Wire.write(0x6B); Wire.write(0);
Wire.endTransmission(true); Serial.begin(9600); } void loop()
{ Wire.beginTransmission(MPU_addr); Wire.write(0x3B); Wire.endTransmission(false);
yAng = map(AcY,minVal,maxVal,-90,90); int zAng = map(AcZ,minVal,maxVal,-90,90);
x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI); y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);
Serial.print("AngleX= "); Serial.println(x);
Serial.print("AngleY= "); Serial.println(y);
Serial.print("AngleZ= "); Serial.println(z); Serial.println("-----------------------------------------");
delay(400); }

• Ac_OlcerMPU_6050.ino

Step 3: Done!

It has finished! If it doesn't work, please leave a comment. By the way, my English is not so good,
sorry for my bad English.
Ahmet Burkay KIRNIK
Istanbul/TURKEY

11,394views
19favorites

BurkayKirnik

2

More by BurkayKirnik:
Related

MEASURING INCLINATION ANGLE (ARDUION+MPU6050)
by ecworks

Arduino Self-Balancing Robot
by midhun_s

3D Printed Remote Controlled BB8 Droid - Make Course
by jdl92990

Google Earth controlled by Accelerometer(MPU-6050)
by mikilabo

MPU6050: Arduino 6 Axis Accelerometer + Gyro - GY 521 Test & 3D Simulation
by HobbyTransform

FEATURED CHANNELS

• Woodworking

• Paper

• Kitchen Hacks

• Puzzles

• Laser Cutting

• Space

• 3D Printing

• Sewing

learn how to make anything!

• Who We Are
• Contact
• Jobs
• Help

Find Us
• Pinterest
Resources
• For Teachers
• Residency Program