Table of Contents

Interfacing MPU6050 Accelerometer with Arduino

Example Description
Learn how to interface an MPU6050 accelerometer, a popular 6-axis accelerometer and gyroscope module, with Arduino
Introduction

Accelerometers are vital sensors used to measure acceleration in one, two, or three axes, finding applications in robotics, gaming, and motion-sensing projects. In this example, we will guide you through connecting an MPU6050 accelerometer, a widely available 6-axis accelerometer and gyroscope module, to an Arduino board.

Our goal is to interface the accelerometer with Arduino and determine the angular movements of an object along the x-axis and y-axis.

Circuit Diagram

Connection

  1. Connect sensor VCC to 5V of the Arduino
  2. GBD to Arduino GND
  3.  SCL  to A5 of the Arduino.
  4. SDA to A4 of the Arduino.
Code 
  1. Open PictoBlox and create a new file.
  2. Change the scripting mode from “stage” mode to “upload” mode.
  3. Click on the extension button and add the communication extension.
  4. From the Arduino palette, drag the “when Arduino starts up” block into the scripting area.
  5. click on communication extensions and drag  “set serial () baud rate to () ”  into the scripting area.
  6. Set the baud rate to 9600.
  7. From the controls palette, add the “forever” block.
  8. Since the sensor is connected to Arduino, communication is enabled. Now, to write/print information on the serial monitor, go to the communication palette, drag the “write () on serial ()” block, and put it inside the forever block.
  9. Insert the “join” block in place of “Hello World” from the operators palette.
  10. To find the angle along the x-axis, change “Apple” with “x =” and in place of “Banana,” add the “get () with weight constant ()” block and choose “filtered angle in x-axis.”
  11. Repeat the above steps for the y-axis
  12. Add a “wait” block to read the values clearly..
  13. Now, upload the code into the board and check for the output on the serial monitor.

 

Final Script 

 

Output