The gyroscope measures rotational velocity (rad/s), this is the change of the angular position over time along the X, Y and Z axis (roll, pitch and yaw). This allows us to determine the orientation of an object.
The accelerometer measures acceleration (rate of change of the object’s velocity). It senses static forces like gravity (9.8m/s2) or dynamic forces like vibrations or movement. The MPU-6050 measures acceleration over the X, Y an Z axis. Ideally, in a static object the acceleration over the Z axis is equal to the gravitational force, and it should be zero on the X and Y axis.
Using the values from the accelerometer, it is possible to calculate the roll and pitch angles using trigonometry. However, it is not possible to calculate the yaw.
We can combine the information from both sensors to get more accurate information about the sensor orientation.
MPU-6050 PinoutHere’s the pinout for the MPU-6050 sensor module.
VCCPower the sensor (3.3V or 5V)GNDCommon GNDSCLSCL pin for I2C communication (GPIO 5)SDASDA pin for I2C communication (GPIO 4)XDAUsed to interface other I2C sensors with the MPU-6050XCLUsed to interface other I2C sensors with the MPU-6050AD0Use this pin to change the I2C addressINTInterrupt pin – can be used to indicate that new measurement data is available
Preparing Arduino IDEWe’ll program the ESP8266 NodeMCU board using Arduino IDE. So, make sure you have the ESP8266 add-on installed. Follow the next tutorial:
If you prefer using VS Code + PlatformIO IDE, follow the next guide:
Installing LibrariesThere are different ways to get readings from the sensor. In this tutorial, we’ll use the Adafruit MPU6050 library. To use this library you also need to install the Adafruit Unified Sensor library and the Adafruit Bus IO Library.
Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.
Type “adafruit mpu6050” on the search box and install the library.
Then, search for “Adafruit Unified Sensor”. Scroll all the way down to find the library and install it.
Finally, search for “Adafruit Bus IO” and install it.







_ztBMuBhMHo.jpg?auto=compress%2Cformat&w=48&h=48&fit=fill&bg=ffffff)



Comments