MPU6050
The MPU-6050 devices combine a 3-axis gyroscope and a 3-axis accelerometer.
This module is open source, you can find all the production files here.
Gyroscope module - MPU6050 Datasheet

Example

1
#include <Wire.h>
2
3
const int MPU_addr=0x68; // MPU-6050 I2C address
4
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
5
6
void setup(){
7
Wire.begin();
8
Wire.beginTransmission(MPU_addr);
9
Wire.write(0x6B); // PWR_MGMT_1 register
10
Wire.write(0); // wakes up the MPU-6050
11
Wire.endTransmission(true);
12
Serial.begin(9600);
13
}
14
15
void loop(){
16
// Begin mpu transmission
17
Wire.beginTransmission(MPU_addr);
18
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
19
Wire.endTransmission(false);
20
21
Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers
22
AcX = Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
23
AcY = Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
24
AcZ = Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
25
Tmp = Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
26
GyX = Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
27
GyY = Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
28
GyZ = Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
29
30
Serial.print("AcX = "); Serial.print(AcX);
31
Serial.print(" | AcY = "); Serial.print(AcY);
32
Serial.print(" | AcZ = "); Serial.print(AcZ);
33
Serial.print(" | Tmp = "); Serial.print(Tmp/340.00+36.53); // Equation for temperature in degrees C from datasheet
34
Serial.print(" | GyX = "); Serial.print(GyX);
35
Serial.print(" | GyY = "); Serial.print(GyY);
36
Serial.print(" | GyZ = "); Serial.println(GyZ);
37
38
delay(500);
39
}
Copied!
Copy link
Contents
Example