Circuit Documentation
Summary
This document provides a detailed overview of a circuit that integrates an MPU-6050 accelerometer and gyroscope sensor with an Arduino UNO microcontroller. The MPU-6050 is used to capture motion data, which is then processed and output by the Arduino UNO.
Component List
MPU-6050
- Description: The MPU-6050 is a 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.
- Pins: VCC, GND, SCL, SDA, XDA, XCL, AD0, INT
- Purpose in Circuit: To capture motion data (acceleration and gyroscopic data).
Arduino UNO
- Description: The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
- Purpose in Circuit: To process the motion data from the MPU-6050 and output the results.
Wiring Details
MPU-6050
- VCC: Connected to Arduino UNO 5V
- GND: Connected to Arduino UNO GND
- SCL: Connected to Arduino UNO A5
- SDA: Connected to Arduino UNO A4
Arduino UNO
- 5V: Connected to MPU-6050 VCC
- GND: Connected to MPU-6050 GND
- A5: Connected to MPU-6050 SCL
- A4: Connected to MPU-6050 SDA
Code Documentation
Arduino UNO Code
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
MPU6050 mpu;
int16_t ax, ay, az;
int16_t gx, gy, gz;
struct MyData {
byte X;
byte Y;
byte Z;
};
MyData data;
void setup()
{
Serial.begin(9600);
Wire.begin();
mpu.initialize();
//pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
data.X = map(ax, -17000, 17000, 0, 255 ); // X axis data
data.Y = map(ay, -17000, 17000, 0, 255);
data.Z = map(az, -17000, 17000, 0, 255); // Y axis data
delay(500);
Serial.print("Axis X = ");
Serial.print(data.X);
}
This code initializes the MPU-6050 sensor and reads the accelerometer and gyroscope data. The data is then mapped to a range of 0 to 255 and printed to the serial monitor. The setup() function initializes the serial communication and the MPU-6050 sensor, while the loop() function continuously reads the sensor data and outputs it.
