Arduino with MPU6050 Gyroscope

A compact yet well optimised three-axis accelerometer and three-axis gyroscope with temperature sensor.

Let’s put it together with Arduino.

Parts and materials

  • Arduino UNO
  • DFRobot 6 DOF Sensor – MPU6050
  • Oled lcd 128×64 1 ElectroPeak 0.96″ OLED 64×128 Display Module

Tools and machinery that are required

  • Breadboard, 400
  • 10 Pc. Jumper Wire Kit, 5 cm Long

Online services and applications

  • Pcbway
  • Arduino IDE

This project’s details

Flight controllers, ship/boat controllers, direction prediction, and regulating the Microcontroller appropriately all benefit from three-axis gyroscope sensors.

In today’s lesson, we’ll learn about the MPU6050 gyro sensor and create a simple project to demonstrate its capabilities.

Pitch, yaw, and roll readings can be shown.

Accelerometers vs. Gyroscopes:

A gyroscope sensor is a device that can measure and keep track of an object’s orientation and angular velocity.

Accelerometers aren’t as sophisticated as these.

These can detect the object’s tilt and lateral orientation, whereas an accelerometer can only detect linear motion.

MPU6050:

MPU6050 is a three-axis accelerometer and three-axis gyroscope Micro Electro-mechanical system (MEMS).

It aids in the measurement of velocity, direction, acceleration, displacement, and other motion-related characteristics.

which executes MotionFusion algorithms with six axes of motion.

Through an auxiliary master I2C link, the device may access external magnetometers or other sensors, allowing the devices to collect a complete set of sensor data without the need for involvement from the system processor.

Features:

Combination of MEMS 3-axis accelerometer and 3-axis gyroscope values

3-5V power supply

I2C protocol is used for communication.

High precision is provided by the built-in 16-bit ADC.

High processing power is provided by the built-in DMP.

It may be used to connect to other IIC devices, such as magnetometers.

IIC Addresses That Can Be Changed

Temperature sensor built-in

Acceleration may be measured in a variety of ways.

The on-chip accelerometer on the MPU6050 can measure acceleration with four configurable full scale ranges of 2g, 4g, 8g, and 16g.

Three 16-bit analog-to-digital converters sample the three axes of movement concurrently in the MPU6050 (along X, Y and Z axis).

Rotation measurement:

The MPU6050 has an on-chip gyroscope that can monitor angular rotation with four configurable full scale ranges of 250°/s, 500°/s, 1000°/s, and 2000°/s.

The MPU6050 features three more 16-bit analog-to-digital converters that sample three axes of rotation at the same time (around X, Y and Z axis).

From 3.9 to 8000 samples per second, the sampling rate can be changed.

The I2C Protocol:

The module communicates with the Arduino through the I2C interface.

It recognises two different I2C addresses: 0x68HEX and 0x69HEX.

This enables the usage of two MPU6050s on the same bus or the avoidance of address conflicts with other devices on the bus.

The ADO pin specifies the module’s I2C address.

A 4.7K pull-down resistor is integrated into this pin.

As a result, if you keep the ADO pin unplugged, the default I2C address is 0x68HEX, but if you connect it to 3.3V, the line is pulled HIGH, and the I2C address changes to 0x69HEX.

You may also look up the I2C address by clicking on this link.

Incorporating External Sensors:

The MPU6050 module has a function for attaching external sensors, which helps to improve accuracy even further.

These external sensors are linked to the MPU6050 through a separate I2C bus (XDA and XCL) from the main I2C bus.

A magnetometer, which can detect magnetic fields in three axes, is commonly attached to this external connection.

The MPU6050 features six degrees of freedom (DOF) on its own, three for the accelerometer and three for the gyroscope.

The addition of a magnetometer increases the sensor’s DOF to nine.

Required components:

1) MPU6050
2) OLED I2C
3) ARDUINO UNO
4) ENERGY SUPPLY
5) WIRES AND BREADBOARD

Diagram of a circuit:

Both the MPU6050 and the OLED may be readily linked using the I2C standard.

As a result, we adjusted the address and linked them to the microcontroller in parallel.

A 5 volt supply is sufficient to power the entire system.

If you want to build your own microcontroller board, follow these steps:

If you want to create your own Arduino as I did, follow these instructions.

You’ll find all of the Gerber files with circuit information here.

PCBway is the only prototype PCB firm that offers quality PCB boards at reasonable costs, and you’ll earn newbie and sign-up coupon prizes if you sign up with this link.

The ordering procedure is straightforward; first, choose the PCB’s specifications (length and width).

After that, select the PCB material, colour, and thickness.

Save the information to your cart, then submit the Gerber files. Once the PCB unit has been reviewed, the PCBWAY team will give you a message to checkout and pay.

In just 7 days, you may have your PCBs delivered to your home.

Code :

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <MPU6050_light.h>

#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);


MPU6050 mpu(Wire);
unsigned long timer = 0;

void setup() {
  Serial.begin(115200);                           // Ensure serial monitor set to this value also    
  if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))  // Address 0x3C for most of these displays, if doesn't work try 0x3D 
  { 
    Serial.println(F("SSD1306 allocation failed"));
    for(;;);                                      // Don't proceed, loop forever
  } 
  display.setTextSize(1);             
  display.setTextColor(SSD1306_WHITE);            // Draw white text
  display.clearDisplay();                         
  Wire.begin();
  mpu.begin();
  display.println(F("Calculating gyro offset, do not move MPU6050"));
  display.display();        
  mpu.calcGyroOffsets();                          // This does the calibration
  display.setTextSize(2);          
}

void loop() {
  mpu.update();  
  if((millis()-timer)>10)                         // print data every 10ms
  {                                           
    display.clearDisplay();                       // clear screen
    display.setCursor(0,0);                         
    display.print("P : ");
    display.println(mpu.getAngleX());
    display.print("R : ");
    display.println(mpu.getAngleY());
    display.print("Y : ");
    display.print(mpu.getAngleZ());
    display.display();                            // display data
    timer = millis();  
  }
}

Be the smile of someone else, your smile will never vanish

KP

“It’s better to have a dirty mind than a dirty heart” – KP

Listen to everyone, Respect to everyone, Respond to few one

KP

Helping Hands.

About the author

pondabrothers

View all posts

Leave a Reply

Your email address will not be published.