arduino-experiments

Introduction

This experiment demonstrates how to use the MPU6050 sensor, which combines a gyroscope and accelerometer, to measure motion and orientation. It is commonly used in motion tracking and robotics applications.

Components Needed

No Ads Available.

Circuit Setup

  1. Connect the VCC pin of the MPU6050 to the 5V pin on the Arduino.
  2. Connect the GND pin to the GND pin on the Arduino.
  3. Connect the SDA and SCL pins to the corresponding pins on the Arduino (A4 and A5 on Arduino Uno).

Ensure the sensor is properly connected to the Arduino.

Code for Gyroscope and Accelerometer

Upload the following code to your Arduino to read data from the MPU6050 sensor:


#include 
#include 

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
}

void loop() {
  int16_t ax, ay, az;
  int16_t gx, gy, gz;
  mpu.getAcceleration(&ax, &ay, &az);
  mpu.getRotation(&gx, &gy, &gz);
  
  Serial.print("Accel X: "); Serial.print(ax);
  Serial.print(" Y: "); Serial.print(ay);
  Serial.print(" Z: "); Serial.println(az);
  
  Serial.print("Gyro X: "); Serial.print(gx);
  Serial.print(" Y: "); Serial.print(gy);
  Serial.print(" Z: "); Serial.println(gz);
  
  delay(500);
}
            

Explanation

The code initializes the MPU6050 sensor and reads both the acceleration and gyroscope data. The sensor detects movement along three axes (X, Y, Z), and the data is output to the serial monitor.

Troubleshooting

Contact Us

If you have any questions or inquiries, feel free to reach out to us at Microautomation.no@icloud.com .

Follow our Socials for the newest updates!