MPU6050 and 3D cube

Time to rotate a virtual cube on a 0.96″ OLED Display! In this tutorial, I’ll be using the MPU6050 to get the acceleration values of the X-axis and the Y-Axis, which would then be translated to the speed at which the cube is rotating at. I’ll not be using the values of the gyroscope this time but I may used it in the future.



For more information on how to use the I2C OLED Display, you can check it out here: Interfacing 0.96″ OLED Display with Arduino UNO


Parts required:

  • Arduino Uno x 1
  • MPU6050 (Accelerometer + Gyro Sensor) Module x 1
  • 0.96″ I2C OLED Display x 1
  • Jumper Wires


What is MPU6050?



The MPU6050 is a accelerometer and a gyroscope sensor that has the ability to record values on 3 axis (X – Axis, Y – Axis, Z- Axis), and uses I2C bus to interface with the Arduino. This sensor is particular useful in tracking rotational and linear motion of an object at the same time. The advantages of this sensor is that the output for each channel is 16 bits analog to digital conversion hardware , which means that the readings are very accurate, and the fact that this sensor is not expensive too. With all this advantages, many people or hobbyist likes to use the MPU6050 in their projects, which includes self balancing robots, camera stabliser, motion tracking, quadcopters and many more.

Since the accelerometer and the gyroscope are packaged together in the MPU6050, we can take advantage of this to combine the readings of both sensors to get an even more accurate & stable value of the linear and rotational motion of the object.


How does it work?

Well, we would first get raw values of both the x & y channels from the MPU6050 via the I2C bus, which I will map the raw values of both the x-axis & y-axis channels from -17000 <-> 17000 to -50 <-> 50. This value is then used to determine the speed at which the cube is rotating at. When the mapped value of the x-axis is positive, the cube will rotate to the right, vice versa. When the mapped value of the y-axis is positive, the cube will rotate upwards, vice versa. We can make the cube rotate diagonally when the sensor is tilted sideways.

I’ll be display the raw values of both x-axis and y-axis channels of the accelerometer and gyroscope on the left side of the screen for debugging purposes, even though I’m not using the values of the gyroscope yet. I might use it in the future to further increase the accuracy of the readings of motion.

A great thanks to Adafruit for their graphic library, mike rankin for his rotating 3D cube part of the code.






Share this post:

You may also like...

Leave a Reply