The Accelerometer & Gyro is a combined sensor that measures both linear acceleration and angular velocity. This dual functionality allows the detection of orientation, movement, and rotation in three-dimensional space. These sensors are widely used in applications such as motion tracking, robotics, gaming, drones, and smartphones.
By combining an accelerometer and a gyroscope, this component provides a comprehensive solution for motion sensing, enabling precise measurements of tilt, orientation, and dynamic movement.
Below are the key technical details for a typical Accelerometer & Gyro module (e.g., MPU-6050):
The Accelerometer & Gyro module typically has the following pinout:
Pin | Name | Description |
---|---|---|
1 | VCC | Power supply input (3.3V to 5V). |
2 | GND | Ground connection. |
3 | SCL | I2C clock line for communication. |
4 | SDA | I2C data line for communication. |
5 | INT | Interrupt pin (optional, used for event-based notifications). |
6 | AD0 | Address selection pin (used to set the I2C address of the module). |
To use the Accelerometer & Gyro module with an Arduino UNO, follow these steps:
Wiring:
VCC
pin of the module to the 5V pin on the Arduino.GND
pin of the module to the GND pin on the Arduino.SCL
pin of the module to the A5 pin on the Arduino (I2C clock line).SDA
pin of the module to the A4 pin on the Arduino (I2C data line).Install Required Libraries:
Wire
library (pre-installed with Arduino IDE).MPU6050
library from the Arduino Library Manager.Example Code: Use the following code to read acceleration and gyroscope data from the module:
#include <Wire.h>
#include <MPU6050.h>
MPU6050 mpu; // Create an MPU6050 object
void setup() {
Serial.begin(9600); // Initialize serial communication
Wire.begin(); // Initialize I2C communication
// Initialize the MPU6050 sensor
if (!mpu.begin(MPU6050_SCALE_2000DPS, MPU6050_RANGE_2G)) {
Serial.println("Could not find a valid MPU6050 sensor!");
while (1); // Halt the program if initialization fails
}
Serial.println("MPU6050 initialized successfully!");
}
void loop() {
// Read acceleration and gyroscope data
Vector rawAccel = mpu.readRawAccel();
Vector rawGyro = mpu.readRawGyro();
// Print acceleration data
Serial.print("Accel X: "); Serial.print(rawAccel.XAxis);
Serial.print(" | Accel Y: "); Serial.print(rawAccel.YAxis);
Serial.print(" | Accel Z: "); Serial.println(rawAccel.ZAxis);
// Print gyroscope data
Serial.print("Gyro X: "); Serial.print(rawGyro.XAxis);
Serial.print(" | Gyro Y: "); Serial.print(rawGyro.YAxis);
Serial.print(" | Gyro Z: "); Serial.println(rawGyro.ZAxis);
delay(500); // Wait for 500ms before the next reading
}
0x68
. If the AD0
pin is connected to VCC, the address changes to 0x69
.No Data Output:
Initialization Fails:
SCL
and SDA
lines are connected properly.Inconsistent Readings:
Incorrect Orientation:
Can I use this module with a 3.3V microcontroller?
How do I calibrate the sensor?
MPU6050
or by manually adjusting offsets for each axis.What is the maximum sampling rate of the module?
By following this documentation, you can effectively integrate and use the Accelerometer & Gyro module in your projects.