Displaying MPU-6050 Sensor Data on LCD 1602 or LCD2004 with Arduino

Displaying MPU-6050 Sensor Data on LCD 1602 or LCD2004 with Arduino

In this tutorial, we will learn how to display data from the MPU-6050 sensor on an LCD 1602 or LCD2004 using Arduino. The MPU-6050 is a versatile sensor that combines a 3-axis gyroscope and a 3-axis accelerometer, making it ideal for various applications such as motion detection and orientation. By connecting this sensor to an LCD display, we can visualize real-time sensor data, including angles and temperature.

As we progress through this project, we will cover the necessary hardware components, wiring details, and code implementation. This will help you understand how to set up the MPU-6050 and display its output on an LCD. For further clarification on the code, be sure to check out the video at (in video at 00:00).

Hardware Explained

The primary components for this project are the Arduino board, the MPU-6050 sensor, and the LCD display (either 1602 or 2004). The Arduino serves as the microcontroller that processes the data from the MPU-6050 and sends it to the LCD.

The MPU-6050 sensor uses I2C communication to send data to the Arduino. It includes an accelerometer and a gyroscope, which allow it to sense motion and orientation. The LCD display is used to show the angles derived from the sensor data. It connects to the Arduino via I2C as well, which simplifies wiring and communication.

Datasheet Details

ManufacturerInvensense
Part numberMPU-6050
Logic/IO voltage3.3 V / 5 V
Supply voltage3.3 V to 5 V
Output data rate1 kHz (max)
Temperature range-40 to +85 °C
PackageQFN
Notes / variantsGyroscope and accelerometer integrated

  • Ensure proper power supply within the specified voltage range.
  • Use pull-up resistors on the I2C lines if necessary.
  • Check the I2C address for compatibility with your setup.
  • Calibrate the sensor for accurate readings.
  • Be cautious with wiring to avoid short circuits.

Wiring Instructions

arduino_wiring_MPU-6050_LCD2004_bb

To wire the MPU-6050 to the Arduino, start by connecting the VCC pin of the MPU-6050 to the 5V pin on the Arduino. Next, connect the GND pin of the MPU-6050 to one of the GND pins on the Arduino. For I2C communication, connect the SDA pin of the MPU-6050 to analog pin A4 on the Arduino, and connect the SCL pin to analog pin A5.

For the LCD display, connect the VCC pin to the 5V pin on the Arduino and the GND pin to the GND pin on the Arduino as well. Connect the SDA pin of the LCD to the same A4 pin used for the MPU-6050, and the SCL pin of the LCD to the A5 pin. This way, both the MPU-6050 and the LCD share the same I2C lines, simplifying the wiring.

Ensure that the connections are secure and that there are no loose wires. If your LCD or sensor does not power on, double-check the wiring and connections.

Code Examples & Walkthrough

In the code, we start by including the necessary libraries for the MPU-6050 and the LCD:

#include 
#include 
#include 

Here, we create instances for both the MPU-6050 and the LCD. The MPU-6050 is initialized with the `Wire` library for I2C communication, while the LCD is set up with its address and dimensions.

In the setup function, we initialize the sensor and the LCD:

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu6050.begin();
  lcd.begin();
  lcd.backlight();
  lcd.clear();
}

This code sets up serial communication for debugging, initializes the I2C communication, and prepares the LCD for display. The backlight is turned on to make the display visible.

In the loop function, we continuously read data from the MPU-6050 and display it on the LCD:

void loop() {
  mpu6050.update();
  lcd.clear();
  lcdDisplay(mpu6050.getAngleX(), mpu6050.getAngleY(), mpu6050.getAngleZ());
  delay(100);
}

This snippet updates the sensor data and clears the LCD for new readings every 100 milliseconds. The `lcdDisplay` function is called to show the angles on the LCD.

For a complete understanding, please watch the corresponding video where the full code is demonstrated (in video at 00:00).

Demonstration / What to Expect

When everything is set up correctly, the LCD should display the angles for the X, Y, and Z axes in real-time. You can tilt the MPU-6050 sensor to see the changes on the display. If you encounter issues, check for reversed polarity in your wiring or ensure that the I2C addresses are correctly set.

Monitoring the values on the LCD will allow you to see how the sensor responds to movement and orientation changes. If the values seem static or incorrect, verify the connections and ensure the sensor is functioning properly.

Images

arduino_wiring_MPU-6050_LCD2004_bb
arduino_wiring_MPU-6050_LCD2004_bb
LCD2004_display-3
LCD2004_display-3
LCD2004_display-1
LCD2004_display-1
LCD2004_display-2
LCD2004_display-2
119-Arduino code for MPU-6050 accelerometer and gyroscope sensor (angles only)
Language: C++
120-Arduino code for the MPU-6050 accelerometer and gyroscope sensor (all data)
Language: C++
Copied!

Resources & references

Files📁

Arduino Libraries (zip)

Fritzing File

Other files