Connecting the MPU6050 Gyroscope Sensor with Arduino

MPU6050 gyroscope sensor has many powerful features and is packaged in a single chip. It consists of a MEMS accelerometer, a MEMS gyroscope, and a temperature sensor. This module is very accurate when converting analog signals to digital because each channel has a 16-bit ADC hardware. The module can capture x, y, and z channels simultaneously. It has an I2C interface to communicate with the main controller. This MPU6050 module is a compact chip that combines both accelerometer and gyroscope. It is a very useful device for many applications such as drones, robots, and motion sensors. It is also known as a gyroscope or a three-axis accelerometer.

Today in this article, we will introduce how to connect this MPU6050 gyroscope to the Arduino development board and display these values on a 16×2 LCD screen.

Required Components

1. Arduino Uno development board

2. MPU6050 gyroscope sensor

3. 10K potentiometer

4. Jumper wires

5. Breadboard

6. USB cable

7. Power supply

Introduction to MPU6050 Gyroscope Sensor

MPU-6050 is a single-chip, 8-pin 6-axis gyroscope and accelerometer. The module defaults to operate in I2C serial communication mode, but it can be configured to SPI interface by configuring the registers. For I2C, it has SDA and SCL lines. Almost all pins are multifunctional, but here we only introduce the pins related to I2C mode.

Connecting the MPU6050 Gyroscope Sensor with Arduino

Pin Configuration

Vcc: – This pin is used to power the MPU6050 module with respect to ground.

GND: – This is the ground pin.

SDA: – SDA pin for data transmission between the controller and the MPU6050 module.

SCL: – SCL pin for clock input.

XDA: – This is the sensor I2C SDA data line used for configuring and reading external sensors (optional, not used in this example).

XCL: – This is the sensor I2C SCL clock line used for configuring and reading external sensors (optional, not used in this example).

ADO: – I2C slave address LSB (not applicable in this example).

INT: – Interrupt pin used to indicate that data is ready.

Project Description

In this article, we use Arduino and MPU6050 to display the temperature, gyroscope, and accelerometer readings on the LCD. The module provides us with raw values and standard values, but the raw values are unstable, so we display the standard values on the LCD. If you only want to display the accelerometer values, you can also use the ADXL335 accelerometer with Arduino.

In this project, we first display the temperature value on the LCD, then after 10 seconds, display the gyroscope value, and after another 10 seconds, display the accelerometer readings, as shown in the images below:

Connecting the MPU6050 Gyroscope Sensor with Arduino

Connecting the MPU6050 Gyroscope Sensor with Arduino

Circuit Diagram and Explanation

The circuit diagram connecting the MPU6050 to the Arduino development board is very simple; we used the LCD and MPU6050 here. We used the USB power from a laptop. A 10k potentiometer was used to control the brightness of the LCD. In the connection with the MPU6050, we used 5 connections, where the MPU6050’s 3.3v power and ground are connected to the Arduino’s 3.3v and ground. The MPU6050’s SCL and SDA pins are connected to the Arduino’s A4 and A5 pins. Additionally, the MPU6050’s INT pin is connected to the Arduino’s interrupt 0 (D2). The LCD’s RS, RW, and EN are directly connected to the Arduino’s 8, ground, and 9. The data pins are directly connected to digital pins numbered 10, 11, 12, and 13.

Connecting the MPU6050 Gyroscope Sensor with Arduino

Programming Instructions

The programming part for this project is also quite easy. Here, we use the MPU6050 library to establish a connection with Arduino. First, we need to download the MPU6050 library from GitHub and install it in the Arduino IDE.

After that, we can find the sample code in the examples. Users can directly upload them to the Arduino to test the code and can view the values through the serial monitor. Alternatively, users can use the code provided at the end of the article to display the values on the LCD and the serial monitor.

In terms of code, we have included some necessary libraries, such as MPU6050 and LCD.

  1. #include<LiquidCrystal.h>

  2. LiquidCrystal lcd(8,9,10,11,12,13);

  3. #include <Wire.h>

  4. #include <MPU6050.h>

Copy Code

In the setup function, we initialize the two devices and write a welcome message to the LCD:

  1. void setup()

  2. {

  3. lcd.begin(16,2);

  4. lcd.createChar(0, degree);

  5. Serial.begin(9600);

  6. Serial.println(“Initialize MPU6050”);

  7. while(!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G))

  8. {

  9. lcd.clear();

  10. lcd.print(“Device not Found”);

  11. Serial.println(“Could not find a valid MPU6050 sensor, check wiring!”);

  12. delay(500);

  13. }

  14. count=0;

  15. mpu.calibrateGyro();

  16. mpu.setThreshold(3);

Copy Code

In the loop function, we call three functions every 10 seconds to display the temperature, gyroscope, and accelerometer readings on the LCD. These three functions are tempShow, gyroShow, and accelShow, which you can check in the complete Arduino code given at the end of this article:

  1. void loop()

  2. {

  3. lcd.clear();

  4. lcd.print(“Temperature”);

  5. long st=millis();

  6. Serial.println(“Temperature”);

  7. while(millis()<st+period)

  8. {

  9. lcd.setCursor(0,1);

  10. tempShow();

  11. }

  12. lcd.clear();

  13. lcd.print(“Gyro”);

  14. delay(2000);

  15. st=millis();

  16. Serial.println(“Gyro”);

  17. while(millis()<st+period)

  18. {

  19. lcd.setCursor(0,1);

  20. gyroShow();

  21. }

  22. lcd.clear();

  23. lcd.print(“Accelerometer”);

  24. delay(2000);

  25. st=millis();

Copy Code

MPU6050 gyroscope and accelerometer can be used to detect the position and orientation of any device. The gyroscope uses Earth’s gravity to determine the x, y, and z axis positions, while acceleration detection is based on the rate of change of motion.

For more tutorials on Arduino development boards, please click “Read Original“.

Leave a Comment

Your email address will not be published. Required fields are marked *