How to Use 3-Axis Gyro & Accelerometer Sensor Module

You can determine motion and orientation values by using the three-axis (X, Y, Z) gyro and acceleration sensor.
About the Component
As shown in the diagram, the directions of the X-axis, Y-axis, and Z-axis are fixed. The sensor connects over I2C and can read the acceleration and angular velocity of each axis.

When the sensor is placed flat, the angles are approximately as follows:
- X-axis angle: 0 (+ when the right side is lowered, ±90 on its side, ±180 upside down)
- Y-axis angle: 0 (+ when the front is lowered, ±90 on its side, ±180 upside down)
- Z-axis angle: 0 (0 face up to 180 upside down)
Changes and Confirmations Possible on the Sensor Side
You can check the orientation of X, Y, and Z at the part marked with a red circle in the photo.

About I2C
I2C communication uses two signal lines, SDA and SCL. SDA stands for Serial Data and is the signal line for data. SCL stands for Serial Clock and is the signal line for the clock.
Specifications
| Voltage | 3~5V |
|---|---|
| Communication Method | I2C |
| Gyro Measurement Range | ±250 500 1000 2000 °/sec |
| Acceleration Measurement Range | ±2±4±8±16g |
| Size | 34 x 20 (mm) |
Connection
When Connecting Directly to the SPACEBLOCK Microcontroller Board
As shown in the photo, insert the pin header next to the yellow pin socket on the SPACEBLOCK microcontroller board into the pin socket of the three-axis gyro and three-axis acceleration sensor module.

When Connecting with Jumper Wires
Connect the three-axis gyro and three-axis acceleration sensor module to the SPACEBLOCK microcontroller board using jumper wires (male-female) as follows:
- Connect the GND pin of the three-axis gyro and three-axis acceleration sensor to the GND pin of the SPACEBLOCK
- Connect the VCC pin of the three-axis gyro and three-axis acceleration sensor to the 3.3V pin of the SPACEBLOCK
- Connect the SCL pin of the three-axis gyro and three-axis acceleration sensor to the B1 pin of the SPACEBLOCK
- Connect the SDA pin of the three-axis gyro and three-axis acceleration sensor to the B3 pin of the SPACEBLOCK
- Connect the XDA pin of the three-axis gyro and three-axis acceleration sensor to the B5 pin of the SPACEBLOCK
- Connect the XCL pin of the three-axis gyro and three-axis acceleration sensor to the B7 pin of the SPACEBLOCK
- Connect the ADO pin of the three-axis gyro and three-axis acceleration sensor to the B9 pin of the SPACEBLOCK
- Connect the INT pin of the three-axis gyro and three-axis acceleration sensor to the B11 pin of the SPACEBLOCK

※ The pin header next to the yellow pin socket on the SPACEBLOCK microcontroller board can be treated as pins with the same signal as the adjacent yellow pin socket.
Usage
The "Read gyro acceleration ~" block returns the acceleration of the X-axis, Y-axis, and Z-axis (±2g scaled to ±100) and the absolute value (0 at rest, larger when shaken).
The "Read gyro angle ~" block returns the tilt angle (degrees) calculated from the direction of gravity.
The "Read gyro angular velocity ~" block returns the speed of rotation around each axis (degrees/second).
The "Gyro is ~" block returns whether the gyro is being shaken, rotating, moving, facing up, or facing down as a boolean (High(true) / Low(false)).
The "Calibrate gyro" block sets the zero point while the board is held still. If you choose "Set current orientation to 0", the current orientation becomes the reference for angle 0, so the same program works regardless of how the board is mounted.
The "Read all gyro values" block returns all 9 values (acceleration, angular velocity, and angle) as a list at once. You can put it directly into the microSD CSV write block to record them.
You can retrieve values from the three-axis gyro and three-axis acceleration sensor module using the blocks under "Gyro" in the 'Input' category of your project.
For detailed usage of the block, click here.
Read gyro acceleration ~