Select Page

This project was a good introduction to the I2C, utilizing the communication protocol to build a ball maze that can tilt in both directions based on the orientation of the MPU-6050 accelerometer, mounted on top of an Arduino UNO via a Shield board. The tilting action of the ball maze is determined by two 9G servo motors, each servo managing tilting in each direction. This is accomplished with bare metal programming to the ATMEGA328p, with the necessary libraries created with guidance from datasheets of the microcontroller IC and the accelerometer, along with the know-how on the operation of a servo motor. The actual ball maze is 3D-printed piece by piece and assembled, connecting the necessary joints and mounting the servo motors within.

Communication between the microcontroller IC and accelerometer is initialized and sending a read bit via I2C, reading the necessary registers within the accelerometer in sequential order containing the raw data needed for the X, Y, and Z axis, concluding with a “not acknowledge” or “NACK” bit to conclude the transfer of data from the accelerometer. This process is done continuously. Through sensor-fusion methods, the average of data between the accelerometer and gyroscope helps us acquire more accurate and stable data. Next, functions are called to convert the raw g-force data from the registers into angles using trigonometric functions.

These calculated angles are mapped to a range from -90 and 90, corresponding to the range of motion that the 9G servos can provide. Two pulse-width modulation signals that are required for the operation of each servo, depending on the orientation of the accelerometer, are generated and sent as two individual signals as outputs to the signal pins of each servo motor. This enables us to operate the tilting function of the ball maze by manipulating the orientation of the accelerometer.

To see a demonstration of the ball maze in action, click here.