If you want to track motion then one way is to use an Inertial measurement unit (IMU).
There are many types of IMU IC's and many of them are available with an i2c interface.
There is an example sketch of using a MPU6050 in the repo here.
The sketch was assembled and modified from parts of i2cdevlib.
i2cdevlib is use in the FreeIMU open source IMU project